agentleFS
Goodnight77Goodnight77/rag-skills/skills/retrieval-strategies/adaptive-retrieval/SKILL.md

adaptive-retrieval

Skill8 starsChanged 7 months agoMITView on GitHub

Dynamically select retrieval strategies based on query type and characteristics.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use an LLM to classify queries into types.

    line 36
  2. Distinctive:

    When users ask factual, analytical, and opinion-based questions

    line 81
  3. Distinctive:

    When you have the flexibility to implement multiple retrieval strategies

    line 83
  4. Distinctive:

    When implementation simplicity is prioritized over optimization

    line 88
  5. Distinctive:

    When single strategy already provides excellent results

    line 90

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Overview

Adaptive retrieval classifies queries into types (factual, analytical, opinion, contextual) and applies different retrieval strategies optimized for each type. This dynamic approach ensures that each query receives the most appropriate treatment for optimal results.

Problem Statement

One-size-fits-all retrieval has inherent limitations:

  • Query Diversity: Different query types require different retrieval approaches
  • Factual Queries: Need precision and specific information
  • Analytical Queries: Require comprehensive, diverse information
  • Opinion Queries: Benefit from multiple viewpoints and perspectives
  • Contextual Queries: Depend on user-specific context and history

Key Concepts

  • Query Classification: Categorizing queries by their nature and intent
  • Strategy Selection: Choosing optimal retrieval method per query type
  • Factual Strategy: Query enhancement with precise ranking
  • Analytical Strategy: Sub-query generation for comprehensive coverage
  • Opinion Strategy: Viewpoint identification and diversity selection
  • Contextual Strategy: User context integration

Implementation Guide

Step 1: Implement Query Classifier

Use an LLM to classify queries into types.

Why: Accurate classification is the foundation of adaptive retrieval - the right strategy depends on correctly identifying the query type.

Direct the LLM to classify queries into categories: factual, analytical, opinion, or contextual.

Step 2: Implement Factual Retrieval Strategy

Enhance queries for precision and rank results by relevance.

Why: Factual queries benefit from query enhancement that adds relevant terminology and precise ranking that identifies the most authoritative sources.

Rewrite the query to be more specific, retrieve more candidates, and re-rank by relevance to the original query.

Step 3: Implement Analytical Retrieval Strategy

Generate sub-queries and ensure diversity in results.

Why: Analytical queries need coverage of multiple aspects. Sub-query decomposition and diversity selection ensure comprehensive information gathering.

Break down the query into sub-questions, retrieve for each, and select a diverse set of results.

Step 4: Implement Opinion Retrieval Strategy

Identify viewpoints and select diverse opinions.

Why: Opinion queries require multiple perspectives. Viewpoint identification ensures retrieval represents different stances on the topic.

Identify distinct viewpoints on the topic, retrieve for each viewpoint, and select diverse opinions.

Step 5: Implement Contextual Retrieval Strategy

Incorporate user context into the query.

Why: Contextual queries depend on user-specific information. Incorporating context ensures retrieval matches the user's situation and needs.

Reformulate the query to include user context, then retrieve and rank results considering both relevance and context.

Step 6: Build Adaptive Retriever

Combine all strategies into a unified system.

Why: A unified adaptive retriever provides a single interface that automatically selects the optimal strategy for each query.

Route queries to the appropriate strategy based on classification, then execute retrieval using the selected method.

For implementation patterns, see LangChain router architecture, LlamaIndex RouterQueryEngine, and the Self-RAG paper for related concepts.

When to Use This Skill

  • Building RAG systems handling diverse query types
  • When users ask factual, analytical, and opinion-based questions
  • For applications where user context matters (personalized systems)
  • When you have the flexibility to implement multiple retrieval strategies
  • For domains with clear query type patterns (medical, legal, technical)

When NOT to Use This Skill

  • For systems with uniform query types (e.g., only factual)
  • When implementation simplicity is prioritized over optimization
  • For latency-critical applications (classification adds overhead)
  • When single strategy already provides excellent results
  • For very small document collections where strategy differences are minimal

Related Skills

  • Query Transformation Strategies - Query enhancement methods
  • Self-RAG - Reflective retrieval decisions
  • HyDE - Query expansion technique

Metrics & Success Criteria

  • Classification Accuracy: High accuracy in identifying query types (> 85%)
  • Strategy Effectiveness: Each strategy outperforms generic retrieval for its query type
  • Overall Quality: Improved retrieval quality across diverse queries
  • Latency: Acceptable overhead for classification and strategy selection (< 200ms)
  • Adaptiveness: System dynamically responds to different query characteristics

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.