TOOL WIKI · VECTOR & SEARCH

sqlite-vec

Adds vector-search capabilities to an embedded SQLite database.

Download example files Code + setup + checks in a ZIP
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

WHAT IT ISSQLite extension
WHERE IT FITSVector & search
SEE HOW THE SYSTEM FITS TOGETHERSELECT A COMPONENT
ingestindexembed queryscopematchesevidenceSource recordsText + access metadataEmbedding processOne compatible spacesqlite-vecSQLite extensionUser queryAuthenticated scopeFilter + rankRelevant candidatesAgent contextPassages + provenance
  1. Preserve source identifiers, version, tenant, and deletion status.

  2. Use the same embedding model and dimensions for indexed records and queries.

  3. Local applications and small deployments that favor an embedded store. Treat the embedding index and the application’s metadata schema separately.

  4. Resolve allowed tenants and filters before searching for evidence.

  5. Apply resource permissions and select the evidence that supports this task.

  6. Return source text and identifiers, not a vector distance presented as factual certainty.

    Result or stopping point
sqlite-vec

Local applications and small deployments that favor an embedded store. Treat the embedding index and the application’s metadata schema separately.

Follow the arrows, then select a component to inspect its responsibility. On mobile, downward arrows connect the next step; bent arrows identify branches and return paths. Select a destination to jump to that component.

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.
Shell
python3 -m venv .venv
source .venv/bin/activate
pip install sqlite-vec

Try a small integration

search.py

Python · 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

Shell
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

Retrieval that can ask a better questionUse PostgreSQL and pgvector for agent memory

Explore the same layer

pgvectorQdrantPineconeWeaviate

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.