Vectorize: search your notes by meaning, not exact words
Vectorize (vector database for semantic search)
What it is
Vectorize is Cloudflare's vector database. A vector (also called an embedding) is a long list of numbers that an AI model produces to describe the meaning of a piece of text. Two sentences that mean similar things, such as "chest pain on exertion" and "angina when walking uphill", get vectors that sit close together, even though they share almost no words.
The usual pattern has three steps. First, a Worker sends each note or paragraph to an embedding model in Workers AI (lesson 12), for example @cf/baai/bge-base-en-v1.5, which returns 768 numbers. Second, the Worker stores those numbers in a Vectorize index with insert or upsert, along with an id and a little metadata such as the note title or URL. Third, when someone searches, the Worker turns the question into a vector the same way and calls query to get the closest matches (topK, for example the best 5).
You create an index once, either in the dashboard under Storage and Databases, then Vectorize, or with Wrangler: npx wrangler vectorize create cpd-notes --dimensions=768 --metric=cosine. The dimensions must match the model you use, and they cannot be changed later. The Worker then reaches the index through a binding in wrangler.toml: a [[vectorize]] block with binding = "VECTORIZE" and index_name = "cpd-notes", which shows up in code as env.VECTORIZE.
Why it matters
Ordinary search only finds the exact words you typed. Meaning-based search finds the CPD note about "tiredness and low ferritin" when you search "iron deficiency fatigue", which is how you actually remember things in a busy clinic day.
It is the storage half of "ask my own documents" tools, often called RAG (retrieval augmented generation): Vectorize finds the three most relevant paragraphs, and a Workers AI chat model answers using only those, so the answer comes from your notes rather than the model's guesses.
It fits alongside what you already know: D1 or R2 hold the full text, Vectorize holds only the vectors and a pointer back, and everything runs on your Cloudflare account. Keep patient-identifiable information out of it, the same as any other cloud tool.
On your account
From your own setup: your bots publish hundreds of cards and posts, such as the prompt library on prompts.drkotha.com and the CPD write-ups on drkotha.com subdomains. A small Worker could embed each card's title and summary into an index called prompts-index, and a search box would then find "a prompt for a tracker app" even if the card says "habit log builder".
A minimal query in a Worker looks like this: const { data } = await env.AI.run("@cf/baai/bge-base-en-v1.5", { text: [question] }); const results = await env.VECTORIZE.query(data[0], { topK: 5, returnMetadata: "all" }); Each result has an id, a score (closer to 1 means more similar with cosine), and the metadata you stored.
Nothing was created for this lesson. This desk only redeployed its own Worker, cloudflare-tutor, and did not create any index or touch ainews, aiweekly, the AI News root redirect rule, DNS, or any other Worker.
Do this yourself
These stay in the dashboard, on your side. This site does not change DNS, routes, or other Workers.
- On your own machine, run npx wrangler vectorize create practice-notes --dimensions=768 --metric=cosine, then open Storage and Databases, then Vectorize in the dashboard and confirm the new index shows 768 dimensions and the cosine metric (you can delete it afterwards with npx wrangler vectorize delete practice-notes).