Skip to content

armgit / mem0

Public Imported from GitHub
0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

3.6 KB
Raw Blame
---
title: "Upstash Vector"
description: "Use Upstash Vector as a serverless vector database in Mem0 with optional built-in embedding models."
---
[Upstash Vector](https://upstash.com/docs/vector) is a serverless vector database with built-in embedding models.

### Usage with Upstash embeddings

You can enable the built-in embedding models by setting `enable_embeddings` to `True`. This allows you to use Upstash's embedding models for vectorization.

<Note>
    Server-side Upstash embeddings (`enable_embeddings`) are available in the Python SDK only. The TypeScript SDK always embeds text with your configured embedder before writing to Upstash, so use the external embedding provider setup below.
</Note>

```python
import os
from mem0 import Memory

os.environ["UPSTASH_VECTOR_REST_URL"] = "..."
os.environ["UPSTASH_VECTOR_REST_TOKEN"] = "..."

config = {
    "vector_store": {
        "provider": "upstash_vector",
        "config": {
            "enable_embeddings": True,
        }
    }
}

m = Memory.from_config(config)
m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
```

<Note>
    Setting `enable_embeddings` to `True` will bypass any external embedding provider you have configured.
</Note>

### Usage with external embedding providers

<CodeGroup>
```python Python
import os
from mem0 import Memory

os.environ["OPENAI_API_KEY"] = "..."
os.environ["UPSTASH_VECTOR_REST_URL"] = "..."
os.environ["UPSTASH_VECTOR_REST_TOKEN"] = "..."

config = {
    "vector_store": {
        "provider": "upstash_vector",
    },
    "embedder": {
        "provider": "openai",
        "config": {
            "model": "text-embedding-3-large"
        },
    }
}

m = Memory.from_config(config)
m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
```

```typescript TypeScript
import { Memory } from "mem0ai/oss";

// Set OPENAI_API_KEY, UPSTASH_VECTOR_REST_URL, and UPSTASH_VECTOR_REST_TOKEN in your environment.
const config = {
  embedder: {
    provider: "openai",
    config: {
      apiKey: process.env.OPENAI_API_KEY,
      model: "text-embedding-3-large",
    },
  },
  vectorStore: {
    provider: "upstash_vector",
    config: {
      collectionName: "memories",
      url: process.env.UPSTASH_VECTOR_REST_URL,
      token: process.env.UPSTASH_VECTOR_REST_TOKEN,
    },
  },
};

const memory = new Memory(config);
await memory.add("Likes to play cricket on weekends", {
  userId: "alice",
  metadata: { category: "hobbies" },
});
```
</CodeGroup>

### Config

Here are the parameters available for configuring Upstash Vector:

| Parameter           | Description                        | Default Value |
| ------------------- | ---------------------------------- | ------------- |
| `url`               | URL for the Upstash Vector index   | `None`        |
| `token`             | Token for the Upstash Vector index | `None`        |
| `client`            | An `upstash_vector.Index` instance | `None`        |
| `collection_name`   | The default namespace used         | `"mem0"`      |
| `enable_embeddings` | Whether to use Upstash embeddings  | `False`       |

<Note>
  When `url` and `token` are not provided, the `UPSTASH_VECTOR_REST_URL` and
  `UPSTASH_VECTOR_REST_TOKEN` environment variables are used.
</Note>

<Note>
  The TypeScript SDK uses camelCase config keys (`collectionName`, `url`, `token`), where `collectionName` is required. Pass `url` and `token` (or a preconfigured `client`) explicitly, since the TypeScript SDK does not read them from environment variables. `enable_embeddings` is not supported in TypeScript.
</Note>