TOOL WIKI · VECTOR & SEARCH
sqlite-vec
Adds vector-search capabilities to an embedded SQLite database.
Jump to a section 10 sections
EXAMPLE USE CASE
Keep scoped vector recall in an embedded database
A policy assistant needs relevant records with source ownership; vector similarity alone does not establish who may read them.
- Input
- A vec0 table with a tenant partition key and two toy vectors.
- Expected output
- The tenant-a row and its measured distance.
- Success check: The nearest authorized record is the returns policy; the unrelated tenant never appears.
- Try a failure: The same vector in another tenant must remain outside the requested partition.
Example scope: Actual loaded SQLite extension and nearest-neighbor query, executed locally in QA.
Official reference · sqlite-vec
Preserve source identifiers, version, tenant, and deletion status.
Use the same embedding model and dimensions for indexed records and queries.
indexTo 03 · sqlite-vecLocal applications and small deployments that favor an embedded store. Treat the embedding index and the application’s metadata schema separately.
matchesTo 05 · Filter + rankResolve allowed tenants and filters before searching for evidence.
embed queryBack to 02 · Embedding processApply resource permissions and select the evidence that supports this task.
evidenceTo 06 · Agent contextReturn source text and identifiers, not a vector distance presented as factual certainty.
Result or stopping point
Local applications and small deployments that favor an embedded store. Treat the embedding index and the application’s metadata schema separately.
When to consider it
- Local applications and small deployments that favor an embedded store.
A design decision to make
- Treat the embedding index and the application’s metadata schema separately.
Prerequisites and setup
- Python 3.11+ and a fresh scratch directory. Toy vectors avoid embedding-provider calls.
python3 -m venv .venv
source .venv/bin/activate
pip install sqlite-vecTry a small integration
search.py
import sqlite3
import sqlite_vec
con = sqlite3.connect(":memory:")
con.enable_load_extension(True)
sqlite_vec.load(con)
con.enable_load_extension(False)
con.execute("CREATE VIRTUAL TABLE policies USING vec0(id INTEGER PRIMARY KEY, tenant TEXT PARTITION KEY, embedding FLOAT[3])")
con.execute("INSERT INTO policies VALUES (?,?,?)",(1,"a","[1,0,0]"))
con.execute("INSERT INTO policies VALUES (?,?,?)",(2,"b","[1,0,0]"))
hits = con.execute("SELECT id,tenant,distance FROM policies WHERE embedding MATCH ? AND k=1 AND tenant=?",("[1,0,0]","a")).fetchall()
assert hits[0][0] == 1
print(hits)Run and check the result
python search.py- The nearest authorized record is the returns policy; the unrelated tenant never appears.
- Change the query vector or tenant filter and inspect the returned IDs, metadata and score ordering.
Common failures
- Some Python SQLite builds disallow extension loading; install a compatible SQLite runtime rather than removing the vector check.
- Partition-key equality filters are explicit. A plain shared index does not know the current user.
Production decisions
- Use embeddings from one named model/version with a fixed dimension and distance metric. The three-value vectors here demonstrate mechanics, not semantic quality.
- Enforce authenticated tenant/resource filters outside model control. Test filtered recall, deletion, backups, index rebuilds and p95 latency on realistic data.
Keep exploring
Explore the same layer
Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.