feat(ts-sdk): add OpenSearch vector store (#5810)

Co-authored-by: kartik-mem0 <kartik.labhshetwar@mem0.ai>
This commit is contained in:
AxelRay
2026-07-07 17:10:20 +07:00
committed by GitHub
parent 002fe46ab3
commit 87276ef968
9 changed files with 886 additions and 3 deletions
+62 -3
View File
@@ -6,12 +6,18 @@ description: "Use OpenSearch as a vector database in Mem0 with k-NN search suppo
### Installation
OpenSearch support requires additional dependencies. Install them with:
OpenSearch support requires an additional client library. Install the one for your SDK:
```bash
<CodeGroup>
```bash Python
pip install opensearch-py
```
```bash TypeScript
npm install @opensearch-project/opensearch
```
</CodeGroup>
### Prerequisites
Before using OpenSearch with Mem0, you need to set up a collection in AWS OpenSearch Service.
@@ -26,7 +32,8 @@ You can create a collection through the AWS Console:
### Usage
```python
<CodeGroup>
```python Python
import os
from mem0 import Memory
import boto3
@@ -56,8 +63,43 @@ config = {
}
```
```typescript TypeScript
import { Memory } from 'mem0ai/oss';
// Basic self-hosted OpenSearch. For AWS OpenSearch Serverless, build an
// @opensearch-project/opensearch Client with AwsSigv4Signer and pass it as
// `client` instead of host/port/user/password.
const config = {
vectorStore: {
provider: 'opensearch',
config: {
collectionName: 'mem0',
embeddingModelDims: 1024,
host: 'localhost',
port: 9200,
user: 'admin',
password: 'admin',
useSSL: false,
verifyCerts: false,
},
},
};
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>
### Configuration Options
<Tabs>
<Tab title="Python">
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `collection_name` | string | required | Name of the OpenSearch index |
@@ -68,6 +110,23 @@ config = {
| `use_ssl` | bool | False | Enable SSL/TLS connection |
| `verify_certs` | bool | False | Verify SSL certificates |
| `auto_refresh` | bool | False | Automatically refresh index after insert. OpenSearch refreshes every ~1 second by default, so this is rarely needed. |
</Tab>
<Tab title="TypeScript">
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `collectionName` | string | required | Name of the OpenSearch index |
| `embeddingModelDims` | number | 1536 | Dimension of embedding vectors |
| `host` | string | `localhost` | OpenSearch endpoint host |
| `port` | number | 9200 | Port number |
| `httpAuth` | object | None | Authentication credentials, an object or `[user, password]` tuple |
| `user` | string | None | Username for basic auth (used together with `password`) |
| `password` | string | None | Password for basic auth (used together with `user`) |
| `useSSL` | boolean | false | Enable SSL/TLS connection |
| `verifyCerts` | boolean | false | Verify SSL certificates |
| `autoRefresh` | boolean | false | Refresh the index after each write so new memories are searchable immediately. Not supported on AWS Serverless. |
| `client` | object | None | Preconfigured OpenSearch client, e.g. one built with AwsSigv4Signer for AWS auth |
</Tab>
</Tabs>
<Note>
The defaults above match a local OpenSearch instance. The AWS OpenSearch Serverless