docs/components/vectordbs/dbs/opensearch.mdx
OpenSearch is an enterprise-grade search and observability suite that brings order to unstructured data at scale. OpenSearch supports k-NN (k-Nearest Neighbors) and allows you to store and retrieve high-dimensional vector embeddings efficiently.
OpenSearch support requires an additional client library. Install the one for your SDK:
<CodeGroup> ```bash Python pip install opensearch-py ```npm install @opensearch-project/opensearch
Before using OpenSearch with Mem0, you need to set up a collection in AWS OpenSearch Service.
You can create a collection through the AWS Console:
region = 'us-west-2' service = 'aoss' credentials = boto3.Session().get_credentials() auth = AWSV4SignerAuth(credentials, region, service)
config = { "vector_store": { "provider": "opensearch", "config": { "collection_name": "mem0", "host": "your-domain.us-west-2.aoss.amazonaws.com", "port": 443, "http_auth": auth, "embedding_model_dims": 1024, "connection_class": RequestsHttpConnection, "pool_maxsize": 20, "use_ssl": True, "verify_certs": True } } }
```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" } });
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 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."}
]
m.add(messages, user_id="alice", metadata={"category": "movies"})
results = m.search("What kind of movies does Alice like?", filters={"user_id": "alice"})