Show SQL schema for embeddings in docs

This commit is contained in:
Simon Willison 2023-09-02 20:48:00 -07:00
parent 73a9043108
commit b7e6c1675b
4 changed files with 43 additions and 3 deletions

View file

@ -31,7 +31,7 @@ jobs:
run: |
cog --check \
-p "import sys, os; sys._called_from_test=True; os.environ['LLM_USER_PATH'] = '/tmp'" \
docs/*.md
docs/**/*.md
- name: Run Black
run: |
black --check .

View file

@ -25,7 +25,7 @@
# Rebuild docs with cog
@cog:
pipenv run cog -r -p "import sys, os; sys._called_from_test=True; os.environ['LLM_USER_PATH'] = '/tmp'" docs/*.md
pipenv run cog -r -p "import sys, os; sys._called_from_test=True; os.environ['LLM_USER_PATH'] = '/tmp'" docs/**/*.md
# Serve live docs on localhost:8000
@docs: cog

View file

@ -32,7 +32,9 @@ This will start a live preview server, using [sphinx-autobuild](https://pypi.org
The CLI `--help` examples in the documentation are managed using [Cog](https://github.com/nedbat/cog). Update those files like this:
cog -r docs/*.md
just cog
You'll need [Just](https://github.com/casey/just) installed to run this command.
## Release process

View file

@ -135,3 +135,41 @@ for id, score in collection.similar_by_id("cat"):
print(id, score)
```
The item itself is excluded from the results.
(embeddings-sql-schema)=
## SQL schema
Here's the SQL schema used by the embeddings database:
<!-- [[[cog
import cog
from llm.embeddings_migrations import embeddings_migrations
import sqlite_utils
import re
db = sqlite_utils.Database(memory=True)
embeddings_migrations.apply(db)
cog.out("```sql\n")
for table in ("collections", "embeddings"):
schema = db[table].schema
cog.out(format(schema))
cog.out("\n")
cog.out("```\n")
]]] -->
```sql
CREATE TABLE [collections] (
[id] INTEGER PRIMARY KEY,
[name] TEXT,
[model] TEXT
)
CREATE TABLE "embeddings" (
[collection_id] INTEGER REFERENCES [collections]([id]),
[id] TEXT,
[embedding] BLOB,
[content] TEXT,
[metadata] TEXT,
[updated] INTEGER,
PRIMARY KEY ([collection_id], [id])
)
```
<!-- [[[end]]] -->