Elasticsearch is a distributed, RESTful search and analytics engine that can efficiently store and search vector data using dense vectors and k-NN search.

Installation

Elasticsearch support requires additional dependencies. Install them with:

pip install elasticsearch>=8.0.0

Usage

import os
from mem0 import Memory

os.environ["OPENAI_API_KEY"] = "sk-xx"

config = {
    "vector_store": {
        "provider": "elasticsearch",
        "config": {
            "collection_name": "mem0",
            "host": "localhost",
            "port": 9200,
            "embedding_model_dims": 1536
        }
    }
}

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

Config

Let’s see the available parameters for the elasticsearch config:

ParameterDescriptionDefault Value
collection_nameThe name of the index to store the vectorsmem0
embedding_model_dimsDimensions of the embedding model1536
hostThe host where the Elasticsearch server is runninglocalhost
portThe port where the Elasticsearch server is running9200
cloud_idCloud ID for Elastic Cloud deploymentNone
api_keyAPI key for authenticationNone
userUsername for basic authenticationNone
passwordPassword for basic authenticationNone
verify_certsWhether to verify SSL certificatesTrue
auto_create_indexWhether to automatically create the indexTrue

Features

  • Efficient vector search using Elasticsearch’s native k-NN search
  • Support for both local and cloud deployments (Elastic Cloud)
  • Multiple authentication methods (Basic Auth, API Key)
  • Automatic index creation with optimized mappings for vector search
  • Memory isolation through payload filtering