> ## Documentation Index
> Fetch the complete documentation index at: https://new.docs.falkordb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Mem0

> Add FalkorDB as a graph memory backend for Mem0 AI agents with per-user graph isolation, hybrid search, and seamless integration.

[Mem0](https://github.com/mem0ai/mem0) is a memory management framework for AI agents that enables persistent, contextual memory across interactions. The [mem0-falkordb](https://github.com/FalkorDB/mem0-falkordb) plugin adds FalkorDB as a graph store backend for Mem0 without modifying any Mem0 source code.

## Overview

The mem0-falkordb plugin provides:

* **Graph-structured memory**: Store relationships between entities, not just flat facts
* **Per-user graph isolation**: Each user gets their own isolated FalkorDB graph
* **Context-aware retrieval**: Semantic search with vector embeddings
* **Memory evolution**: Support for updates and conflict resolution
* **Runtime patching**: No modifications to Mem0 source code required

## Why Mem0 + FalkorDB?

### FalkorDB's Added Value

* **Native multi-graph support**: Isolated memory spaces for different users or agents
* **Natural data isolation**: No user\_id filtering needed in Cypher queries
* **Simpler, faster queries**: No WHERE clauses on user\_id
* **Easy cleanup**: `delete_all` simply drops the user's graph
* **High performance**: Fast graph operations and efficient memory usage
* **Cloud and on-premises ready**: Works with FalkorDB Cloud or your own deployment

### Use Cases

* **Multi-agent systems**: Persistent memory for each agent with graph-based relationships
* **Conversational AI**: Track facts, entities, and relationships across conversations
* **Personalized assistants**: Build context-aware AI that remembers user preferences and history
* **Customer support**: Provide context-rich responses based on customer interaction history
* **Knowledge management**: Aggregate and navigate complex information networks

## Getting Started

### Prerequisites

* Python 3.10 or higher
* FalkorDB instance (Cloud or self-hosted)
* OpenAI API key (or other supported LLM provider)

### Installation

Install both Mem0 and the FalkorDB plugin:

```bash theme={null}
pip install mem0ai
pip install mem0-falkordb
```

### Quick Start Example

Here's a complete example to get you started:

```python theme={null}
from mem0_falkordb import register
register()

from mem0 import Memory

config = {
    "graph_store": {
        "provider": "falkordb",
        "config": {
            "host": "localhost",
            "port": 6379,
            "database": "mem0",
        },
    },
    "llm": {
        "provider": "openai",
        "config": {"model": "gpt-4o-mini"},
    },
}

m = Memory.from_config(config)

# Add memories for a user
m.add("I love pizza", user_id="alice")
m.add("Alice is a software engineer", user_id="alice")
m.add("Alice works on AI projects", user_id="alice")

# Search the memory
results = m.search("what does alice like?", user_id="alice")
print(results)
```

### Understanding the Code

1. **Register the plugin**: Call `register()` to patch FalkorDB into Mem0's factory system
2. **Configure Mem0**: Set FalkorDB as the graph store provider with connection details
3. **Add memories**: Store information with user\_id for automatic graph isolation
4. **Search**: Query memories using natural language

## Running FalkorDB

### Using Docker

```bash theme={null}
docker run --rm -p 6379:6379 falkordb/falkordb:latest
```

### Using FalkorDB Cloud

Sign up for a free account at [app.falkordb.cloud](https://app.falkordb.cloud) and use the connection details in your config:

```python theme={null}
config = {
    "graph_store": {
        "provider": "falkordb",
        "config": {
            "host": "your-instance.falkordb.cloud",
            "port": 6379,
            "username": "default",
            "password": "your-password",
            "database": "mem0",
        },
    },
    # ... rest of config
}
```

## Configuration Options

### Graph Store Configuration

```python theme={null}
config = {
    "graph_store": {
        "provider": "falkordb",
        "config": {
            "host": "localhost",       # FalkorDB server host
            "port": 6379,              # FalkorDB server port
            "database": "mem0",        # Graph name prefix
            "username": None,          # Authentication username (optional)
            "password": None,          # Authentication password (optional)
            "base_label": True,        # Use __Entity__ base label
        },
    },
}
```

| Parameter    | Type | Default     | Description                                               |
| ------------ | ---- | ----------- | --------------------------------------------------------- |
| `host`       | str  | `localhost` | FalkorDB server host                                      |
| `port`       | int  | `6379`      | FalkorDB server port                                      |
| `database`   | str  | `mem0`      | Graph name prefix (each user gets `{database}_{user_id}`) |
| `username`   | str  | `None`      | Authentication username (optional)                        |
| `password`   | str  | `None`      | Authentication password (optional)                        |
| `base_label` | bool | `True`      | Use `__Entity__` base label                               |

### Per-User Graph Isolation

Each user automatically gets their own isolated FalkorDB graph (e.g., `mem0_alice`, `mem0_bob`). This provides:

* **Natural data isolation**: No user\_id filtering needed in Cypher queries
* **Simpler, faster queries**: No WHERE clauses on user\_id
* **Easy cleanup**: `delete_all` simply drops the user's graph
* **Scalability**: Leverage FalkorDB's native multi-graph support

## Advanced Features

### Working with Multiple Users

```python theme={null}
# Add memories for different users
m.add("Alice loves pizza", user_id="alice")
m.add("Bob prefers pasta", user_id="bob")

# Each user gets their own isolated graph
alice_results = m.search("what food?", user_id="alice")
bob_results = m.search("what food?", user_id="bob")

# Results are isolated per user
print(alice_results)  # Returns info about pizza
print(bob_results)    # Returns info about pasta
```

### Getting All Memories

```python theme={null}
# Get all memories for a user
all_memories = m.get_all(user_id="alice")
for memory in all_memories:
    print(memory)
```

### Updating Memories

```python theme={null}
# Mem0 automatically handles memory updates and conflict resolution
m.add("Alice now prefers sushi", user_id="alice")
results = m.search("what food does alice like?", user_id="alice")
# Results will reflect the updated preference
```

### Deleting Memories

```python theme={null}
# Delete specific memories
m.delete(memory_id="specific-id", user_id="alice")

# Delete all memories for a user (drops the user's graph)
m.delete_all(user_id="alice")
```

### Memory History

```python theme={null}
# Get memory history for a specific memory
history = m.history(memory_id="specific-id")
for entry in history:
    print(f"Version: {entry['version']}, Changed: {entry['changed_at']}")
```

## Demo

The mem0-falkordb repository includes a comprehensive demo showcasing:

* Graph-structured memory with relationships
* Per-user graph isolation
* Context-aware retrieval
* Memory evolution and updates
* Visual graph inspection

```bash theme={null}
# Clone the repository
git clone https://github.com/FalkorDB/mem0-falkordb.git
cd mem0-falkordb

# Start FalkorDB
docker run --rm -p 6379:6379 falkordb/falkordb:latest

# Run the demo
cd demo
uv sync
export OPENAI_API_KEY='your-key-here'
uv run python demo.py
```

See the [demo README](https://github.com/FalkorDB/mem0-falkordb/blob/main/demo/README.md) for complete instructions.

## Best Practices

1. **Call register() once**: Always call `register()` before creating a Mem0 `Memory` instance
2. **Use user\_id consistently**: Always provide user\_id for proper graph isolation
3. **Configure LLM**: Ensure your LLM provider is properly configured for entity extraction
4. **Monitor graph size**: Use `GRAPH.MEMORY USAGE` command to track memory usage
5. **Clean up**: Use `delete_all()` to remove user graphs when no longer needed
6. **Connection pooling**: Reuse Memory instances when possible

## Troubleshooting

### Installation Issues

If you have trouble installing:

* Ensure you have Python 3.10 or higher
* Install Mem0 and mem0-falkordb separately
* Try installing in a fresh virtual environment

### Connection Issues

If you can't connect to FalkorDB:

* Verify FalkorDB is running: `redis-cli -h localhost -p 6379 ping`
* Check your connection details (host, port, credentials)
* Ensure FalkorDB is accessible on the specified host and port

### Memory Not Being Stored

* Make sure to call `register()` before creating the Memory instance
* Verify your LLM API key is set correctly
* Check that the user\_id is provided when adding memories
* Ensure FalkorDB has enough memory available

### Search Returns No Results

* Verify memories were added successfully with `get_all()`
* Check that you're using the correct user\_id
* Ensure your embeddings configuration is correct
* Try more specific or different search queries

## Resources

* 📦 [PyPI Package](https://pypi.org/project/mem0-falkordb/)
* 💻 [GitHub Repository](https://github.com/FalkorDB/mem0-falkordb)
* 📚 [Mem0 Documentation](https://github.com/mem0ai/mem0)
* 🎥 [Demo Application](https://github.com/FalkorDB/mem0-falkordb/tree/main/demo)
* 🔗 [FalkorDB Cloud](https://app.falkordb.cloud)

## Next Steps

* Explore [Graphiti](/agentic-memory/graphiti) for temporal knowledge graph capabilities
* Learn about [Cognee](/agentic-memory/cognee) for alternative memory management approaches
* Review [GenAI Tools](/genai-tools) for graph reasoning and LLM integrations

## Frequently Asked Questions

<AccordionGroup>
  <Accordion title="How does mem0-falkordb differ from the default Mem0 graph store?">
    The mem0-falkordb plugin provides **per-user graph isolation** using FalkorDB's native multi-graph support. Each user gets their own separate graph (e.g., `mem0_alice`, `mem0_bob`), eliminating the need for user\_id filtering in queries and enabling simpler, faster operations.
  </Accordion>

  <Accordion title="Do I need to modify Mem0 source code to use FalkorDB?">
    No. The mem0-falkordb plugin uses **runtime patching** to register FalkorDB as a graph store provider. Simply call `register()` before creating a Mem0 Memory instance and configure `provider: 'falkordb'` in your config.
  </Accordion>

  <Accordion title="What happens when I call delete_all for a user?">
    When you call `delete_all(user_id='alice')`, it simply **drops the entire user graph** (e.g., `mem0_alice`). This is much faster and cleaner than deleting individual records because each user has their own isolated graph.
  </Accordion>

  <Accordion title="Can I use FalkorDB Cloud with Mem0?">
    Yes. Update your config with your FalkorDB Cloud connection details including `host`, `port`, `username`, and `password`. Sign up at [app.falkordb.cloud](https://app.falkordb.cloud) for a free account.
  </Accordion>

  <Accordion title="Why am I getting no results from memory search?">
    Common causes include: not calling `register()` before creating the Memory instance, incorrect or missing `user_id` parameter, invalid LLM API key for entity extraction, or misconfigured embeddings. Verify memories exist with `get_all(user_id='...')`.
  </Accordion>
</AccordionGroup>
