Documentation Index
Fetch the complete documentation index at: https://mintlify.com/georgeguimaraes/arcana/llms.txt
Use this file to discover all available pages before exploring further.
Function Signature
Purpose
Scores each chunk based on relevance to the question, filters by threshold, and re-sorts by score. UsesArcana.Reranker.LLM by default.
Improves answer quality by ensuring only the most relevant chunks are used for generation.
Parameters
The agent context from the pipeline
Options for the rerank step
Options
Custom reranker module or function (default:
Arcana.Reranker.LLM)- Module: Must implement
rerank/3callback - Function: Signature
fn question, chunks, opts -> {:ok, reranked_chunks} | {:error, reason} end
Minimum score to keep (default: 7, range 0-10)Chunks scoring below this threshold are filtered out.
Custom prompt function for LLM reranker
fn question, chunk_text -> prompt endOnly used by the default LLM reranker.Override the LLM function for this step
Context Updates
Replaced with reranked chunks. Results are flattened into a single result with collection “reranked”.
Map of chunk ID to rerank score position (higher = better)
Examples
Basic Usage
With Custom Threshold
With Multi-Hop Reasoning
Custom Reranker Module
Inline Reranker Function
Semantic Similarity Reranker
Hybrid Reranker
Result Transformation
Reranking flattens results into a single result:Deduplication
Chunks are automatically deduplicated by ID during reranking:Score Mapping
Thererank_scores map stores positional scores:
Custom Reranker Behaviour
- Be a subset of input chunks (filtered)
- Be sorted by relevance (best first)
- Maintain the same structure (
id,text,score, etc.)
Telemetry Event
Emits[:arcana, :agent, :rerank] with metadata:
When to Use
Usererank/2 when:
- Initial search returns many chunks with varying quality
- You want to improve precision before answer generation
- Combining results from multiple searches (decompose, reason)
- Your embedding model has recall > precision
Impact on Answer Quality
Without Reranking:- Answer may include less relevant information
- More noise in the context
- Longer context with lower signal
- Answer focuses on most relevant chunks
- Higher quality, more focused answers
- Reduced token usage in answer generation
Best Practices
- Use after reason/2 - Rerank the final merged results
- Tune threshold - Start with 7, adjust based on quality
- Monitor chunk counts - Ensure enough chunks pass threshold
- Consider latency - LLM reranking adds time per chunk
- Use cross-encoders - More accurate than bi-encoders for reranking
Trade-offs
Benefits:- Improved answer quality
- Better precision
- Reduced context noise
- Can filter out irrelevant chunks
- LLM-based: High latency (scores each chunk)
- Cross-encoder: Moderate latency, better accuracy
- Position in pipeline matters (do last)
Reranking Strategies
| Strategy | Speed | Accuracy | Use Case |
|---|---|---|---|
| LLM-based | Slow | High | Best quality, low volume |
| Cross-encoder | Medium | High | Production, balanced |
| Semantic similarity | Fast | Medium | High volume, speed critical |
| Keyword overlap | Fastest | Low | Simple queries, real-time |
| Hybrid | Medium | High | Best of all worlds |