Skip to navigation

Vector Search

Find semantically similar documents using approximate nearest neighbor (ANN) and exact kNN search.

Overview

turbopuffer supports both approximate nearest neighbor (ANN) search for speed at scale, and exact kNN search for recall-critical workloads. Both operate over dense float vector embeddings stored in your namespace.

ANN search uses an index to find the nearest neighbors quickly, trading a small amount of recall for significant speed gains at scale.

const results = await client.namespaces.query("my-namespace", {
rankBy: ["vector", "ANN", queryVector],
topK: 20,
distanceMetric: "cosine_distance",
});

kNN performs an exhaustive search — guaranteed recall, slower on large datasets.

const results = await client.namespaces.query("my-namespace", {
rankBy: ["vector", "kNN", queryVector],
topK: 20,
});

Distance metrics

MetricDescription
cosine_distance1 - cosine_similarity. Ranges 0–2. Lower is better.
euclidean_squaredsum((x - y)^2). Lower is better.

Auto-embedding

turbopuffer can generate embeddings automatically from a text attribute using a hosted model:

await client.namespaces.write("my-namespace", {
schema: {
text: {
type: "string",
embed: { model: "text-embedding-3-small" },
},
},
});

Then query using an Embed expression instead of a raw vector:

const results = await client.namespaces.query("my-namespace", {
rankBy: ["text", "ANN", ["Embed", "my search query"]],
topK: 10,
});