Vector search
One field, one index
Section titled “One field, one index”t.vector({ dimensions }) is an embedding: a fixed-length list of numbers from 1 to 1,536, stored as one f32le:v1:<base64> string so a row is byte-identical through SQLite, the log, a snapshot and a backup. It is optional like any other field, so existing rows stay valid, and it is never returned by a default read.
note: model({ title: t.string(), excerpt: t.string(), archived: t.boolean().default(false), embedding: t.vector({ dimensions: 768 }).optional(),})A deployment mirrors one vector attribute of one model into one Cloudflare Vectorize index, and declares it in tapedb.vectorize.json so the CLI can provision it:
{ "model": "note", "field": "embedding", "filterFields": ["archived"] }That file belongs to the CLI, not to Wrangler: wrangler.jsonc is validated and warns about unknown fields, so a correct project would warn on every deploy.
defineTapeDB({ schema, vectorize: { index: "VECTORIZE", model: "note", field: "embedding", filterFields: ["archived"], embed: { binding: "AI" }, // optional: let callers search with words keywordFields: ["title", "excerpt"], // optional: exact-term recall rerank: { binding: "AI" }, // optional: cross-encoder reordering },})The schema and the defineTapeDB option are checked when the Worker is defined: the field must be that model’s vector attribute, a filter must be a flat, non-personal string, number or boolean, and at most ten filters (the provider’s metadata-index ceiling). A deployment without the option creates no table, reads no binding and writes nothing.
Deploying
Section titled “Deploying”npx tapedb-cli deploy validates the declaration against the schema, derives the index name from deployment identity (tapedb-<worker>-<model>), creates the index and one metadata index per filter, records index and its ownership in that file, and writes the binding the Worker reads into wrangler.jsonc:
"vectorize": [{ "binding": "VECTORIZE", "index_name": "tapedb-app-note" }]Because the name is derived, a repeat deploy, two concurrent deploys and a retry after a failed upload converge on one index. Every later deploy reads the live index and refuses to upload when anything disagrees with the record or the schema — another dimension count, another metric, a metadata index of the wrong type, or an ownership record naming another account or worker — naming both values and deploying nothing. An index that already exists without a record is refused rather than adopted; if it is yours, add index to tapedb.vectorize.json and deploy again.
A deployment restricted to eu or fedramp refuses vector search before provisioning anything: Vectorize cannot meet that residency, and an index cannot be redeployed out of a jurisdiction.
Writing and indexing
Section titled “Writing and indexing”Embeddings on a row are application-supplied: write the text and its matching vector together, or clear the vector on an edit that invalidates it, and no write ever calls a model. The models a search may call are the ones you configure: embed turns the query’s words into a vector, and rerank scores candidates against them.
The intent to index a row is committed inside the write’s transaction, by a trigger on the indexed model, into _vector_queue in the workspace’s own SQLite, and drained from the durability alarm. The index being slow or down therefore costs a retry, never a write.
Each publish carries a digest over the model, the row, the vector’s canonical bytes and the configured filter values. A row that changed nothing is not sent again; a row whose only change is a filter value is, because the provider filters before ranking and would otherwise keep matching on the old value.
Visibility is asynchronous. Measured on a live index, an accepted upsert became searchable 73–103 seconds later, so pending is the ordinary state of a fresh row.
Searching
Section titled “Searching”const { rows, truncated } = await db.note.search({ text: "quarterly planning", // or vector: await embed("…") limit: 10, filter: { archived: false }, select: ["title", "excerpt"],});text is the query in words: the engine embeds it with the deployment’s vectorize.embed binding, which defaults to @cf/baai/bge-base-en-v1.5 and must produce the field’s declared dimensions. text and vector are alternatives, so a caller either sends words or runs the embedding model itself, and sending both is refused. Without embed, only vector works, which is what a pipeline that embeds its corpus already produces.
keywordFields adds exact-term recall: those strings are mirrored into an FTS5 table inside the workspace’s own SQLite by triggers, so a text query matches a part number, an acronym or a name the embedding blurs, finds a row whose text changed after its vector was published, and finds a row written a second ago while its vector is still pending. The two ranked lists are fused by reciprocal rank.
rerank scores each candidate’s passage against the question with @cf/baai/bge-reranker-base, and its order and relevance replace the fused ranking. search.reranked says whether that happened; a reranker that fails leaves the retrieval order rather than failing the search.
search.mode says what the score means: vector is the provider’s cosine similarity, hybrid is that fused rank, comparable inside one answer only.
limit defaults to 10 and 50 is the ceiling; a larger number is refused rather than clamped. filter is equality on the deployment’s declared filter fields, applied before the ranking. select narrows the rows like a read’s select, and the embedding is never returned.
The index is a cache of earlier writes, never the answer. Every candidate is re-read from the workspace’s SQLite through the same path a findMany takes, so view, where and row-level rules decide what comes back, an ID the database no longer holds is dropped, and a row whose embedding or filter value changed after it was published is dropped rather than ranked on a vector it no longer has. A row the caller may not see is absent, not blurred: an answer that finds nothing and one that is allowed nothing have the same shape.
Status and operators
Section titled “Status and operators”GET /engine/workspaces/:id/status reports the queue:
{ "vectorize": { "pending": 3, "failing": 1, "deadLettered": 0, "indexed": 412, "lastMutationId": "01J...", "fenced": false, "purge": null, "rebuild": null }}Three admin-or-owner routes act on one workspace’s index; an ordinary member is refused before learning whether vector search is configured:
| route | |
|---|---|
POST …/vector/retry |
requeue failed and dead-lettered work; the next drain re-reads each row from the database |
POST …/vector/rebuild |
one crash-resumable job per workspace: forget the accepted digests, delete entries whose row is gone, re-publish every row in bounded batches from a cursor in SQLite. Concurrent requests get one jobId |
POST …/vector/rows |
{ model, ids } → unindexed, pending, indexed or failed, for rows the caller may read |
While a rebuild runs, search for that workspace answers 503 vector_search_unavailable with retry-after: 30, because a half-built index would rank on a state the database no longer has. vectorize.rebuild in the status is the visible cause.
Erasing a workspace erases its vectors too: a fence in R2 is written before any delete, each batch is confirmed against the mutation ID its own delete was accepted under, and the ledger resumes after an eviction. A restored backup is re-indexed under the destination’s identity, so an erased workspace cannot come back through a stale index.
What is not here
Section titled “What is not here”Three things are outside this release, and each is a mechanism of its own rather than an unfinished part of search:
- Subscriptions to search results. A read goes live when you
subscribeto it. A search does not: it is one call that answers once, and there is no change feed over a ranked list. - Ranking across workspaces. A workspace is one SQLite database with one index over it, and every candidate is re-read through that workspace’s access rules before it is returned. Fusing ranked lists from several workspaces would rank rows before those rules could refuse them, so this is a different design, not a wider query.
- Providers other than Vectorize. The index is a cache of earlier writes: a queue committed inside the write’s transaction, a digest per publish, metadata indexes for filters, a crash-resumable rebuild and an erasure fence. Another provider is a second implementation of that contract, not a different HTTP client.
Search needs connectivity because the index lives at the provider. Ordinary offline writes are unaffected: the intent to index commits inside the write’s own transaction, so a slow or unreachable provider costs a retry, never a write.