Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Turso 5 min read Case study mediumAdept

The space complexity of vector indexes in LibSQL

LibSQL's built-in vector index uses LM-DiskANN, a disk-oriented graph ANN algorithm that stores neighbor graphs in shadow tables. That storage can inflate database size sharply: one mobile app grew from 3.5 MB to 50 MB, with a single index taking 19 MB. Compressing neighbor vectors to float8 shrank the index about 3x, and also cutting max_neighbors from the default (~3·sqrt(dim), about 70 for 512-dim vectors) to 20 gave about an 8x reduction. On a dataset under 1,000 nodes, top-k results matched the default index exactly. Recall may drift on datasets above roughly 10,000 vectors.

Related posts

  • Approximate nearest neighbor search with DiskANN in libSQL

    Turso mediumAdept

    libSQL implements approximate nearest neighbor search using LM-DiskANN, a low-memory variant of DiskANN. The index is wired into SQLite's indexing system through a new OpenVectorIdx bytecode instruction, so inserts update the vector index automatically. Each node is stored on disk as a fixed-size block holding its full vector plus its neighbors' IDs and compressed vectors. That layout lets best-first graph search make local decisions without extra I/O, trading extra storage for lower memory use. Queries go through a vector_top_k virtual table, and early 1-bit binary quantization with Hamming distance is in place to cut index size further.

  • Turso brings Native Vector Search to SQLite

    Turso mediumAdept

    libSQL, the SQLite fork behind Turso, now has native vector similarity search exposed as a column type (F32_BLOB) instead of an extension like sqlite-vss. Vectors are stored as blobs and handled with functions such as vector(), vector_extract() and vector_distance_cos(), so similarity queries can mix with ordinary relational filters. Full table scans give perfect recall and stay acceptable up to roughly 10,000 vectors. Larger datasets can use a DiskANN-based approximate nearest neighbor index, created with libsql_vector_idx and queried explicitly through vector_top_k joined back to the table. DiskANN's low memory footprint suits Turso's database-per-tenant, embedded-replica and on-device mobile use cases. The feature is in beta.

  • Indexing sparse vectors with Turso

    Turso hardMaster

    Turso 0.3.0 adds a compact sparse vector representation (vector32_sparse) that uses 5–50x less storage than dense vectors, plus an inverted index for nearest-neighbor search by weighted Jaccard distance. The index plugs in through a new Index Method mechanism that, unlike SQLite VTables, integrates custom access methods into the query planner via SQL query patterns. Two approximations trade speed for accuracy: frequency-based selection of the rarest p% of query components, and adaptive length filtering with a bounded error Δ. On 400k TF-IDF vectors from Amazon Reviews, brute force took 448ms and 269ms. The exact index brought short queries down to 31ms, and length filtering with Δ>0 reached 1.5–3ms with good recall@5, while long queries benefited more from component selection.

  • SQLite Retrieval Augmented Generation and Vector Search

    Turso mediumAdept

    Retrieval-augmented generation fixes stale or hallucinated LLM answers by retrieving relevant data, typically via embeddings and vector similarity search, and injecting it into the prompt. libSQL adds native vector search to SQLite: embeddings are stored in an F32_BLOB column (SQLite treats column types as hints), inserted with a vector() function, and queried with vector_distance_cos() plus ORDER BY/LIMIT for exact top-k results. That exact search is a full table scan and only scales to small datasets, so larger collections need approximate nearest-neighbour indexing, which a follow-up post will cover.

  • Personal Knowledge Graphs in AI RAG-powered Applications with libSQL

    Turso mediumAdept

    Kin, a local-first mobile personal AI, stores its personal knowledge graph in libSQL so that relational data, graph edges and vector embeddings live in one embeddable single-file database instead of syncing a separate store like faiss. Nodes and edges are ordinary SQLite tables. Each edge carries an F32_BLOB(512) embedding of its normalized subject–predicate–object triple, which makes the triples searchable by vector similarity. The post walks through inserting vectors with the vector() function and shows why brute-force vector_distance_cos scans are slow. It then covers adding a libsql_vector_idx index and querying via vector_top_k joined on rowid, recomputing distances on the small result set and filtering by a cosine threshold.

The quest for software engineering knowledge.

Look:
Layout: