Agent skill · Backend & API

agentsop-hybrid-retrieval

Enhancement-overlay SOP for adding sparse (BM25 / keyword) retrieval alongside dense (embedding) retrieval. Activate when a calling agent is building, reviewing, or debugging a retrieval pipeline whose corpus contains exact-match tokens — identifiers, error codes, SKUs, API/function names, proper nouns, citations, rare jargon — that pure dense embedding silently misses. Encodes the single decision rule (**hybrid is traffic-driven, not theoretical: add sparse only when the query share that depends on exact tokens is non-trivial**), the wiring of QueryFusionRetriever-style fusion (RRF vs alpha-w

agentsopegithub.com/agentsopeGitHub ↗
claude-codeMIT
Install
npx skills add agentsope/SkillAlchemy --skill agentsop-hybrid-retrieval --agent claude-code

Same command for any agent — swap --agent for codex, cursor, copilot.

Facts
Files in the skill folder: 4
SKILL.md size: 25 KB
Bundled scripts: none
Version: 0.1.0
Path: skills/agentsop-hybrid-retrieval/SKILL.md
Open the folder on GitHub →
Where it comes from
Stars: 255
Language: Python

Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.

Review
written from the skill's own SKILL.md · Aug 5, 2026

What it does

Sets up a hybrid retrieval workflow that combines dense embedding-based recall with sparse BM25 retrieval to capture exact-token matches (identifiers, codes, names, etc.) when lexical traffic justifies it. It defines a decision rule that hybrid should be activated only when the query-share of lexical signals is non-trivial, and specifies how to fuse the two retrievers and tune alpha per query type.

How it works

  • Activation is triggered by conditions including presence of exact-match tokens, bug reports about exact queries failing with dense-only, and evidence from PR reviews or traffic composition.
  • Build two retrievers over the same node set: a dense retriever (index.as_retriever(...)) and a sparse BM25 retriever (BM25Retriever.from_defaults(nodes=...), with similarity_top_k widened to 10–20).
  • Fuse them using a deliberate fusion method, defaulting to Reciprocal Rank Fusion (QueryFusionRetriever(mode="reciprocal_rerank")) or using relative_score with retriever_weights when a labeled set exists.
  • Tune alpha per query type (semantic vs lexical) by evaluating a set of alpha values {0.0, 0.25, 0.5, 0.75, 1.0} and selecting per-type settings that lift lexical recall without regressing semantic recall; if needed, route by query type to apply per-type alpha.
  • Consider native hybrid support in the vector store (Qdrant/Weaviate/Pinecone) to avoid a separate BM25 index when available.
  • Gate changes with an eval loop to ensure lexical gains do not regress semantic performance.

When to use it

Use when the corpus contains exact-match tokens and users report missing results for exact queries, or when tuning recall on a corpus where both meaning and exact strings matter, and you are deciding between pure dense, hybrid, or sparse-first configurations.

What it can touch

  • The two retrievers: dense index (via index.as_retriever) and sparse BM25 retriever (BM25Retriever.from_defaults).
  • Fusion logic via QueryFusionRetriever with mode values like "reciprocal_rerank" or "relative_score" and retriever_weights.
  • Alpha tuning workflows per query type and routing decisions for per-type blends.

Caveats

  • Activation is traffic-driven; — not theoretical — and the lexical share must meet thresholds (5–50% for hybrid; >50% inverts to BM25-first). If the lexical share is below 5%, dense-only is recommended.
  • Global alpha tuning can hurt semantic performance; per-type tuning is advised.
  • If the vector store provides native hybrid, it may be preferable to use that instead of a separate BM25 index.
  • The approach assumes a common node set for both dense and sparse retrievers; misalignment can reduce recall.
From the SKILL.md

# Hybrid Retrieval · Dense + Sparse SOP > Third-person operating model for a coder agent that owns retrieval recall on a > corpus where *both* meaning and exact tokens matter. The audience is the LLM > agent writing or reviewing retrieval code — not an end user. > **One sentence**: *Dense captures meaning, sparse captures exact tokens; hybrid > wins when both matter — but only fuse them when traffic actually carries > exact-match queries, and tune the blend per query type or hybrid loses to dense.* --- ## 1. 何时激活 (Activation Rules) Activate this skill when **any** of the following holds: 1. The corpus contains **exact-match tokens** that a query may reference verbatim: error codes (`ERR_SSL_PROTOCOL`), SKUs / part numbers (`A1-2293-X`), API or function names (`as_query_engine`), proper nouns, legal/medical citations (`42 U.S.C. § 1983`), version strings, rare jargon, ticket IDs. 2. A bug report says **"I searched the exact code/name/string and got nothing"**, or "the right document exists but dense retrieval ranks it below fuzzy near-misses". 3. PR review surfaces a retriever serving lexical-identity traffic but wired **dense-only** (`index.as_retriever(...)` / `similarity_search(.

What's inside
Steps it walks through
  1. 1. 何时激活 (Activation Rules)
  2. 2. 核心心智模型 (Core Mental Model)
  3. Principle 1 — Dense and sparse fail in opposite directions
  4. Principle 2 — Hybrid is traffic-driven, not theoretical
  5. Principle 3 — One global alpha underperforms; tune per query type
  6. 3. SOP 工作流 (Agentic Protocol)
  7. Stage 0 — Decide if the corpus needs sparse at all
  8. Stage 1 — Wire BM25 + dense as two retrievers
  9. Stage 2 — Fuse (RRF or alpha-weighted)
  10. Stage 3 — Tune alpha by query type (the gate)
  11. 4. 操作模型 (Operation Models)
  12. OP-01 WhenHybridChecklist
  13. OP-02 ChooseFusionMethod
  14. OP-03 WireBM25Leg
Ships with 3 files
  • README.md
  • intermediate/operation_candidates.json
  • references/R1-source-evidence.md
More from SkillAlchemy
All skills →
About this skill
What does the agentsop-hybrid-retrieval skill do?

Enhancement-overlay SOP for adding sparse (BM25 / keyword) retrieval alongside dense (embedding) retrieval. Activate when a calling agent is building, reviewing, or debugging a retrieval pipeline whose corpus contains exact-match tokens — identifiers, error codes, SKUs, API/function names, proper nouns, citations, rare jargon — that pure dense embedding silently misses. Encodes the single decision rule (**hybrid is traffic-driven, not theoretical: add sparse only when the query share that depends on exact tokens is non-trivial**), the wiring of QueryFusionRetriever-style fusion (RRF vs alpha-w

How do I install it?

Run `npx skills add agentsope/SkillAlchemy --skill agentsop-hybrid-retrieval --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.

Where does this skill come from?

From agentsope/SkillAlchemy, a repository with 255 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.

Is a popular skill a good skill?

Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.

Keep going