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/api.md
1# Vectorize API Reference23## Types45```typescript6interface VectorizeVector {7id: string; // Max 64 bytes8values: number[]; // Must match index dimensions9namespace?: string; // Optional partition (max 64 bytes)10metadata?: Record<string, any>; // Max 10 KiB11}12```1314## Query1516```typescript17const matches = await env.VECTORIZE.query(queryVector, {18topK: 10, // Max 100 (or 20 with returnValues/returnMetadata:"all")19returnMetadata: "indexed", // "none" | "indexed" | "all"20returnValues: false,21namespace: "tenant-123",22filter: { category: "docs" }23});24// matches.matches[0] = { id, score, metadata? }25```2627**returnMetadata:** `"none"` (fastest) → `"indexed"` (recommended) → `"all"` (topK max 20)2829**queryById (V2 only):** Search using existing vector as query.30```typescript31await env.VECTORIZE.queryById("doc-123", { topK: 5 });32```3334## Insert/Upsert3536```typescript37// Insert: ignores duplicates (keeps first)38await env.VECTORIZE.insert([{ id, values, metadata }]);3940// Upsert: overwrites duplicates (keeps last)41await env.VECTORIZE.upsert([{ id, values, metadata }]);42```4344**Max 1,000 vectors per call (Workers) / 5,000 (HTTP API).** Queryable after 5-10 seconds.4546## Other Operations4748```typescript49// Get by IDs50const vectors = await env.VECTORIZE.getByIds(["id1", "id2"]);5152// Delete (max 1000 IDs per call)53await env.VECTORIZE.deleteByIds(["id1", "id2"]);5455// Index info56const info = await env.VECTORIZE.describe();57// { dimensions, metric, vectorCount }58```5960## Filtering6162Requires metadata index. Filter operators:6364| Operator | Example |65|----------|---------|66| `$eq` (implicit) | `{ category: "docs" }` |67| `$ne` | `{ status: { $ne: "deleted" } }` |68| `$in` / `$nin` | `{ tag: { $in: ["sale"] } }` |69| `$lt`, `$lte`, `$gt`, `$gte` | `{ price: { $lt: 100 } }` |7071**Constraints:** Max 2048 bytes, no dots/`$` in keys, values: string/number/boolean/null.7273## Performance7475| Configuration | topK Limit | Speed |76|--------------|------------|-------|77| No metadata | 100 | Fastest |78| `returnMetadata: "indexed"` | 100 | Fast |79| `returnMetadata: "all"` | 20 | Slower |80| `returnValues: true` | 20 | Slower |8182**Batch operations:** Always batch (1,000/call via Workers, 5,000 via HTTP API) for optimal throughput.8384```typescript85for (let i = 0; i < vectors.length; i += 1000) {86await env.VECTORIZE.upsert(vectors.slice(i, i + 1000));87}88```89