← all notes

c3 searches by meaning.

c3 runs on libSQL, which has vector columns and a nearest-neighbour index built in. Here's how a Cell uses them, what they cost at different sizes, and a bug in the index we fixed while measuring it.

Every Cell can bind a c3 database, and c3 is built on libSQL, the fork of SQLite that Turso maintains. libSQL stores a vector in an ordinary column and compares vectors in plain SQL. So a Cell can search its own data by meaning with no second database, no extension to load and nothing extra to deploy. Our js-vec-search example has done this since June. What we hadn't done was write it up properly, so this week we wrote the reference page, measured how far each approach goes, and found one bug on the way.

This is the whole thing, from table to search:

await env.DB.exec(`
  CREATE TABLE docs (id INTEGER PRIMARY KEY, title TEXT, embedding F32_BLOB(1536))
`);

await env.DB.prepare("INSERT INTO docs (title, embedding) VALUES (?, vector32(?))")
  .bind(title, embedding)          // a plain array of 1536 numbers
  .run();

const { results } = await env.DB.prepare(`
  SELECT id, title, vector_distance_cos(embedding, vector32(?)) AS distance
  FROM docs ORDER BY distance LIMIT 10
`).bind(queryEmbedding).all();

F32_BLOB(1536) is a column of 1536 float32 values. vector32() turns text like [0.1, 0.2, ...] into one, and vector_distance_cos gives the cosine distance between two, where smaller means closer in meaning. The binding sends parameters to c3 as JSON, and a JSON array is exactly the text vector32() reads, so the array an embeddings API hands back binds as it is.

js-vec-search wraps that in a Cell you can deploy. It embeds each document with OpenAI's text-embedding-3-small using your own API key, stores the result in an F32_BLOB(1536) column, and ranks documents against a query with the SELECT above. It has a small search page at /. This week the key moved from a c3 table into a vault binding, which is where a secret belongs.

That query compares the question against every row, and the example does that on purpose. It sounds like it should be slow, so we measured it on a release build of c3 on a laptop. Searching 10,000 rows of 1536 dimensions took 34 ms. 20,000 rows of 384 dimensions took 19 ms, and 2,000 rows of 1536 took 7 ms. The answers are exact, since every row gets looked at.

So a Cell with a few thousand documents, say a support knowledge base or a product catalogue, can search by meaning with one query and no setup beyond the column.

For bigger tables libSQL has an approximate index. You create it with libsql_vector_idx and query it with vector_top_k, and it reads a small part of the table instead of all of it. We loaded 2,000 rows of 1536 dimensions into a table that had the index on it from the start.

With the default settings, the load took 87.8 seconds. The slowest batch of 100 inserts took 5.4 seconds on its own. The database grew to 658 MB, against 16 MB for the same rows with no index. The index keeps a full-precision copy of each row's neighbouring vectors next to the row, so it ends up far bigger than the data it indexes. A search through it took 26 ms and found all ten of the true nearest rows.

libSQL has two options that shrink it. compress_neighbors=float8 stores the neighbour copies at 8 bits instead of 32, and max_neighbors=16 keeps fewer of them. With both, the same load took 10.8 seconds and 82 MB, and a search took about 4 ms. It found 7 of the true 10. Our test vectors were random numbers, which is about the hardest case for this kind of index, because there are no clusters for it to use. We haven't measured it on real embeddings yet.

no index float8, 16 neighbours default index 16 MB 82 MB 658 MB
The same 2,000 rows of 1536 dimensions with no index, with the two options, and with the defaults.

So the docs say to start with the full scan, add the index when the query's meta.duration_ms says to, and pass both options unless you've measured a reason not to.

Adding the index to a table that already had the 2,000 rows in it didn't go well. c3 cancels any statement that runs longer than 30 seconds, and building the index over 2,000 rows takes longer than that, so the CREATE INDEX failed with c3's timeout error. That part we expected.

What came next we didn't. vector_top_k on that index failed with index not found. Running the same CREATE INDEX again came back in a millisecond and reported success, and searches still found nothing.

libSQL keeps a vector index in three places: the index row in sqlite_master, a table of its own named <index>_shadow for the data, and a settings row in libsql_vector_meta_shadow. When c3 cancels the build, SQLite rolls the statement back, but the shadow table and the settings row can survive it. The next CREATE INDEX under that name finds the shadow table already there, takes the index as built, and fills nothing.

build finishes cancelled at 30 s sqlite_master d_idx_shadow libsql_vector_ meta_shadow index d_idx 2,000 rows d_idx settings rolled back still there, empty still there
Where libSQL keeps a vector index, and what a cancelled build leaves. The next CREATE INDEX finds the empty shadow table and builds nothing.

c3 2026.11.009 fixes it. When a vector CREATE INDEX fails, c3 drops whatever it left behind, and the timeout error says the index wasn't created and links to the docs. Before running one, c3 also clears shadow state that has no index row next to it, which repairs any database that hit this earlier. An index that existed before the statement is never touched.

To index a table that's already full, the docs walk through it: make a new table with the index already on it, copy the rows across in chunks small enough to finish well inside 30 seconds, and swap the names at the end.

Our export command hands back each database as a SQLite file that any SQLite tool opens. Stock SQLite doesn't know about vectors, though. It reads each one as a plain blob, has none of the vector_* functions, and refuses any insert into a table with a vector index. The export docs now say so: use a libSQL driver to keep searching, or drop the vector index before writing to the file with stock SQLite.

js-vec-search deploys with three commands: create the database, set your OpenAI key in the vault, and ribo deploy. The reference, with the index options, the chunked copy and the full list of functions, is at tissue.systems/docs/c3/vector-search.