The opensearch backend uses OpenSearch as the vector store. Memory text is embedded by an embedding model, written to OpenSearch with a per-user index (the actual index name is {index}_{user_id}), and retrieved by similarity. It is the default backend for LongTermMemory.
When to use
- You already run an OpenSearch cluster and want self-hosted vector search;
- You need persistence, sharing across processes and instances, and full control over indexing and retrieval.
Dependencies
Usage
Before running, provide a reachable OpenSearch cluster, an account allowed to create and access indexes, a valid CA certificate, and the connection and embedding variables below. Dimensions must match an existing index; use a new index and reinsert memories when changing dimensions
You can also pass connection and embedding config explicitly via backend_config:
Parameters
LongTermMemory parameters
Constructor parameters
backend_config supports the following settings:
OpenSearch connection config
opensearch_config is an OpensearchConfig with env prefix DATABASE_OPENSEARCH_:
Embedding config
embedding_config is an EmbeddingModelConfig with env prefix MODEL_EMBEDDING_:
Environment variables
index must follow OpenSearch naming rules: all lowercase, only a-z0-9_-., and not starting with _ or -; otherwise initialization fails. In production, set cert_path to enable certificate verification and avoid security risks.
Verify writes and retrieval
After configuring the dependencies and credentials on this page, run this standalone example. It saves user text and searches for that user directly without calling a conversation model
Results should contain the saved language preference. Managed services may extract memories asynchronously, so a completed write does not guarantee immediate retrieval. An empty result can also indicate permission, network, or service failure; check error logs and service records. The save method does not return a success Boolean
The final index includes user_id, so user IDs must also meet the index character rules. The same index and user_id access the same memory; search_memory(app_name=...) does not add another index boundary