SQLite向量搜索:最轻量的RAG方案
向量搜索真的需要服务器吗?sqlite-vec把向量加到最便携的数据库里。
SQLite Vector Search 2026: sqlite-vec and the Lightest RAG Stack Ever
SQLite is the most deployed database on Earth - every phone, browser, and desktop app ships with it. sqlite-vec (7,900 GitHub stars) adds vector search as a loadable extension, making it possible to run a full RAG pipeline inside a single file. No server, no Docker, no cloud.
Why SQLite for Vectors
- Zero infrastructure - one file, no daemon
- Perfect for desktop/mobile apps - embed RAG in your app
- Battery-friendly - no network calls for local semantic search
- Good to ~1M vectors - plenty for personal or small-team use
Step 1: Install
pip install sqlite-vec
# or load as a SQLite extension in any language
Step 2: Create and Insert
import sqlite3, sqlite_vec
conn = sqlite3.connect("search.db")
conn.enable_load_extension(True)
sqlite_vec.load(conn)
conn.execute("CREATE VIRTUAL TABLE vec_docs USING vec0(embedding float[768])")
# Insert with an embedding from any model
conn.execute(
"INSERT INTO vec_docs(rowid, embedding) VALUES (?, ?)",
(1, embedding_list)
)
Step 3: Search
rows = conn.execute(
"SELECT rowid, distance FROM vec_docs WHERE embedding MATCH ? ORDER BY distance LIMIT 5",
(query_embedding,)
).fetchall()
Step 4: Full RAG in One File
The complete stack: documents in a normal table, embeddings in the vec0 virtual table, and the LLM served locally by Ollama. Total: one .db file + one Python script.
When to Use It vs a Real Vector DB
| Scenario | Use |
|---|---|
| Desktop app, mobile app, CLI tool | sqlite-vec |
| Single-user local search | sqlite-vec |
| Multi-user web app, high concurrency | Qdrant, Chroma, PGVector |
| 10M+ vectors | Milvus, Qdrant, Weaviate |
FAQ
sqlite-vec vs sqlite-vss? sqlite-vss is the older, unmaintained project; sqlite-vec is its modern successor with better performance and maintenance.
Does it work on mobile? Yes - loads in iOS and Android apps; it is written in C with no server component.
How many vectors can it handle? Community benchmarks show smooth operation to ~1M vectors; beyond that, a server-based vector DB is a better fit.
