Supported LLM Providers
Any LLM provider supported by Mem0 can be used for reranking:- OpenAI: GPT-4, GPT-3.5-turbo, etc.
- Anthropic: Claude models
- Together: Open-source models
- Groq: Fast inference
- Ollama: Local models
- And more…
Configuration
Python
Custom Scoring Prompt
You can provide a custom prompt for relevance scoring:Python
Usage Example
Python
Output
Domain-Specific Scoring
Create specialized scoring for your domain:Python
Multiple LLM Providers
Use different LLM providers for reranking:Python
Configuration Parameters
| Parameter | Description | Type | Default |
|---|---|---|---|
model | LLM model to use for scoring | str | "gpt-4o-mini" |
provider | LLM provider name | str | "openai" |
api_key | API key for the LLM provider | str | None |
top_k | Maximum documents to return | int | None |
temperature | Temperature for LLM generation | float | 0.0 |
max_tokens | Maximum tokens for LLM response | int | 100 |
scoring_prompt | Custom prompt template | str | Default prompt |
Advantages
- Maximum Flexibility: Custom prompts for any use case
- Domain Expertise: Leverage LLM knowledge for specialized domains
- Interpretability: Understand scoring through prompt engineering
- Multi-criteria: Score based on multiple relevance factors
Considerations
- Latency: Higher latency than specialized rerankers
- Cost: LLM API costs per reranking operation
- Consistency: May have slight variations in scoring
- Prompt Engineering: Requires careful prompt design
Best Practices
- Temperature: Use 0.0 for consistent scoring
- Prompt Design: Be specific about scoring criteria
- Token Efficiency: Keep prompts concise to reduce costs
- Caching: Cache results for repeated queries when possible
- Fallback: Handle API errors gracefully