Skip to content

VectorizeIndex

Source: src/Cloudflare/Vectorize/VectorizeIndex.ts

A Cloudflare Vectorize index for storing and querying vector embeddings.

Vectorize is a globally distributed vector database. Create an index as a resource, then bind it to a Worker to insert, upsert, and query vectors.

A Vectorize index is identified by its name and is immutable: its dimensions, metric, preset, and description are all fixed at creation. Changing any of them triggers a replacement.

Index with explicit dimensions and metric

const index = yield* Cloudflare.VectorizeIndex("my-index", {
dimensions: 768,
metric: "cosine",
});

Index from a managed embedding model preset

A preset fixes the dimensions and metric to match the named model.

const index = yield* Cloudflare.VectorizeIndex("my-index", {
preset: "@cf/baai/bge-base-en-v1.5",
});

Index with a description

const index = yield* Cloudflare.VectorizeIndex("my-index", {
dimensions: 1536,
metric: "euclidean",
description: "Product catalog embeddings",
});
const index = yield* Cloudflare.VectorizeConnection.bind(MyIndex);
// Insert vectors
yield* index.upsert([
{ id: "1", values: [0.1, 0.2, 0.3], metadata: { title: "doc" } },
]);
// Query the nearest neighbors
const matches = yield* index.query([0.1, 0.2, 0.3], { topK: 5 });