{"id":2784,"library":"sqlite-vec","title":"SQLite-vec: Vector Search Extension for SQLite","description":"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.","status":"active","version":"0.1.9","language":"en","source_language":"en","source_url":"https://github.com/asg017/sqlite-vec","tags":["sqlite","vector database","embeddings","vector search","AI","local-first","extension"],"install":[{"cmd":"pip install sqlite-vec","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"Used to load the sqlite-vec extension into a SQLite connection.","symbol":"load","correct":"from sqlite_vec import load"},{"note":"Helper function to convert Python list of floats into the compact BLOB format used by sqlite-vec.","symbol":"serialize_float32","correct":"from sqlite_vec import serialize_float32"}],"quickstart":{"code":"import sqlite3\nfrom sqlite_vec import load, serialize_float32\nimport numpy as np # Often used for embeddings\nimport os\n\n# Connect to an in-memory SQLite database\ndb = sqlite3.connect(\":memory:\")\n\n# Enable loading of SQLite extensions (necessary for sqlite-vec)\ndb.enable_load_extension(True)\n\n# Load the sqlite-vec extension\nload(db)\n\n# For security, disable extension loading immediately after loading\ndb.enable_load_extension(False)\n\n# Verify the extension is loaded\nvec_version, = db.execute(\"SELECT vec_version()\").fetchone()\nprint(f\"sqlite-vec version: {vec_version}\")\n\n# Create a virtual table for vectors using vec0 module\ndb.execute(\"CREATE VIRTUAL TABLE documents USING vec0(embedding float[4]);\")\n\n# Example embeddings (using numpy for convenience, ensure float32)\nembedding1 = np.array([0.1, 0.2, 0.3, 0.4], dtype=np.float32)\nembedding2 = np.array([0.5, 0.6, 0.7, 0.8], dtype=np.float32)\nembedding3 = np.array([0.15, 0.25, 0.35, 0.45], dtype=np.float32)\n\n# Insert embeddings into the virtual table\n# sqlite-vec automatically handles numpy arrays if they implement the Buffer protocol\n# For lists, use serialize_float32(list_of_floats)\ndb.execute(\"INSERT INTO documents(rowid, embedding) VALUES (?, ?);\", (1, embedding1))\ndb.execute(\"INSERT INTO documents(rowid, embedding) VALUES (?, ?);\", (2, embedding2))\ndb.execute(\"INSERT INTO documents(rowid, embedding) VALUES (?, ?);\", (3, embedding3))\ndb.commit()\n\n# Query for nearest neighbors (L2 distance by default)\nquery_embedding = np.array([0.1, 0.2, 0.3, 0.35], dtype=np.float32)\n\nprint(\"\\nNearest neighbors to [0.1, 0.2, 0.3, 0.35]:\")\nfor rowid, distance in db.execute(\n    \"SELECT rowid, distance FROM documents WHERE embedding MATCH ? ORDER BY distance LIMIT 2;\",\n    [query_embedding]\n):\n    print(f\"Document ID: {rowid}, Distance: {distance:.4f}\")\n\n# Close the database connection\ndb.close()\n","lang":"python","description":"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."},"warnings":[{"fix":"Always check release notes for breaking changes when upgrading, especially before v1.0.0.","message":"sqlite-vec is pre-v1, meaning its API and behavior are subject to breaking changes in future releases.","severity":"breaking","affected_versions":"<1.0.0"},{"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.","message":"SQLite version 3.41 or higher is recommended for full feature compatibility and optimal performance, though it will work with older versions.","severity":"gotcha","affected_versions":"<3.41"},{"fix":"Always call `db.enable_load_extension(False)` right after `sqlite_vec.load(db)` to minimize potential security vulnerabilities.","message":"Loading 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.","severity":"gotcha","affected_versions":"*"},{"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.","message":"Current 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.","severity":"gotcha","affected_versions":"<1.0.0"},{"fix":"Upgrade to the latest available version (0.1.9 or later alpha releases if available) to benefit from memory leak fixes.","message":"Older versions (prior to v0.2.0-alpha) had known memory leak issues, particularly during DELETE operations.","severity":"gotcha","affected_versions":"<0.2.0-alpha"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}