Building Vector Search and Personal Knowledge Graphs on Mobile with libSQL and React Native
Kin, a local-first personal AI app, stores its agent memory as a vector-searchable knowledge graph on the user's device using libSQL through the OP-SQLite React Native binding, enabled with a package.json flag. Nodes and edges live in relational tables with F32_BLOB embedding columns. Edges are indexed with libsql_vector_idx, using compress_neighbors and max_neighbors to save space, and queried via vector_top_k joined on rowid, with distance computed by vector_distance_cos. Practical gotchas include serializing Float32Array vectors into dynamic SQL because OP-SQLite lacks typed-array parameters, and iOS/Android build clashes when other packages such as expo-updates or expo-sqlite compile their own SQLite.
Related posts
- Personal Knowledge Graphs in AI RAG-powered Applications with libSQL
Turso mediumAdeptKin, 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.
- SQLite Retrieval Augmented Generation and Vector Search
Turso mediumAdeptRetrieval-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.
- In-Browser Semantic AI Search with PGlite and Transformers.js
Supabase mediumAdeptA fully local, in-browser semantic search can be built by combining PGlite (Postgres compiled to run in the browser, persisted to IndexedDB) with the pgvector extension and Transformers.js running the Supabase/gte-small embedding model. The tutorial sets up a React/Vite app, creates an embeddings table with a 384-dimension vector column and an HNSW index using inner product ops, and seeds it with precomputed embeddings. Queries then embed the user's search text in the browser and run inner product search against the local database. Suggested use cases include e-commerce product search and similar-product suggestions without a server roundtrip.
- You Don't Need A Separate Vector Database
Turso easyNoviceVector search belongs in your primary database rather than a separate system like Pinecone, because syncing embeddings across multiple stores adds cost and operational complexity. Turso's libSQL fork adds a native vector datatype (F32_BLOB) and DiskANN-based indexes with options like 1-bit neighbor compression. Similarity search can then be combined with ordinary SQL filters, and data and embeddings can be updated atomically in one transaction. Dedicated vector databases still offer re-ranking, hybrid scoring and compression, but many applications don't need them. Examples include on-device AI assistants and per-agent ephemeral databases.
- Turso brings Native Vector Search to SQLite
Turso mediumAdeptlibSQL, 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.