-
Notifications
You must be signed in to change notification settings - Fork 77
Open
Description
Path: /features/ai-and-embeddings
In the vector index usage example, the schema is declared with a column named full_emb
:
turso-docs/features/ai-and-embeddings.mdx
Lines 85 to 93 in 60dba44
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
:
turso-docs/features/ai-and-embeddings.mdx
Lines 101 to 110 in 60dba44
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]')); | |
``` |
turso-docs/features/ai-and-embeddings.mdx
Lines 118 to 128 in 60dba44
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; | |
``` |
Metadata
Metadata
Assignees
Labels
No labels