agentleFS
patonkikhpatonkikh/APES/skills/rag/retriever-optimizer/skill.md

retriever-optimizer

Skill3 starsChanged 4 months agoMITView on GitHub

Optimize RAG retrieval quality: tune top-k, reranking, query preprocessing, and filtering to maximize recall and precision. Use when working on RAG pipelines, chunking, embeddings, retrieval, or hybrid search.

The file

Files
skill.md

Retriever Optimizer

Purpose

Optimize RAG retrieval quality: tune top-k, reranking, query preprocessing, and filtering to maximize recall and precision.

Input: RAG architecture, golden query set (optional), current retrieval metrics
Output: Retriever optimization report with parameter recommendations and A/B test plan Examples: See examples.md for worked input/output.


Workflow

Step 1: Baseline retrieval metrics

Measure on golden set:

MetricCurrentTarget
Recall@k
Precision@k
MRR
Latency p95

Step 2: Analyze failure modes

Categorize misses:

Failure typeCountExample query
Wrong chunk retrieved
Right doc, wrong section
Query-document vocabulary gap
Multi-hop not supported

Step 3: Tune retrieval parameters

ParameterCurrentRecommendedRationale
top-k initial
top-k after rerank
Similarity threshold
Metadata filters

Step 4: Recommend enhancements

Options:

  • Query expansion / HyDE
  • Cross-encoder reranking
  • Metadata pre-filtering
  • Hypothetical document embedding
  • Query decomposition

Prioritize by failure mode analysis.

Step 5: Define A/B test plan

VariantChangeSuccess metricSample size

Step 6: Validate

Run Validation checklist.


Decision Rules

ConditionAction
No golden query setCreate minimum 20 Q&A pairs before tuning
Recall low, precision highIncrease k, add query expansion
Precision low, recall highAdd reranker, raise similarity threshold
Latency exceeds budgetReduce k, use lighter reranker
Vocabulary gap failures dominateRecommend hybrid-search-advisor

Validation

  • Baseline metrics documented
  • Failure modes categorized with examples
  • Parameter recommendations with rationale
  • Enhancements prioritized by failure type
  • A/B test plan defined
  • Latency impact estimated per change
  • No tuning without measurable success criteria

Anti-patterns

  • Random k tuning — changing top-k without measuring.
  • Rerank everything — expensive reranker on all queries regardless of need.
  • Ignore latency — quality gains that break SLA.
  • Overfit golden set — tuning to 5 queries only.
  • No baseline — optimizing without before metrics.

Best Practices

  • Hold out 20% of golden set for validation.
  • Tune one parameter at a time.
  • Log retrieval results in production for continuous improvement.
  • Pair with hybrid-search-advisor for keyword gaps.
  • Re-evaluate after corpus or embedding changes.

Output Structure

# Retriever Optimization: [System Name]

## Baseline
| Metric | Value | Target |
|--------|-------|--------|

## Failure Analysis
| Type | % | Example | Fix |
|------|---|---------|-----|

## Parameter Tuning
| Param | Before | After | Impact |
|-------|--------|-------|--------|

## Recommended Enhancements
| Priority | Enhancement | Addresses |
|----------|-------------|-----------|

## A/B Test Plan
| Variant | Metric | Duration |
|---------|--------|----------|

Next Skills

OutcomeRecommended Skill
Add keyword retrievalrag/hybrid-search-advisor
Fix chunking issuesrag/chunking-strategy-advisor
Change embeddingsrag/embedding-strategy-advisor
Citation validationrag/citation-validator

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.