{
  "schema_version": 3,
  "id": "integrate/mem0",
  "title": "Redis with Mem0",
  "url": "https://redis.io/docs/latest/integrate/mem0/",
  "summary": "Use Redis as the vector store for Mem0 agent memory.",
  "tags": [
    "docs",
    "integrate",
    "oss",
    "rs",
    "rc"
  ],
  "last_updated": "2026-11-26T13:54:22Z",
  "children": [],
  "page_type": "content",
  "content_hash": "8ff38e2da6b5d42dfa9e332ae61d892a59347587bd20ee101366be0c07bc48de",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "[Mem0](https://docs.mem0.ai/) is a memory layer for AI applications. When you give it a conversation, it uses a large language model (LLM) to extract the facts worth remembering, such as \"likes sci-fi movies and dislikes thrillers\", and stores them for a user, an agent, or a run. Later, you search those memories by meaning and add the results to a prompt.\n\nThe open source Mem0 library can use Redis as its vector store. Redis holds each memory, its embedding, and the fields that Mem0 filters on. This page covers the Python library. It doesn't cover the hosted Mem0 Platform.\n\nSee the [memory layer](https://redis.io/docs/latest/develop/use-cases/memory-layer) use case for more information\nabout when to use this pattern."
    },
    {
      "id": "requirements",
      "title": "Requirements",
      "role": "content",
      "text": "- Python 3.10 or later\n- Redis with [Redis Search](https://redis.io/docs/latest/develop/ai/search-and-query) (Redis 8 and later versions include it but earlier versions need Redis Stack).\n- An LLM and an embedding model. By default, Mem0 uses OpenAI, so set `OPENAI_API_KEY`, or configure other providers as explained in the [Mem0 documentation](https://docs.mem0.ai/).\n\nInstall Mem0 with its `vector-stores` extra:\n\n[code example]\n\nThe examples on this page were run with Mem0 2.2.1 and Redis 8.10. A small test server stood in for the LLM and embedding provider."
    },
    {
      "id": "store-memories-in-redis",
      "title": "Store memories in Redis",
      "role": "content",
      "text": "Set `vector_store.provider` to `redis`:\n\n[code example]\n\n| Setting | Default | Notes |\n|---------|---------|-------|\n| `collection_name` | `mem0` | The name of the Redis index. It is also part of each key. |\n| `embedding_model_dims` | `1536` | The vector size of your embedding model. |\n| `redis_url` | none | The Redis connection URL. It is the only connection setting, so put the username, password, and TLS in the URL, for example `rediss://<user>:<password>@<host>:6379`. |\n\n`embedding_model_dims` must match your embedding model. The default of 1536 fits OpenAI `text-embedding-3-small` and `text-embedding-ada-002`. If the sizes differ, `memory.add()` still succeeds, but Redis can't index the memory. The index reports `hash_indexing_failures` and the memory never appears in a search."
    },
    {
      "id": "add-and-search-memories",
      "title": "Add and search memories",
      "role": "content",
      "text": "Pass a conversation to `add()` with an identifier for the user. Mem0 asks the LLM for the facts to keep, embeds them, and writes them to Redis:\n\n[code example]\n\nMem0 skips a fact that it has already stored for the user. Adding the same messages twice creates one memory. A search returns the memories most similar to the query, with a `score` of 1 minus the cosine distance, so a higher score is a closer match. The `user_id`, `agent_id`, and `run_id` filters are Redis tag fields, so a search for one user never returns another user's memories.\n\nTo store text as it is, without asking the LLM to extract facts, pass `infer=False` to `add()`. Mem0 also has `get_all()`, `update()`, and `delete()`. The memories survive a restart of your application: a new `Memory` object with the same `collection_name` reads the existing ones."
    },
    {
      "id": "what-mem0-stores-in-redis",
      "title": "What Mem0 stores in Redis",
      "role": "content",
      "text": "Mem0 writes one Redis hash for each memory, with a key of the form `mem0:<collection_name>:<memory id>`. The hash has these fields:\n\n| Field | Index type | Holds |\n|-------|------------|-------|\n| `memory` | text | The memory text. |\n| `embedding` | vector | The embedding. The index is a `FLAT` index with cosine distance. |\n| `user_id`, `agent_id`, `run_id`, `memory_id`, `hash` | tag | The owner, the memory identifier, and an MD5 hash that is used to skip duplicates. |\n| `metadata` | text | The metadata that you passed to `add()`, as JSON. |\n| `created_at`, `updated_at` | numeric | Timestamps in seconds. |\n\nMem0 also creates a second, empty index named `mem0migrations` in the same database, and it re-creates the index definition each time you create a `Memory` object. The hashes themselves are not touched.\n\nMem0 doesn't keep the change history in Redis. It writes a SQLite file, `history.db` in `~/.mem0` by default, which holds the data behind `memory.history()`. Set `MEM0_DIR` or `history_db_path` to change the location. Each application instance has its own history file, so the history isn't shared between instances even when they share the Redis memories."
    },
    {
      "id": "more-information",
      "title": "More information",
      "role": "content",
      "text": "- [Mem0 Redis vector store](https://docs.mem0.ai/components/vectordbs/dbs/redis)\n- [Mem0 open source overview](https://docs.mem0.ai/)\n- [RedisVL](https://redis.io/docs/latest/develop/ai/redisvl), the Redis library that Mem0 uses to create and query the index\n- [Redis Agent Memory](https://redis.io/docs/latest/develop/ai/context-engine/agent-memory), a managed agent memory service from Redis"
    }
  ],
  "examples": [
    {
      "id": "requirements-ex0",
      "language": "bash",
      "code": "pip install 'mem0ai[vector-stores]'",
      "section_id": "requirements"
    },
    {
      "id": "store-memories-in-redis-ex0",
      "language": "python",
      "code": "import os\nfrom mem0 import Memory\n\nos.environ[\"OPENAI_API_KEY\"] = \"<your-openai-api-key>\"\n\nconfig = {\n    \"vector_store\": {\n        \"provider\": \"redis\",\n        \"config\": {\n            \"collection_name\": \"mem0\",\n            \"embedding_model_dims\": 1536,\n            \"redis_url\": \"redis://localhost:6379\",\n        },\n    },\n}\n\nmemory = Memory.from_config(config)",
      "section_id": "store-memories-in-redis"
    },
    {
      "id": "add-and-search-memories-ex0",
      "language": "python",
      "code": "messages = [\n    {\"role\": \"user\", \"content\": \"I'm planning a movie night. I'm not a fan of thrillers but I love sci-fi.\"},\n    {\"role\": \"assistant\", \"content\": \"Got it. I'll suggest sci-fi movies.\"},\n]\n\nmemory.add(messages, user_id=\"alice\", metadata={\"category\": \"movies\"})\n\nresults = memory.search(\"What movies does Alice like?\", filters={\"user_id\": \"alice\"}, limit=3)\nfor result in results[\"results\"]:\n    print(result[\"memory\"], result[\"score\"])",
      "section_id": "add-and-search-memories"
    }
  ]
}
