
Turso Vector Search: Add Semantic Search to a SQLite Database Without an Extension
Also available in Hindi: यह लेख हिंदी में पढ़ें
If your app already keeps its data in SQLite, you may not need a separate vector database for RAG. Turso's libSQL engine has vector search built in: embeddings sit in a normal table next to your rows, and an index finds the nearest ones. No extension to load.
Create a libSQL database
turso db create my-db
turso db shell my-db
Turso Cloud now hosts two engines. Plain turso db create gives you libSQL, the SQLite fork Turso has run in production for years. Adding --tursodb creates a database on the new Turso engine, which is in early preview on Turso Cloud. That choice matters for vector search, as the table below shows.
Store embeddings next to your data
CREATE TABLE notes (
id INTEGER PRIMARY KEY,
body TEXT,
embedding F32_BLOB(3)
);
INSERT INTO notes (body, embedding) VALUES
('refund policy', vector32('[0.9, 0.1, 0.0]')),
('shipping times', vector32('[0.1, 0.9, 0.0]'));
F32_BLOB(3) means 32-bit floats with exactly 3 dimensions. Real embeddings have hundreds or thousands, so use the number your embedding model returns. Turso suggests FLOAT32 as the starting type; FLOAT8 and FLOAT1BIT save space at some precision cost. The limit is 65,536 dimensions.
Build the index and query it
CREATE INDEX notes_idx ON notes (libsql_vector_idx(embedding));
SELECT n.body
FROM vector_top_k('notes_idx', vector32('[0.85, 0.15, 0.05]'), 2) AS v
JOIN notes AS n ON n.id = v.id;
The index uses the DiskANN algorithm, which is approximate: it trades a little accuracy for speed on large tables. It fills itself from existing rows and stays in sync with inserts and updates. Cosine distance is the default; pass 'metric=l2' for Euclidean.
Errors you will probably hit
- "dimensions are different: 2 != 3": the query vector or inserted vector does not match the column size. Every vector must use the same model and length.
- "ambiguous column name: id": in our test, Turso's sample join
ON movies.rowid = idbroke once the table had its ownidcolumn. Alias both sides as above. - No index on a
--tursodbdatabase: there, similarity search is a linear scan withvector_distance_cosandORDER BY, so filter withWHEREon big tables.
The free plan includes 100 databases, 5 GB of storage and 500 million rows read a month. Compare Chroma for local RAG, Qdrant hybrid search and the best database for side projects, or visit the Turso tool page.
Sources
- AI & Embeddings, Turso docs
- Vector Search guide, Turso Cloud and Quickstart, Turso docs
- Pricing, Turso
- COMPAT.md, tursodatabase/turso on GitHub
- Vector search, Bunny Database docs (independent libSQL host)
FAQ
Do I need a SQLite extension for vectors?
No. Vector types and functions are built into libSQL on Turso.
Is the vector index exact?
No. DiskANN is approximate nearest neighbor search; it can miss a close match on large tables.
Can I filter by other columns?
Yes. Join the index results to your table and add WHERE conditions, or build a partial index.
Which vector type should I start with?
FLOAT32 (F32_BLOB). Try FLOAT8 or FLOAT1BIT only when storage becomes a problem.