---
title: Zero Entropy
description: "Configure Zero Entropy neural reranking models in Mem0 with zerank-1 and zerank-1-small support."
---

[Zero Entropy](https://www.zeroentropy.dev) provides neural reranking models that significantly improve search relevance with fast performance.

## Models

Zero Entropy offers two reranking models:

- **`zerank-1`**: Flagship state-of-the-art reranker (non-commercial license)
- **`zerank-1-small`**: Open-source model (Apache 2.0 license)

## Installation

```bash
pip install zeroentropy
```

## Configuration

```python Python
from mem0 import Memory

config = {
    "vector_store": {
        "provider": "chroma",
        "config": {
            "collection_name": "my_memories",
            "path": "./chroma_db"
        }
    },
    "llm": {
        "provider": "openai",
        "config": {
            "model": "gpt-4o-mini"
        }
    },
    "rerank": {
        "provider": "zero_entropy",
        "config": {
            "model": "zerank-1",  # or "zerank-1-small"
            "api_key": "your-zero-entropy-api-key",  # or set ZERO_ENTROPY_API_KEY
            "top_k": 5
        }
    }
}

memory = Memory.from_config(config)
```

## TypeScript (self-hosted)

The [TypeScript OSS SDK](/open-source/features/reranker-search#typescript-sdk) (`mem0ai/oss`) ships the Zero Entropy reranker under the same provider name as Python, `zero_entropy`. It reads the key from config or `ZERO_ENTROPY_API_KEY` and defaults to the `zerank-1` model.

```bash
pnpm add zeroentropy
```

```typescript
import { Memory } from "mem0ai/oss";

const memory = new Memory({
  reranker: {
    provider: "zero_entropy",
    config: {
      apiKey: process.env.ZERO_ENTROPY_API_KEY,
      // model: "zerank-1",   // default (or "zerank-1-small")
      topK: 5,
    },
  },
});

const results = await memory.search("What Italian food does the user like?", {
  filters: { userId: "alice" },
  rerank: true,
});
```

## Environment Variables

Set your API key as an environment variable:

```bash
export ZERO_ENTROPY_API_KEY="your-api-key"
```

## Usage Example

```python Python
import os
from mem0 import Memory

# Set API key
os.environ["ZERO_ENTROPY_API_KEY"] = "your-api-key"

# Initialize memory with Zero Entropy reranker
config = {
    "vector_store": {"provider": "chroma"},
    "llm": {"provider": "openai", "config": {"model": "gpt-4o-mini"}},
    "rerank": {"provider": "zero_entropy", "config": {"model": "zerank-1"}}
}

memory = Memory.from_config(config)

# Add memories
messages = [
    {"role": "user", "content": "I love Italian pasta, especially carbonara"},
    {"role": "user", "content": "Japanese sushi is also amazing"},
    {"role": "user", "content": "I enjoy cooking Mediterranean dishes"}
]

memory.add(messages, user_id="alice")

# Search with reranking
results = memory.search("What Italian food does the user like?", filters={"user_id": "alice"})

for result in results['results']:
    print(f"Memory: {result['memory']}")
    print(f"Vector Score: {result['score']:.3f}")
    print(f"Rerank Score: {result['rerank_score']:.3f}")
    print()
```

## Configuration Parameters

| Parameter | Description | Type | Default |
|-----------|-------------|------|---------|
| `model` | Model to use: `"zerank-1"` or `"zerank-1-small"` | `str` | `"zerank-1"` |
| `api_key` | Zero Entropy API key | `str` | `None` |
| `top_k` | Maximum documents to return after reranking | `int` | `None` |

## Performance

- **Fast**: Optimized neural architecture for low latency
- **Accurate**: State-of-the-art relevance scoring
- **Cost-effective**: ~$0.025/1M tokens processed

## Best Practices

1. **Model Selection**: Use `zerank-1` for best quality, `zerank-1-small` for faster processing
2. **Batch Size**: Process multiple queries together when possible
3. **Top-k Limiting**: Set reasonable `top_k` values (5-20) for best performance
4. **API Key Management**: Use environment variables for secure key storage