RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Eruo Fredoline
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /Courses
  5. /Advanced RAG — Chunking, Retrieval, Re-ranking
  6. /Ch. 4
Advanced RAG — Chunking, Retrieval, Re-ranking

04. Multi-Strategy Retrieval

Chapter 4 of 24 · 15 min
KEY INSIGHT

Routing queries to appropriate retrieval strategies reduces noise and improves signal in the initial result set.

Production retrieval rarely relies on a single method. Different query types demand different strategies, and combining approaches improves recall.

Query classification determines which retrieval paths to activate. Transactional queries ("what is X") need precise definitions. Exploratory queries ("how does Y work") benefit from broad context. Factual queries ("when did Z happen") require exact matches.

Strategy routing assigns queries to retrieval methods:

  • Dense retrieval handles semantic similarity and paraphrases
  • Sparse retrieval handles exact terminology and technical terms
  • Keyword matching handles product names, dates, identifiers
from enum import Enum
from typing import List, Callable

class QueryType(Enum):
    SEMANTIC = "semantic"      # Conceptual, how/why questions
    FACTUAL = "factual"        # Specific data, dates, names
    DEFINITIONAL = "definitional"  # What is X, definitions
    PROCEDURAL = "procedural"  # How to, steps, tutorials

class MultiStrategyRetriever:
    def __init__(self, retrievers: dict, classifier: Callable):
        self.retrievers = retrievers  # {strategy_name: retriever}
        self.classifier = classifier
    
    def retrieve(self, query: str, top_k: int = 10) -> List[dict]:
        query_type = self.classifier(query)
        
        # Activate relevant strategies
        strategies = self._get_strategies_for_type(query_type)
        
        results = []
        for strategy in strategies:
            retrieved = self.retrievers[strategy].search(query, top_k * 2)
            results.extend(retrieved)
        
        # Deduplicate and return combined results
        return self._deduplicate_and_rank(results, top_k)
    
    def _get_strategies_for_type(self, query_type: QueryType) -> List[str]:
        strategy_map = {
            QueryType.SEMANTIC: ["dense", "sparse"],
            QueryType.FACTUAL: ["sparse", "dense"],
            QueryType.DEFINITIONAL: ["dense"],
            QueryType.PROCEDURAL: ["dense", "sparse", "keyword"]
        }
        return strategy_map.get(query_type, ["dense"])

Local verification checkpoint

Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.

Local verification checkpoint

Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.

EXERCISE

Build a simple keyword-based classifier using regex patterns for 3 query types. Test on 50 queries and report precision per type.

← Chapter 3
Fixed-Size vs Semantic Tradeoffs
Chapter 5 →
Dense Retrieval Deep Dive