Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vector index usage example table schema is inconsistent #268

Open
rhashimoto opened this issue Jan 9, 2025 · 1 comment
Open

vector index usage example table schema is inconsistent #268

rhashimoto opened this issue Jan 9, 2025 · 1 comment

Comments

@rhashimoto
Copy link

Path: /features/ai-and-embeddings

In the vector index usage example, the schema is declared with a column named full_emb:

Begin by declaring a column used for storing vectors with the `F32_BLOB` datatype:
```sql
CREATE TABLE movies (
title TEXT,
year INT,
full_emb F32_BLOB(4) -- 4-dimensional f32 vector
);
```

But subsequently the column is referenced with embedding:

Once you generate embeddings for your data (via an LLM), you can insert them into your table:
```sql
INSERT INTO movies (title, year, embedding)
VALUES
('Napoleon', 2023, vector32('[0.800, 0.579, 0.481, 0.229]')),
('Black Hawk Down', 2001, vector32('[0.406, 0.027, 0.378, 0.056]')),
('Gladiator', 2000, vector32('[0.698, 0.140, 0.073, 0.125]')),
('Blade Runner', 1982, vector32('[0.379, 0.637, 0.011, 0.647]'));
```

You can now write queries combining vectors and standard SQLite data:
```sql
SELECT title,
vector_extract(embedding),
vector_distance_cos(embedding, vector32('[0.064, 0.777, 0.661, 0.687]'))
FROM movies
ORDER BY
vector_distance_cos(embedding, vector32('[0.064, 0.777, 0.661, 0.687]'))
ASC;
```

@notrab
Copy link
Member

notrab commented Jan 29, 2025

Feel free to open a PR to suggest any changes. Thank you 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants