SQLite-vec vs SQLite Vector: Python setup for RAG
Learn to add vector search to SQLite with two Python extensions, use metadata filters, and compare query speed and quantized storage.
Player not loading? Watch on YouTube
This Python tutorial compares SQLite-vec and SQLite Vector for storing embeddings and running similarity searches in SQLite. The speaker presents SQLite-vec as the simpler, lightweight option and SQLite Vector as an approach with more tuning options, then demonstrates both with in-memory databases.
The SQLite-vec example loads the extension and creates a vec0 virtual table with a 1,536-dimensional embedding column. It uses OpenAI's text-embedding-3-small model, serializes vectors as float32, and retrieves the nearest text entries with a top-k query. A filtering example explains the distinction between metadata columns and auxiliary columns: attempting the same filter on an auxiliary column produces an error.
SQLite Vector uses a regular table with embeddings stored as BLOBs. The tutorial loads its extension binary, initializes the vector column with cosine distance, and joins full-scan results back to the text rows. The speaker also corrects an installation mistake: the Python package is sqlite-ai-vector.
The demonstrations use an OpenAI API key, so they are not an offline embedding workflow. Benchmarks use random vectors. At 150,000 vectors, the recorded query times are about 241 ms for SQLite-vec and 231 ms for SQLite Vector, a modest difference in this run. The final examples explain that SQLite Vector retains original data alongside quantized data, reducing the search representation rather than the total database size.