docs(rerankers): align reranker config docs with v3 SDK source
This commit is contained in:
@@ -13,10 +13,10 @@ The number of candidates sent to the reranker significantly impacts performance:
|
||||
```python
|
||||
# Optimal candidate sizes for different rerankers
|
||||
config_map = {
|
||||
"cohere": {"initial_candidates": 100, "top_n": 10},
|
||||
"sentence_transformer": {"initial_candidates": 50, "top_n": 10},
|
||||
"huggingface": {"initial_candidates": 30, "top_n": 5},
|
||||
"llm_reranker": {"initial_candidates": 20, "top_n": 5}
|
||||
"cohere": {"initial_candidates": 100, "top_k": 10},
|
||||
"sentence_transformer": {"initial_candidates": 50, "top_k": 10},
|
||||
"huggingface": {"initial_candidates": 30, "top_k": 5},
|
||||
"llm_reranker": {"initial_candidates": 20, "top_k": 5}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -31,7 +31,7 @@ config = {
|
||||
"config": {
|
||||
"model": "cross-encoder/ms-marco-MiniLM-L-6-v2",
|
||||
"batch_size": 16, # Process multiple candidates at once
|
||||
"top_n": 10
|
||||
"top_k": 10
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ config = {
|
||||
"provider": "cohere",
|
||||
"config": {
|
||||
"model": "rerank-english-v3.0",
|
||||
"top_n": 10,
|
||||
"top_k": 10,
|
||||
"max_chunks_per_doc": 10, # Limit chunk processing
|
||||
"return_documents": False # Reduce response size
|
||||
}
|
||||
@@ -73,7 +73,7 @@ config = {
|
||||
"model": "cross-encoder/ms-marco-MiniLM-L-6-v2",
|
||||
"device": "cuda", # Use GPU when available
|
||||
"batch_size": 32,
|
||||
"top_n": 10,
|
||||
"top_k": 10,
|
||||
"max_length": 512 # Limit input length
|
||||
}
|
||||
}
|
||||
@@ -107,10 +107,9 @@ config = {
|
||||
"provider": "huggingface",
|
||||
"config": {
|
||||
"model": "BAAI/bge-reranker-base",
|
||||
"use_fp16": True, # Half precision for speed
|
||||
"max_length": 512,
|
||||
"batch_size": 8,
|
||||
"top_n": 10
|
||||
"top_k": 10
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,17 +123,11 @@ config = {
|
||||
"reranker": {
|
||||
"provider": "llm_reranker",
|
||||
"config": {
|
||||
"llm": {
|
||||
"provider": "openai",
|
||||
"config": {
|
||||
"model": "gpt-3.5-turbo", # Faster than gpt-4
|
||||
"temperature": 0, # Deterministic results
|
||||
"max_tokens": 500 # Limit response length
|
||||
}
|
||||
},
|
||||
"batch_ranking": True, # Rank multiple at once
|
||||
"top_n": 5, # Fewer results for faster processing
|
||||
"timeout": 10 # Request timeout
|
||||
"provider": "openai",
|
||||
"model": "gpt-4o-mini", # Faster than gpt-4o
|
||||
"temperature": 0.0, # Deterministic results
|
||||
"max_tokens": 100, # Limit response length
|
||||
"top_k": 5 # Fewer results for faster processing
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -201,12 +194,12 @@ class CachedReranker:
|
||||
### Model Caching
|
||||
```python
|
||||
# Pre-load models to avoid initialization overhead
|
||||
# Set SENTENCE_TRANSFORMERS_HOME env var to control cache location
|
||||
config = {
|
||||
"reranker": {
|
||||
"provider": "sentence_transformer",
|
||||
"config": {
|
||||
"model": "cross-encoder/ms-marco-MiniLM-L-6-v2",
|
||||
"cache_folder": "/path/to/model/cache",
|
||||
"device": "cuda"
|
||||
}
|
||||
}
|
||||
@@ -218,14 +211,14 @@ config = {
|
||||
### Async Configuration
|
||||
```python
|
||||
import asyncio
|
||||
from mem0 import Memory
|
||||
from mem0 import AsyncMemory
|
||||
|
||||
async def parallel_search(config, queries, user_id):
|
||||
memory = Memory.from_config(config)
|
||||
memory = AsyncMemory.from_config(config)
|
||||
|
||||
# Process multiple queries concurrently
|
||||
tasks = [
|
||||
memory.search_async(query, user_id=user_id)
|
||||
memory.search(query, filters={"user_id": user_id})
|
||||
for query in queries
|
||||
]
|
||||
|
||||
@@ -249,8 +242,7 @@ config = {
|
||||
"config": {
|
||||
"device": "cuda",
|
||||
"model": "cross-encoder/ms-marco-electra-base",
|
||||
"batch_size": 64, # Larger batch for GPU
|
||||
"fp16": True # Half precision
|
||||
"batch_size": 64 # Larger batch for GPU
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -268,8 +260,7 @@ config = {
|
||||
"provider": "sentence_transformer",
|
||||
"config": {
|
||||
"device": "cpu",
|
||||
"model": "cross-encoder/ms-marco-MiniLM-L-6-v2",
|
||||
"num_workers": 4 # Parallel processing
|
||||
"model": "cross-encoder/ms-marco-MiniLM-L-6-v2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user