docs/components/vectordbs/dbs/turbopuffer.mdx
Turbopuffer is a serverless vector database optimized for low-latency search at scale. It offers cost-effective vector storage with native metadata filtering.
os.environ["OPENAI_API_KEY"] = "sk-xx" os.environ["TURBOPUFFER_API_KEY"] = "tpuf_xxxxxxxxxxxx"
config = { "vector_store": { "provider": "turbopuffer", "config": { "collection_name": "movie_preferences", "embedding_model_dims": 1536, "region": "gcp-us-central1", } } }
m = Memory.from_config(config)
messages = [ {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, {"role": "assistant", "content": "How about thriller movies? They can be quite engaging."}, {"role": "user", "content": "I'm not a big fan of thrillers but I love sci-fi."}, {"role": "assistant", "content": "Got it! I'll suggest sci-fi movies instead."} ]
m.add(messages, user_id="alice", metadata={"category": "movies"})
results = m.search(query="sci-fi recommendations", filters={"user_id": "alice"})
```typescript TypeScript
import { Memory } from "mem0ai/oss";
// Set TURBOPUFFER_API_KEY in your environment, or pass it as config.apiKey below.
const config = {
vectorStore: {
provider: "turbopuffer",
config: {
collectionName: "movie_preferences",
region: "gcp-us-central1",
},
},
};
const memory = new Memory(config);
const messages = [
{ role: "user", content: "I'm planning to watch a movie tonight. Any recommendations?" },
{ role: "assistant", content: "How about thriller movies? They can be quite engaging." },
{ role: "user", content: "I'm not a big fan of thrillers but I love sci-fi." },
{ role: "assistant", content: "Got it! I'll suggest sci-fi movies instead." },
];
await memory.add(messages, { userId: "alice", metadata: { category: "movies" } });
// Search memories
const results = await memory.search("sci-fi recommendations", { userId: "alice" });
Here are the parameters available for configuring Turbopuffer:
| Parameter | Description | Default Value |
|---|---|---|
collection_name | Name of the namespace/collection | mem0 |
embedding_model_dims | Dimensions of the embedding model (must match your chosen embedding model) | 1536 |
api_key | Turbopuffer API key | Environment variable: TURBOPUFFER_API_KEY |
region | Turbopuffer region | gcp-us-central1 |
distance_metric | Distance metric for vector similarity (cosine_distance or euclidean_squared) | cosine_distance |
batch_size | Batch size for bulk operations | 100 |
extra_params | Additional parameters for the Turbopuffer client | None |
| Region | Location |
|---|---|
gcp-us-central1 | Iowa, USA (Default) |
aws-us-west-2 | Oregon, USA |
const config = {
vectorStore: {
provider: "turbopuffer",
config: {
collectionName: "my_memories",
apiKey: "tpuf_xxxxxxxxxxxx",
region: "aws-us-west-2",
distanceMetric: "cosine_distance",
batchSize: 200,
},
},
};