feat(vector-stores): add Cassandra provider to TypeScript OSS SDK (#5823)

Co-authored-by: kartik-mem0 <kartik.labhshetwar@mem0.ai>
This commit is contained in:
Rod Boev
2026-07-06 12:27:32 -04:00
committed by GitHub
parent fec7cdf118
commit 7fb3feb5cd
9 changed files with 1183 additions and 7 deletions
+89 -7
View File
@@ -7,7 +7,8 @@ description: "Use Apache Cassandra as a distributed vector store in Mem0 with se
### Usage
```python
<CodeGroup>
```python Python
import os
from mem0 import Memory
@@ -37,11 +38,43 @@ messages = [
m.add(messages, user_id="alice", metadata={"category": "movies"})
```
```typescript TypeScript
import { Memory } from 'mem0ai/oss';
// Set OPENAI_API_KEY in your environment for the default embedder
const config = {
vectorStore: {
provider: 'cassandra',
config: {
contactPoints: ['127.0.0.1'],
localDataCenter: 'datacenter1', // required with contactPoints; "datacenter1" is the default for a single-node cluster
port: 9042,
username: 'cassandra',
password: 'cassandra',
keyspace: 'mem0',
collectionName: 'memories',
},
},
};
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 thriller movies but I love sci-fi movies."},
{"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."}
]
await memory.add(messages, { userId: "alice", metadata: { category: "movies" } });
```
</CodeGroup>
#### Using DataStax Astra DB
For managed Cassandra with DataStax Astra DB:
```python
<CodeGroup>
```python Python
config = {
"vector_store": {
"provider": "cassandra",
@@ -57,8 +90,24 @@ config = {
}
```
```typescript TypeScript
const config = {
vectorStore: {
provider: 'cassandra',
config: {
username: 'token',
password: 'AstraCS:...', // Your Astra DB application token
keyspace: 'mem0',
collectionName: 'memories',
secureConnectBundle: '/path/to/secure-connect-bundle.zip',
},
},
};
```
</CodeGroup>
<Note>
When using DataStax Astra DB, provide the secure connect bundle path. The contact_points parameter is ignored when a secure connect bundle is provided.
When using DataStax Astra DB, provide the secure connect bundle path. Contact points and `localDataCenter` are not needed when a secure connect bundle is provided.
</Note>
### Config
@@ -78,6 +127,10 @@ Here are the parameters available for configuring Apache Cassandra:
| `protocol_version` | CQL protocol version | `4` |
| `load_balancing_policy` | Custom load balancing policy | `None` |
<Note>
The TypeScript SDK uses camelCase keys: `contactPoints`, `collectionName`, `embeddingModelDims`, `secureConnectBundle`, `protocolVersion`, and `loadBalancingPolicy`. It also requires `localDataCenter` (for example, `datacenter1`) when you connect with `contactPoints` instead of a secure connect bundle. The Node.js driver needs this to route queries; it has no default.
</Note>
### Setup
#### Option 1: Local Cassandra Setup using Docker:
@@ -139,14 +192,20 @@ brew services start cassandra
cqlsh
```
### Python Client Installation
### Client Installation
Install the required Python package:
Install the driver for your SDK:
```bash
<CodeGroup>
```bash Python
pip install cassandra-driver
```
```bash TypeScript
npm install cassandra-driver
```
</CodeGroup>
### Performance Considerations
- **Replication Factor**: For production, use replication factor of at least 3
@@ -156,7 +215,8 @@ pip install cassandra-driver
### Advanced Configuration
```python
<CodeGroup>
```python Python
from cassandra.policies import DCAwareRoundRobinPolicy
config = {
@@ -176,6 +236,28 @@ config = {
}
```
```typescript TypeScript
// The Node.js driver routes to localDataCenter by default, so set it to your
// primary DC for datacenter-aware routing. Pass loadBalancingPolicy only when
// you need a custom policy from the cassandra-driver package.
const config = {
vectorStore: {
provider: 'cassandra',
config: {
contactPoints: ['node1.example.com', 'node2.example.com', 'node3.example.com'],
localDataCenter: 'DC1',
port: 9042,
username: 'mem0_user',
password: 'secure_password',
keyspace: 'mem0_prod',
collectionName: 'memories',
protocolVersion: 4,
},
},
};
```
</CodeGroup>
<Warning>
For production use, configure appropriate replication strategies and consistency levels based on your availability and consistency requirements.
</Warning>