$npx -y skills add jackspace/ClaudeSkillz --skill cloudflare-vectorizeComplete knowledge domain for Cloudflare Vectorize - globally distributed vector database for building semantic search, RAG (Retrieval Augmented Generation), and AI-powered applications. Use when: creating vector indexes, inserting embeddings, querying vectors, implementing seman
| 1 | # Cloudflare Vectorize |
| 2 | |
| 3 | Complete implementation guide for Cloudflare Vectorize - a globally distributed vector database for building semantic search, RAG (Retrieval Augmented Generation), and AI-powered applications with Cloudflare Workers. |
| 4 | |
| 5 | **Status**: Production Ready ✅ |
| 6 | **Last Updated**: 2025-10-21 |
| 7 | **Dependencies**: cloudflare-worker-base (for Worker setup), cloudflare-workers-ai (for embeddings) |
| 8 | **Latest Versions**: wrangler@4.43.0, @cloudflare/workers-types@4.20251014.0 |
| 9 | **Token Savings**: ~65% |
| 10 | **Errors Prevented**: 8 |
| 11 | **Dev Time Saved**: ~3 hours |
| 12 | |
| 13 | ## What This Skill Provides |
| 14 | |
| 15 | ### Core Capabilities |
| 16 | - ✅ **Index Management**: Create, configure, and manage vector indexes |
| 17 | - ✅ **Vector Operations**: Insert, upsert, query, delete, and list vectors |
| 18 | - ✅ **Metadata Filtering**: Advanced filtering with 10 metadata indexes per index |
| 19 | - ✅ **Semantic Search**: Find similar vectors using cosine, euclidean, or dot-product metrics |
| 20 | - ✅ **RAG Patterns**: Complete retrieval-augmented generation workflows |
| 21 | - ✅ **Workers AI Integration**: Native embedding generation with @cf/baai/bge-base-en-v1.5 |
| 22 | - ✅ **OpenAI Integration**: Support for text-embedding-3-small/large models |
| 23 | - ✅ **Document Processing**: Text chunking and batch ingestion pipelines |
| 24 | |
| 25 | ### Templates Included |
| 26 | 1. **basic-search.ts** - Simple vector search with Workers AI |
| 27 | 2. **rag-chat.ts** - Full RAG chatbot with context retrieval |
| 28 | 3. **document-ingestion.ts** - Document chunking and embedding pipeline |
| 29 | 4. **metadata-filtering.ts** - Advanced filtering examples |
| 30 | |
| 31 | ## Critical Setup Rules |
| 32 | |
| 33 | ### ⚠️ MUST DO BEFORE INSERTING VECTORS |
| 34 | ```bash |
| 35 | # 1. Create the index with FIXED dimensions and metric |
| 36 | npx wrangler vectorize create my-index \ |
| 37 | --dimensions=768 \ |
| 38 | --metric=cosine |
| 39 | |
| 40 | # 2. Create metadata indexes IMMEDIATELY (before inserting vectors!) |
| 41 | npx wrangler vectorize create-metadata-index my-index \ |
| 42 | --property-name=category \ |
| 43 | --type=string |
| 44 | |
| 45 | npx wrangler vectorize create-metadata-index my-index \ |
| 46 | --property-name=timestamp \ |
| 47 | --type=number |
| 48 | ``` |
| 49 | |
| 50 | **Why**: Metadata indexes MUST exist before vectors are inserted. Vectors added before a metadata index was created won't be filterable on that property. |
| 51 | |
| 52 | ### Index Configuration (Cannot Be Changed Later) |
| 53 | |
| 54 | ```bash |
| 55 | # Dimensions MUST match your embedding model output: |
| 56 | # - Workers AI @cf/baai/bge-base-en-v1.5: 768 dimensions |
| 57 | # - OpenAI text-embedding-3-small: 1536 dimensions |
| 58 | # - OpenAI text-embedding-3-large: 3072 dimensions |
| 59 | |
| 60 | # Metrics determine similarity calculation: |
| 61 | # - cosine: Best for normalized embeddings (most common) |
| 62 | # - euclidean: Absolute distance between vectors |
| 63 | # - dot-product: For non-normalized vectors |
| 64 | ``` |
| 65 | |
| 66 | ## Wrangler Configuration |
| 67 | |
| 68 | **wrangler.jsonc**: |
| 69 | ```jsonc |
| 70 | { |
| 71 | "name": "my-vectorize-worker", |
| 72 | "main": "src/index.ts", |
| 73 | "compatibility_date": "2025-10-21", |
| 74 | "vectorize": [ |
| 75 | { |
| 76 | "binding": "VECTORIZE_INDEX", |
| 77 | "index_name": "my-index" |
| 78 | } |
| 79 | ], |
| 80 | "ai": { |
| 81 | "binding": "AI" |
| 82 | } |
| 83 | } |
| 84 | ``` |
| 85 | |
| 86 | ## TypeScript Types |
| 87 | |
| 88 | ```typescript |
| 89 | export interface Env { |
| 90 | VECTORIZE_INDEX: VectorizeIndex; |
| 91 | AI: Ai; |
| 92 | } |
| 93 | |
| 94 | interface VectorizeVector { |
| 95 | id: string; |
| 96 | values: number[] | Float32Array | Float64Array; |
| 97 | namespace?: string; |
| 98 | metadata?: Record<string, string | number | boolean | string[]>; |
| 99 | } |
| 100 | |
| 101 | interface VectorizeMatches { |
| 102 | matches: Array<{ |
| 103 | id: string; |
| 104 | score: number; |
| 105 | values?: number[]; |
| 106 | metadata?: Record<string, any>; |
| 107 | namespace?: string; |
| 108 | }>; |
| 109 | count: number; |
| 110 | } |
| 111 | ``` |
| 112 | |
| 113 | ## Common Operations |
| 114 | |
| 115 | ### 1. Insert vs Upsert |
| 116 | |
| 117 | ```typescript |
| 118 | // INSERT: Keeps first insertion if ID exists |
| 119 | await env.VECTORIZE_INDEX.insert([ |
| 120 | { |
| 121 | id: "doc-1", |
| 122 | values: [0.1, 0.2, 0.3, ...], |
| 123 | metadata: { title: "First version" } |
| 124 | } |
| 125 | ]); |
| 126 | |
| 127 | // UPSERT: Overwrites with latest if ID exi |