Zero Entropy - Mem0
Zero Entropy
Zero Entropy 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
pip install zeroentropy
Configuration
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 (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.
pnpm add zeroentropy
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:
export ZERO_ENTROPY_API_KEY="your-api-key"
Usage Example
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
- Model Selection: Use
zerank-1for best quality,zerank-1-smallfor faster processing - Batch Size: Process multiple queries together when possible
- Top-k Limiting: Set reasonable
top_kvalues (5-20) for best performance - API Key Management: Use environment variables for secure key storage