Registry / vector-search / sqlite-vec

sqlite-vec

JSON →
library0.1.9pypypi✓ verified 23d ago

sqlite-vec is a SQLite extension for vector search, written in pure C with no dependencies. It enables storing, manipulating, and querying vector data directly within SQLite files, making it ideal for edge deployments, serverless functions, and local tooling. It supports various vector types (float32, int8, bit) and distance metrics (L1, L2, cosine, Hamming), offering fast brute-force search and SIMD acceleration. The project is pre-v1, so breaking changes are expected. It supports Python, Node.js, Ruby, Rust, and Go bindings.

pip install sqlite-vec
INSTALL
IMPORT
SIG · SQLITE-VEC
S
sqlite-vec
vector-searchpythonv0.1.9
Install
1.5s avg
Import
22ms
Disk
16MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.9 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.022s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

load
from sqlite_vec import load
Used to load the sqlite-vec extension into a SQLite connection.
serialize_float32
from sqlite_vec import serialize_float32
Helper function to convert Python list of floats into the compact BLOB format used by sqlite-vec.

This quickstart demonstrates how to initialize a SQLite database with the `sqlite-vec` extension, create a `vec0` virtual table for storing 4-dimensional float embeddings, insert example embeddings (using NumPy arrays, or `serialize_float32` for Python lists), and perform a K-Nearest Neighbors (KNN) search.

import sqlite3 from sqlite_vec import load, serialize_float32 import numpy as np # Often used for embeddings import os # Connect to an in-memory SQLite database db = sqlite3.connect(":memory:") # Enable loading of SQLite extensions (necessary for sqlite-vec) db.enable_load_extension(True) # Load the sqlite-vec extension load(db) # For security, disable extension loading immediately after loading db.enable_load_extension(False) # Verify the extension is loaded vec_version, = db.execute("SELECT vec_version()").fetchone() print(f"sqlite-vec version: {vec_version}") # Create a virtual table for vectors using vec0 module db.execute("CREATE VIRTUAL TABLE documents USING vec0(embedding float[4]);") # Example embeddings (using numpy for convenience, ensure float32) embedding1 = np.array([0.1, 0.2, 0.3, 0.4], dtype=np.float32) embedding2 = np.array([0.5, 0.6, 0.7, 0.8], dtype=np.float32) embedding3 = np.array([0.15, 0.25, 0.35, 0.45], dtype=np.float32) # Insert embeddings into the virtual table # sqlite-vec automatically handles numpy arrays if they implement the Buffer protocol # For lists, use serialize_float32(list_of_floats) db.execute("INSERT INTO documents(rowid, embedding) VALUES (?, ?);", (1, embedding1)) db.execute("INSERT INTO documents(rowid, embedding) VALUES (?, ?);", (2, embedding2)) db.execute("INSERT INTO documents(rowid, embedding) VALUES (?, ?);", (3, embedding3)) db.commit() # Query for nearest neighbors (L2 distance by default) query_embedding = np.array([0.1, 0.2, 0.3, 0.35], dtype=np.float32) print("\nNearest neighbors to [0.1, 0.2, 0.3, 0.35]:") for rowid, distance in db.execute( "SELECT rowid, distance FROM documents WHERE embedding MATCH ? ORDER BY distance LIMIT 2;", [query_embedding] ): print(f"Document ID: {rowid}, Distance: {distance:.4f}") # Close the database connection db.close()
Debug
Known issues
breakingsqlite-vec is pre-v1, meaning its API and behavior are subject to breaking changes in future releases.
fix
Always check release notes for breaking changes when upgrading, especially before v1.0.0.
affects: <1.0.0
gotchaSQLite version 3.41 or higher is recommended for full feature compatibility and optimal performance, though it will work with older versions.
fix
Ensure your Python environment uses an up-to-date SQLite library. This may involve compiling SQLite with Python or using specific environment variables to override the default system SQLite.
affects: <3.41
gotchaLoading SQLite extensions requires `db.enable_load_extension(True)`, which can be a security risk if not immediately followed by `db.enable_load_extension(False)` after the extension is loaded.
fix
Always call `db.enable_load_extension(False)` right after `sqlite_vec.load(db)` to minimize potential security vulnerabilities.
affects: *
gotchaCurrent versions of sqlite-vec primarily use brute-force search, which may become slow on very large datasets (>1 million vectors with high dimensions). Approximate Nearest Neighbors (ANN) support is planned but not yet a core feature.
fix
For very large datasets, be aware of performance limitations. Consider data quantization or other techniques if exact brute-force search performance degrades too much.
affects: <1.0.0
gotchaOlder versions (prior to v0.2.0-alpha) had known memory leak issues, particularly during DELETE operations.
fix
Upgrade to the latest available version (0.1.9 or later alpha releases if available) to benefit from memory leak fixes.
affects: <0.2.0-alpha
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'sqlite_vec'
The 'sqlite-vec' Python package has not been installed in the current Python environment.
fix
Install the package using pip: `pip install sqlite-vec`
sqlite3.OperationalError: unable to load extension: /path/to/sqlite_vec.so - No such file or directory
The SQLite database could not find the 'sqlite-vec' extension binary at the specified path, typically due to an incorrect path or the file not being present.
fix
Use `sqlite_vec.loadable_path()` from the Python binding to ensure the correct, platform-specific path to the installed extension is used: `conn.load_extension(sqlite_vec.loadable_path())`
sqlite3.OperationalError: no such function: vec_version
The 'sqlite-vec' extension was not successfully loaded into the SQLite connection, so its SQL functions (like `vec_version()`) are unavailable.
fix
Ensure `sqlite-vec` is correctly installed and loaded using `conn.load_extension(sqlite_vec.loadable_path())` before calling any `vec_` functions.
sqlite3.OperationalError: wrong number of arguments for function vec_distance()
The `vec_distance` SQL function was called with an incorrect number of arguments; it requires two vector blobs and a string specifying the distance metric.
fix
Provide all three required arguments, for example: `SELECT vec_distance(X'00000000', X'01010101', 'L2');`
Upgrade
Version history
0.1.9latest on PyPI · released Mar 31, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
112 hits · last 30 days
node
98
OpenAI (training)
1
Resources
sqlite-vec — pip install sqlite-vec · libregistry