1yefuwang1/vectorlite

Fast, SQL powered, in-process vector search for any language with an SQLite driver

Vectorlite – Fast Vector Search Inside SQLite

What it does

Vectorlite is a runtime‑loadable SQLite extension that adds a new virtual table type for approximate nearest‑neighbor (ANN) search on high‑dimensional vectors. It lets you store vectors directly in a SQLite database and run fast similarity queries with ordinary SQL statements.

Why it matters

  • SQL‑first workflow – No separate vector database is needed; you can keep relational data and vector embeddings together in one file.
  • Speed – Uses the HNSW algorithm (via hnswlib) and SIMD‑accelerated distance calculations, giving 3‑100× faster queries than brute‑force SQLite extensions.
  • Cross‑language – The compiled vectorlite.so/.dll/.dylib works with any language that can load SQLite extensions (Python, Node.js, Rust, Go, etc.).
  • Portable – Pre‑built binaries for Linux x64, Windows x64 and macOS Apple Silicon; also available as a Python wheel (vectorlite-py) and an npm package.

How you use it (SQL example)

.load path/to/vectorlite.so               -- load the extension
SELECT vectorlite_info();                -- version info

-- Create a table that holds 3‑dimensional float32 vectors
CREATE VIRTUAL TABLE my_vec USING vectorlite(
    embedding float32[3], hnsw(max_elements=100)
);

INSERT INTO my_vec(rowid, embedding) VALUES (0, vector_from_json('[1,2,3]'));
INSERT INTO my_vec(rowid, embedding) VALUES (1, vector_from_json('[2,3,4]'));
INSERT INTO my_vec(rowid, embedding) VALUES (2, vector_from_json('[7,7,7]'));

-- Find the 2 nearest neighbours of [3,4,5]
SELECT rowid, distance
FROM my_vec
WHERE knn_search(embedding, knn_param(vector_from_json('[3,4,5]'), 2));

The extension supplies helper functions:

  • vector_from_json() / vector_to_json() – convert between JSON arrays and the binary format SQLite stores.
  • vector_distance() – compute exact L2, cosine or inner‑product distance.
  • knn_param() and knn_search() – build and run an ANN query.
  • vectorlite_info() – shows build details and the SIMD target chosen at runtime.

Key features

Feature Details
ANN engine HNSW (hierarchical navigable small world) via hnswlib; tunable ef_construction, M, etc.
Distance metrics L2 (squared), cosine, inner‑product (IP)
SIMD acceleration Uses Google’s Highway library; 1.5‑3× faster than hnswlib’s own distance code for high‑dim vectors
Data types float32, float16, bfloat16 – half‑precision tables are quantised on insert/query
Metadata filter Row‑id predicates are pushed down to the index (SQLite ≥ 3.38)
Persistence Index lives in memory; explicit INSERT … (operation, path) VALUES ('save', '/path') and ('load', …) commands serialize/deserialize it.
Cross‑platform Binaries for Linux x64, Windows x64, macOS Apple Silicon; wheels for Python, npm package for Node.js
Beta status API may change; breaking change removed automatic index file argument in CREATE VIRTUAL TABLE.

Who would use it?

  • Developers building RAG or semantic‑search services that already rely on SQLite for metadata.
  • Data‑science notebooks where you want quick vector similarity without spinning up a separate vector DB.
  • Embedded or edge applications (e.g., mobile, IoT) that need a tiny, self‑contained vector index.
  • Anyone who prefers SQL for querying and wants to keep vector and relational data together.

Limitations

  • The index is in‑memory only; you must explicitly save it before closing the connection.
  • Only beta – future releases may introduce breaking changes.
  • No support for Intel‑based macOS; Apple Silicon only.
  • Approximate results – recall depends on HNSW parameters (you can tune them for higher accuracy).

All information above is taken directly from the repository’s README.

Related

  • Project
  • Project
  • Project
  • Project
  • Project