Repository navigation
How can I evaluate a LlamaIndex retriever without calling an LLM? #23442
|
I’m exploring how to test retrieval separately from answer generation in LlamaIndex. I want a small test dataset where each question has known relevant document IDs, then compare those IDs with the retriever’s results—without calling a generation model. For example: relevant_ids = {"cancel-plan", "refund-policy"}
retrieved_ids = ["billing", "cancel-plan", "upgrade-plan"]My main questions are:
Small examples or documentation pointers would be appreciated. |
Replies: 1 comment
|
Yes, you can evaluate retrieval against manually labeled relevant IDs without calling a generation LLM. 1. Which metrics?
For your example:
2. Node IDs or document IDs?Choose the granularity that matches your labels:
Take the original top k results first. For document-level recall, count each relevant document only once. Duplicate chunks can still occupy retrieval slots; deduplicating before selecting the top k measures a different retrieval policy. 3. LlamaIndex’s built-in evaluator
from llama_index.core.evaluation import RetrieverEvaluator
# Assumes you already have an index.
retriever = index.as_retriever(similarity_top_k=3)
evaluator = RetrieverEvaluator.from_metric_names(
["hit_rate", "mrr"],
retriever=retriever,
)
# Run in a notebook with top-level await, or inside an async function.
result = await evaluator.aevaluate(
query="How do I cancel my plan?",
expected_ids=["cancel-plan", "refund-policy"],
)
print(result.metric_vals_dict)Replace those example IDs with the actual node IDs in your index. The built-in evaluator compares node IDs; it does not automatically group results by source document. Also, k comes from the retriever configuration, not from These metrics need no generation LLM. Retrieval may still make embedding API calls, or LLM calls if you configure query rewriting or another LLM-based retrieval step. |
Yes, you can evaluate retrieval against manually labeled relevant IDs without calling a generation LLM.
1. Which metrics?
For your example:
2. Node IDs or document IDs?
Choose the granularity that matches your labels: