## Turbopuffer

Turbopuffer is a serverless vector database optimized for low-latency search at scale. It offers cost-effective vector storage with native metadata filtering.

### Usage

#### Python

```python
import os
from mem0 import Memory

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"})

# Search memories
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" });
```

### Config

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`                    |

**TypeScript (Node.js) config keys** are camelCase: `collectionName`, `apiKey`, `region`, `distanceMetric`, and `batchSize`. The TypeScript SDK infers the vector dimension from your embedder, so `embeddingModelDims` is not required.

### Regions

| Region                | Location                     |
| --------------------- | ---------------------------- |
| `gcp-us-central1`    | Iowa, USA (Default)         |
| `aws-us-west-2`      | Oregon, USA                  |

### Config Example

#### Python

```python
config = {
    "vector_store": {
        "provider": "turbopuffer",
        "config": {
            "collection_name": "my_memories",
            "embedding_model_dims": 1536,
            "api_key": "tpuf_xxxxxxxxxxxx",
            "region": "aws-us-west-2",
            "distance_metric": "cosine_distance",
            "batch_size": 200,
        }
    }
}
```

#### TypeScript

```typescript
const config = {
  vectorStore: {
    provider: "turbopuffer",
    config: {
      collectionName: "my_memories",
      apiKey: "tpuf_xxxxxxxxxxxx",
      region: "aws-us-west-2",
      distanceMetric: "cosine_distance",
      batchSize: 200,
    },
  },
};
```
