symbols "UserAuthentication"
Semantic Search:
search "authentication middleware logic"
RAG Evaluation
Overview
Systematic evaluation of RAG quality using retrieval and end-to-end metrics. Based on Claude Cookbooks patterns.
Evaluation Metrics
Retrieval Metrics (from .claude/evaluation/retrieval_metrics.py):
- Precision: Proportion of retrieved chunks that are actually relevant
- Formula:
Precision = True Positives / Total Retrieved
- High precision (0.8-1.0): System retrieves mostly relevant items
- Recall: Completeness of retrieval - how many relevant items were found
- Formula:
Recall = True Positives / Total Correct
- High recall (0.8-1.0): System finds most relevant items
- F1 Score: Harmonic mean of precision and recall
- Formula:
F1 = 2 × (Precision × Recall) / (Precision + Recall)
- Balanced measure when both precision and recall matter
- MRR (Mean Reciprocal Rank): Measures ranking quality
- Formula:
MRR = 1 / rank of first correct item
- High MRR (0.8-1.0): Correct items ranked first
End-to-End Metrics (from .claude/evaluation/end_to_end_eval.py):
- Accuracy (LLM-as-Judge): Overall correctness using Claude evaluation
- Compares generated answer to correct answer
- Focuses on substance and meaning, not exact wording
- Checks for completeness and absence of contradictions
Evaluation Process
Create Evaluation Dataset:
{
"query": "How is user authentication implemented?",
"correct_chunks": ["src/auth/middleware.ts", "src/auth/types.ts"],
"correct_answer": "User authentication uses JWT tokens...",
"category": "authentication"
}
Run Retrieval Evaluation:
# Using Promptfoo
npx promptfoo@latest eval -c .claude/evaluation/promptfoo_configs/rag_config.yaml
# Or using Python directly
from .claude.evaluation.retrieval_metrics import evaluate_retrieval
metrics = evaluate_retrieval(retrieved_chunks, correct_chunks)
print(f"Precision: {metrics['precision']}, Recall: {metrics['recall']}, F1: {metrics['f1']}, MRR: {metrics['mrr']}")
Run End-to-End Evaluation:
# Using Promptfoo
npx promptfoo@latest eval -c .claude/evaluation/promptfoo_configs/rag_config.yaml
# Or using Python directly
from .claude.evaluation.end_to_end_eval import evaluate_end_to_end
result = evaluate_end_to_end(query, generated_answer, correct_answer)
print(f"Correct: {result['is_correct']}, Explanation: {result['explanation']}")
Expected Performance
Based on Claude Cookbooks results:
- Basic RAG: Precision 0.43, Recall 0.66, F1 0.52, MRR 0.74, Accuracy 71%
- With Re-ranking: Precision 0.44, Recall 0.69, F1 0.54, MRR 0.87, Accuracy 81%
Best Practices
- Separate Evaluation: Evaluate retrieval and end-to-end separately
- Create Comprehensive Datasets: Cover common and edge cases
- Evaluate Regularly: Run evaluations after codebase changes
- Track Metrics Over Time: Monitor improvements
- Use Both Metrics: Precision/Recall for retrieval, Accuracy for end-to-end
References
1---2name: repo-rag-33description: Perform high-recall codebase retrieval using semantic search and symbol indexing. Use when you need to find specific code, understand project structure, or verify architectural patterns before editing.4---56<identity>7Repo RAG (Retrieval Augmented Generation) - Provides advanced codebase search capabilities beyond simple grep.8</identity>910<capabilities>11- High-recall codebase retrieval using semantic search12- Symbol indexing for finding classes, functions, and types13- Understanding project structure14- Verifying architectural patterns before editing15</capabilities>1617<instructions>18<execution_process>191. **Symbol Search First**: Use `symbols` to find classes, functions, and types. This is more accurate than text search for code structures.202. **Semantic Search**: Use `search` for concepts, comments, or broader patterns.213. **Verification**: Always verify the file path and context returned before proposing edits.22</execution_process>2324<usage_patterns>25- **Architecture Review**: Run symbol searches on key interfaces to understand the dependency graph.26- **Plan Mode**: Use this skill to populate the "Context" section of a Plan Mode artifact.27- **Refactoring**: Identify all usages of a symbol before renaming or modifying it.28</usage_patterns>29</instructions>3031<examples>32<code_example>33**Symbol Search**:3435```36symbols "UserAuthentication"37```3839**Semantic Search**:4041```42search "authentication middleware logic"43```44</code_example>45</examples>4647## RAG Evaluation4849### Overview5051Systematic evaluation of RAG quality using retrieval and end-to-end metrics. Based on Claude Cookbooks patterns.5253### Evaluation Metrics5455**Retrieval Metrics** (from `.claude/evaluation/retrieval_metrics.py`):56- **Precision**: Proportion of retrieved chunks that are actually relevant57 - Formula: `Precision = True Positives / Total Retrieved`58 - High precision (0.8-1.0): System retrieves mostly relevant items59- **Recall**: Completeness of retrieval - how many relevant items were found60 - Formula: `Recall = True Positives / Total Correct`61 - High recall (0.8-1.0): System finds most relevant items62- **F1 Score**: Harmonic mean of precision and recall63 - Formula: `F1 = 2 × (Precision × Recall) / (Precision + Recall)`64 - Balanced measure when both precision and recall matter65- **MRR (Mean Reciprocal Rank)**: Measures ranking quality66 - Formula: `MRR = 1 / rank of first correct item`67 - High MRR (0.8-1.0): Correct items ranked first6869**End-to-End Metrics** (from `.claude/evaluation/end_to_end_eval.py`):70- **Accuracy (LLM-as-Judge)**: Overall correctness using Claude evaluation71 - Compares generated answer to correct answer72 - Focuses on substance and meaning, not exact wording73 - Checks for completeness and absence of contradictions7475### Evaluation Process76771. **Create Evaluation Dataset**:78 ```json79 {80 "query": "How is user authentication implemented?",81 "correct_chunks": ["src/auth/middleware.ts", "src/auth/types.ts"],82 "correct_answer": "User authentication uses JWT tokens...",83 "category": "authentication"84 }85 ```86872. **Run Retrieval Evaluation**:88 ```bash89 # Using Promptfoo90 npx promptfoo@latest eval -c .claude/evaluation/promptfoo_configs/rag_config.yaml91 92 # Or using Python directly93 from .claude.evaluation.retrieval_metrics import evaluate_retrieval94 metrics = evaluate_retrieval(retrieved_chunks, correct_chunks)95 print(f"Precision: {metrics['precision']}, Recall: {metrics['recall']}, F1: {metrics['f1']}, MRR: {metrics['mrr']}")96 ```97983. **Run End-to-End Evaluation**:99 ```bash100 # Using Promptfoo101 npx promptfoo@latest eval -c .claude/evaluation/promptfoo_configs/rag_config.yaml102 103 # Or using Python directly104 from .claude.evaluation.end_to_end_eval import evaluate_end_to_end105 result = evaluate_end_to_end(query, generated_answer, correct_answer)106 print(f"Correct: {result['is_correct']}, Explanation: {result['explanation']}")107 ```108109### Expected Performance110111Based on Claude Cookbooks results:112- **Basic RAG**: Precision 0.43, Recall 0.66, F1 0.52, MRR 0.74, Accuracy 71%113- **With Re-ranking**: Precision 0.44, Recall 0.69, F1 0.54, MRR 0.87, Accuracy 81%114115### Best Practices1161171. **Separate Evaluation**: Evaluate retrieval and end-to-end separately1182. **Create Comprehensive Datasets**: Cover common and edge cases1193. **Evaluate Regularly**: Run evaluations after codebase changes1204. **Track Metrics Over Time**: Monitor improvements1215. **Use Both Metrics**: Precision/Recall for retrieval, Accuracy for end-to-end122123### References124125- [RAG Patterns Guide](../docs/RAG_PATTERNS.md) - Implementation patterns126- [Retrieval Metrics](../evaluation/retrieval_metrics.py) - Metric calculations127- [End-to-End Evaluation](../evaluation/end_to_end_eval.py) - LLM-as-judge128- [Evaluation Guide](../docs/EVALUATION_GUIDE.md) - Comprehensive evaluation guide