Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/vectorize/README.md
1# Cloudflare Vectorize23Globally distributed vector database for AI applications. Store and query vector embeddings for semantic search, recommendations, RAG, and classification.45**Status:** Generally Available (GA) | **Last Updated:** 2026-01-2767## Quick Start89```typescript10// 1. Create index11// npx wrangler vectorize create my-index --dimensions=768 --metric=cosine1213// 2. Configure binding (wrangler.jsonc)14// { "vectorize": [{ "binding": "VECTORIZE", "index_name": "my-index" }] }1516// 3. Query vectors17const matches = await env.VECTORIZE.query(queryVector, { topK: 5 });18```1920## Key Features2122- **10M vectors per index** (V2)23- Dimensions up to 1536 (32-bit float)24- Three distance metrics: cosine, euclidean, dot-product25- Metadata filtering (up to 10 indexes)26- Namespace support (50K namespaces paid, 1K free)27- Seamless Workers AI integration28- Global distribution2930## Reading Order3132| Task | Files to Read |33|------|---------------|34| New to Vectorize | README only |35| Implement feature | README + api + patterns |36| Setup/configure | README + configuration |37| Debug issues | gotchas |38| Integrate with AI | README + patterns |39| RAG implementation | README + patterns |4041## File Guide4243- **README.md** (this file): Overview, quick decisions44- **api.md**: Runtime API, types, operations (query/insert/upsert)45- **configuration.md**: Setup, CLI, metadata indexes46- **patterns.md**: RAG, Workers AI, OpenAI, LangChain, multi-tenant47- **gotchas.md**: Limits, pitfalls, troubleshooting4849## Distance Metric Selection5051Choose based on your use case:5253```54What are you building?55├─ Text/semantic search → cosine (most common)56├─ Image similarity → euclidean57├─ Recommendation system → dot-product58└─ Pre-normalized vectors → dot-product59```6061| Metric | Best For | Score Interpretation |62|--------|----------|---------------------|63| `cosine` | Text embeddings, semantic similarity | Higher = closer (1.0 = identical) |64| `euclidean` | Absolute distance, spatial data | Lower = closer (0.0 = identical) |65| `dot-product` | Recommendations, normalized vectors | Higher = closer |6667**Note:** Index configuration is immutable. Cannot change dimensions or metric after creation.6869## Multi-Tenancy Strategy7071```72How many tenants?73├─ < 50K tenants → Use namespaces (recommended)74│ ├─ Fastest (filter before vector search)75│ └─ Strict isolation76├─ > 50K tenants → Use metadata filtering77│ ├─ Slower (post-filter after vector search)78│ └─ Requires metadata index79└─ Per-tenant indexes → Only if compliance mandated80└─ 50K index limit per account (paid plan)81```8283## Common Workflows8485### Semantic Search8687```typescript88// 1. Generate embedding89const result = await env.AI.run("@cf/baai/bge-base-en-v1.5", { text: [query] });9091// 2. Query Vectorize92const matches = await env.VECTORIZE.query(result.data[0], {93topK: 5,94returnMetadata: "indexed"95});96```9798### RAG Pattern99100```typescript101// 1. Generate query embedding102const embedding = await env.AI.run("@cf/baai/bge-base-en-v1.5", { text: [query] });103104// 2. Search Vectorize105const matches = await env.VECTORIZE.query(embedding.data[0], { topK: 5 });106107// 3. Fetch full documents from R2/D1/KV108const docs = await Promise.all(matches.matches.map(m =>109env.R2.get(m.metadata.key).then(obj => obj?.text())110));111112// 4. Generate LLM response with context113const answer = await env.AI.run("@cf/meta/llama-3-8b-instruct", {114prompt: `Context: ${docs.join("\n\n")}\n\nQuestion: ${query}\n\nAnswer:`115});116```117118## Critical Gotchas119120See `gotchas.md` for details. Most important:1211221. **Async mutations**: Inserts take 5-10s to be queryable1232. **500 batch limit**: Workers API enforces 500 vectors per call (undocumented)1243. **Metadata truncation**: `"indexed"` returns first 64 bytes only1254. **topK with metadata**: Max 20 (not 100) when using returnValues or returnMetadata: "all"1265. **Metadata indexes first**: Must create before inserting vectors127128## Resources129130- [Official Docs](https://developers.cloudflare.com/vectorize/)131- [Client API Reference](https://developers.cloudflare.com/vectorize/reference/client-api/)132- [Workers AI Models](https://developers.cloudflare.com/workers-ai/models/#text-embeddings)133- [Discord: #vectorize](https://discord.cloudflare.com)134