References (archive): SCAFFOLD_SKILLS_ARCHIVE_MAP.md — semantic search / vector patterns from everything-claude-code backend-patterns, tdd-workflow.
- Architecture Review: Run symbol searches on key interfaces to understand the dependency graph.
- Plan Mode: Use this skill to populate the "Context" section of a Plan Mode artifact.
- Refactoring: Identify all usages of a symbol before renaming or modifying it.
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/tools/repo-rag/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/tools/repo-rag/evaluation.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 Python directly
from .claude.tools.repo_rag.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 Python directly
from .claude.tools.repo_rag.evaluation 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
Memory Protocol (MANDATORY)
Before starting:
Read .claude/context/memory/learnings.md
After completing:
- New pattern ->
.claude/context/memory/learnings.md
- Issue found ->
.claude/context/memory/issues.md
- Decision made ->
.claude/context/memory/decisions.md
ASSUME INTERRUPTION: If it's not in memory, it didn't happen.
1---2name: repo-rag3description: 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---5
6**References (archive):** [SCAFFOLD_SKILLS_ARCHIVE_MAP.md](../../docs/SCAFFOLD_SKILLS_ARCHIVE_MAP.md) — semantic search / vector patterns from everything-claude-code backend-patterns, tdd-workflow.
7
8<identity>
9Repo RAG (Retrieval Augmented Generation) - Provides advanced codebase search capabilities beyond simple grep.
10</identity>
11
12<capabilities>
13- High-recall codebase retrieval using semantic search
14- Symbol indexing for finding classes, functions, and types
15- Understanding project structure
16- Verifying architectural patterns before editing
17</capabilities>
18
19<instructions>
20<execution_process>
211. **Symbol Search First**: Use `symbols` to find classes, functions, and types. This is more accurate than text search for code structures.
222. **Semantic Search**: Use `search` for concepts, comments, or broader patterns.
233. **Verification**: Always verify the file path and context returned before proposing edits.
24</execution_process>
25
26<usage_patterns>
27
28- **Architecture Review**: Run symbol searches on key interfaces to understand the dependency graph.
29- **Plan Mode**: Use this skill to populate the "Context" section of a Plan Mode artifact.
30- **Refactoring**: Identify all usages of a symbol before renaming or modifying it.
31 </usage_patterns>
32 </instructions>
33
34<examples>
35<code_example>
36**Symbol Search**:
37
38```
39symbols "UserAuthentication"
40```
41
42**Semantic Search**:
43
44```
45search "authentication middleware logic"
46```
47
48</code_example>
49</examples>
50
51## RAG Evaluation
52
53### Overview
54
55Systematic evaluation of RAG quality using retrieval and end-to-end metrics. Based on Claude Cookbooks patterns.
56
57### Evaluation Metrics
58
59**Retrieval Metrics** (from `.claude/tools/repo-rag/metrics.py`):
60
61- **Precision**: Proportion of retrieved chunks that are actually relevant
62 - Formula: `Precision = True Positives / Total Retrieved`
63 - High precision (0.8-1.0): System retrieves mostly relevant items
64- **Recall**: Completeness of retrieval - how many relevant items were found
65 - Formula: `Recall = True Positives / Total Correct`
66 - High recall (0.8-1.0): System finds most relevant items
67- **F1 Score**: Harmonic mean of precision and recall
68 - Formula: `F1 = 2 × (Precision × Recall) / (Precision + Recall)`
69 - Balanced measure when both precision and recall matter
70- **MRR (Mean Reciprocal Rank)**: Measures ranking quality
71 - Formula: `MRR = 1 / rank of first correct item`
72 - High MRR (0.8-1.0): Correct items ranked first
73
74**End-to-End Metrics** (from `.claude/tools/repo-rag/evaluation.py`):
75
76- **Accuracy (LLM-as-Judge)**: Overall correctness using Claude evaluation
77 - Compares generated answer to correct answer
78 - Focuses on substance and meaning, not exact wording
79 - Checks for completeness and absence of contradictions
80
81### Evaluation Process
82
831. **Create Evaluation Dataset**:
84
85 ```json
86 {
87 "query": "How is user authentication implemented?",
88 "correct_chunks": ["src/auth/middleware.ts", "src/auth/types.ts"],
89 "correct_answer": "User authentication uses JWT tokens...",
90 "category": "authentication"
91 }
92 ```
93
942. **Run Retrieval Evaluation**:
95
96 ```bash
97 # Using Python directly
98 from .claude.tools.repo_rag.metrics import evaluate_retrieval
99 metrics = evaluate_retrieval(retrieved_chunks, correct_chunks)
100 print(f"Precision: {metrics['precision']}, Recall: {metrics['recall']}, F1: {metrics['f1']}, MRR: {metrics['mrr']}")
101 ```
102
1033. **Run End-to-End Evaluation**:
104
105 ```bash
106 # Using Python directly
107 from .claude.tools.repo_rag.evaluation import evaluate_end_to_end
108 result = evaluate_end_to_end(query, generated_answer, correct_answer)
109 print(f"Correct: {result['is_correct']}, Explanation: {result['explanation']}")
110 ```
111
112### Expected Performance
113
114Based on Claude Cookbooks results:
115
116- **Basic RAG**: Precision 0.43, Recall 0.66, F1 0.52, MRR 0.74, Accuracy 71%
117- **With Re-ranking**: Precision 0.44, Recall 0.69, F1 0.54, MRR 0.87, Accuracy 81%
118
119### Best Practices
120
1211. **Separate Evaluation**: Evaluate retrieval and end-to-end separately
1222. **Create Comprehensive Datasets**: Cover common and edge cases
1233. **Evaluate Regularly**: Run evaluations after codebase changes
1244. **Track Metrics Over Time**: Monitor improvements
1255. **Use Both Metrics**: Precision/Recall for retrieval, Accuracy for end-to-end
126
127### References
128
129- [RAG Patterns Guide](../docs/RAG_PATTERNS.md) - Implementation patterns
130- [Retrieval Metrics](../tools/repo-rag/metrics.py) - Metric calculations
131- [End-to-End Evaluation](../tools/repo-rag/evaluation.py) - LLM-as-judge
132- [Evaluation Guide](../docs/EVALUATION_GUIDE.md) - Comprehensive evaluation guide
133
134## Memory Protocol (MANDATORY)
135
136**Before starting:**
137Read `.claude/context/memory/learnings.md`
138
139**After completing:**
140
141- New pattern -> `.claude/context/memory/learnings.md`
142- Issue found -> `.claude/context/memory/issues.md`
143- Decision made -> `.claude/context/memory/decisions.md`
144
145> ASSUME INTERRUPTION: If it's not in memory, it didn't happen.