agentleFS
Goodnight77Goodnight77/rag-skills/skills/retrieval-strategies/hybrid-search-bm25-dense/SKILL.md

hybrid-search-bm25-dense

Skill8 starsChanged 7 months agoMITView on GitHub

Combine BM25 and dense retrieval signals to improve search quality across keyword and semantic queries.

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:

    When exact term matching is important alongside conceptual understanding

    line 62
  2. Distinctive:

    When user queries vary from natural language to specific terms

    line 64
  3. Distinctive:

    When pure semantic search already provides excellent results

    line 67
  4. Distinctive:

    When query latency must be minimized (hybrid adds overhead)

    line 69
  5. Distinctive:

    When using a vector database that already implements hybrid search (e.g., Weaviate)

    line 70

≈ “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

Hybrid search combines BM25 (keyword search) with dense vector embeddings (semantic search) to leverage both exact term matching and semantic understanding. This dual approach improves retrieval quality across diverse query types - keyword queries get exact matches, while semantic queries capture conceptual relationships.

Problem Statement

Pure semantic search or pure keyword search each have limitations:

  • Dense-only search: Struggles with exact term matches, proper nouns, and domain-specific terminology
  • Keyword-only search: Fails at understanding synonyms, paraphrasing, and conceptual relationships
  • Different query types: Some queries are keyword-focused ("error code 404") while others are semantic ("how to fix authentication")

Key Concepts

  • BM25: Okapi BM25 algorithm for keyword search with TF-IDF weighting
  • Dense Search: Vector-based semantic search using embeddings
  • Reciprocal Rank Fusion (RRF): Combines results from multiple ranking methods
  • Score Normalization: Bringing different scoring systems to common scale
  • Alpha Parameter: Controls the weighting between keyword and semantic components

Implementation Guide

Step 1: Set Up Dense Search

Implement vector-based semantic search with your chosen embedding model.

Why: Dense search captures semantic meaning but may miss exact term matches that are crucial for many queries.

Step 2: Set Up BM25 Search

Implement keyword-based search using BM25.

Why: BM25 excels at exact term matching, domain-specific terminology, and proper noun searches where semantic models might struggle.

Step 3: Implement Score Normalization

Normalize scores from different ranking methods to comparable scales.

Why: Different scoring systems (cosine similarity vs. BM25 scores) can't be directly combined - normalization creates a common scale.

Step 4: Implement Result Fusion

Combine results from multiple search methods.

Why: RRF is robust to different scoring scales and doesn't require explicit score normalization, making it ideal for fusion.

Step 5: Build the Hybrid Searcher

Combine all components into a single interface.

Why: A unified interface simplifies usage and allows easy experimentation with different fusion strategies and weights.

For implementation patterns, compare OpenSearch hybrid search docs, OpenSearch score ranker processor, the reciprocal rank fusion paper, and Sentence Transformers retrieve & re-rank.

When to Use This Skill

  • Building production RAG systems where both precision and recall matter
  • Handling diverse query types (keyword + semantic)
  • When exact term matching is important alongside conceptual understanding
  • For technical documentation with specific terminology
  • When user queries vary from natural language to specific terms

When NOT to Use This Skill

  • When pure semantic search already provides excellent results
  • For very small datasets where complexity isn't justified
  • When query latency must be minimized (hybrid adds overhead)
  • When using a vector database that already implements hybrid search (e.g., Weaviate)

Related Skills

  • Multi-Pass Retrieval with Reranking - Further refine results
  • Semantic Chunking - Improve content quality
  • Optimize Retrieval Latency - Performance tuning

Metrics & Success Criteria

  • Retrieval Quality: Improved NDCG/precision/recall vs. single-method search
  • Query Type Coverage: Good results for both keyword and semantic queries
  • Latency: Hybrid search within 1.5x of single-method latency
  • Maintainability: Clear separation of components
  • Flexibility: Easy to adjust alpha and fusion method

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.