Skip to content
Back to Cloud Services

Cloudflare Vectorize Vector Database

Edge vector database for semantic search and RAG — query millions of vectors with metadata filtering.

CloudflareAdvanced

Why

Vectorize stores embeddings at the edge for sub-50ms semantic search — no Pinecone/Weaviate server, scales to millions of vectors, and integrates with Workers AI for embeddings. Pay per query, free tier 10M queries.

Cloudflare's network spans 330+ cities in 125+ countries, serving 20% of all internet traffic. Workers have 0ms cold starts (isolate-based) and the free tier covers 100k requests/day.

When

Use for semantic search, RAG (retrieval-augmented generation), recommendation, and dedup. Avoid for exact-match lookups (use KV) or full-text search (use D1 FTS).

How

1. Create index — wrangler vectorize create my-index --dimensions 768 --metric cosine 2. Bind — [[vectorize]] binding="VECTOR" index_name="my-index" 3. Insert — env.VECTOR.upsert([{ id, values, metadata }]) 4. Query — env.VECTOR.query(topK, vector, { filter: { metadata } }) 5. Embeddings — use Workers AI to generate vectors from text 6. Metadata filter — { "source": "docs" } filters results 7. Reindex — wrangler vectorize create v2 with new dimensions, migrate

Example

// Semantic search: embed query, search Vectorize, return docs export default { async fetch(request: Request, env: Env): Promise<Response> { const { query } = await request.json(); // 1. Embed the query const { data } = await env.AI.run("@cf/baai/bge-base-en-v1.5", { text: [query] }); // 2. Search vector index with metadata filter const { matches } = await env.VECTOR.query(data[0], { topK: 5, filter: { source: "knowledge-base" }, }); // 3. Fetch full docs from D1 by ID const ids = matches.map(m => m.id); const { results } = await env.DB.prepare("SELECT * FROM docs WHERE id IN (?)").bind(ids.join(",")).all(); return Response.json(results); }, };

Common Problems

  • ⚠Dimension mismatch — index created with 768 dims, embeddings must match exactly
  • ⚠Reindexing is manual — changing model/dims requires new index + re-insert all vectors
  • ⚠Metadata filter limited — only equality, no range queries, pre-filter in D1 if needed

Best Practices

  • ✓Store full docs in D1/R2, only vectors in Vectorize — keeps index small and fast
  • ✓Use consistent embedding model — switching models requires full reindex
  • ✓Batch upserts — upsert 100 vectors/call, not 1, reduces API calls 100x

FAQ

What is Cloudflare Vectorize Vector Database and what problem does it solve?

Edge vector database for semantic search and RAG — query millions of vectors with metadata filtering. It lets developers deploy, store, and scale without self-managing infrastructure — a core reference for cloud service selection.

How do I get started with Cloudflare Vectorize Vector Database in 5 minutes?

Two steps to run it: (1) Create index — wrangler vectorize create my-index --dimensions 768 --metric cosine; (2) Bind — [[vectorize]] binding="VECTOR" index_name="my-index". Validate on the free tier first, then wire into production.

What is the #1 pitfall with Cloudflare Vectorize Vector Database?

The most frequent issue is: Dimension mismatch — index created with 768 dims, embeddings must match exactly. Run a pre-launch checklist item by item, and add policy/config scanning in CI.

What are the best practices for Cloudflare Vectorize Vector Database?

Best practices for Cloudflare Vectorize Vector Database include: Store full docs in D1/R2, only vectors in Vectorize — keeps index small and fast; Use consistent embedding model — switching models requires full reindex; Batch upserts — upsert 100 vectors/call, not 1, reduces API calls 100x. The first one — "Store full docs in D1/R2, only vectors in Vectorize — keeps index small and fast" — should be a team default baked into your IaC templates.

How do I control cost and avoid bill surprises with Cloudflare Vectorize Vector Database?

Three ways to prevent overspend: (1) tag every resource with env/team and enable billing alarms; (2) set budget thresholds to trigger Slack/email alerts; (3) review idle resources in Cost Explorer regularly and clean them up. Most Cloudflare Vectorize Vector Database options offer a free tier — validate within free quota before scaling.