Skip to content

Commit

Permalink
Show SQL schema for embeddings in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Sep 3, 2023
1 parent 73a9043 commit b7e6c16
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 38 additions & 0 deletions docs/embeddings/python-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]]] -->

1 comment on commit b7e6c16

@simonw
Copy link
Owner Author

@simonw simonw commented on b7e6c16 Sep 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.