/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,
$ npx -y skills add agentsope/SkillAlchemy --skill agentsop-hybrid-retrieval --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/agentsop-hybrid-retrieval
Context preview
The summary Claude sees to decide when to auto-load this skill.
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,
SKILL.md
agentsop-hybrid-retrieval.SKILL.mdname: agentsop-hybrid-retrieval
version: 0.1.0
description: |
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-weighted), and per-query-type alpha
tuning. Frame the work as recovering lexical identity that dense pooling destroys,
not as "add keyword search for completeness". Cross-links [[llamaindex]].
overlay: true
cross_links: [llamaindex, langchain]
trigger_keywords:
- "hybrid search"
- "hybrid retrieval"
- "BM25"
- "sparse retrieval"
- "dense plus sparse"
- "QueryFusionRetriever"
- "EnsembleRetriever"
- "RRF"
- "reciprocal rank fusion"
- "alpha tuning"
- "keyword search RAG"
when_to_use:
- "the corpus contains exact-match tokens: identifiers, error codes, SKUs, part numbers, API/function names, proper nouns, legal/medical citations, rare jargon"
- "users report 'I searched the exact code/name and got nothing / the wrong doc' on a dense-only retriever"
- "reviewing a retriever where traffic includes lexical-identity lookups but only embeddings are wired"
- "tuning recall on a corpus where both meaning AND exact strings matter"
- "deciding between pure dense, hybrid, or sparse-first for a new RAG corpus"
when_not_to_use:
- "traffic is purely semantic / conceptual with <5% lexical-identity queries — hybrid is over-engineering"
- "the corpus has no stable identifiers and queries never reference exact strings"
- "pre-baseline: ship dense-only and measure first; hybrid is a Stage-3 optimization (see [[llamaindex]])"
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(...)` with no sparse leg). 4. You are tuning recall and have already exhausted the cheap dense knobs (prompt, embedding model, chunk size) per the [[llamaindex]] optimization ladder — hybrid is the next rung. 5. The user mentions hybrid search, BM25, sparse retrieval, RRF, `QueryFusionRetriever`, `EnsembleRetriever`, or vector-store-native hybrid (Qdrant/Weaviate/Pinecone).
Do **not** activate when:
- Traffic is purely semantic ("what does X mean?", "summarize the policy") with a
lexical-identity share **<5%** — adding BM25 doubles index footprint for no gain.
- The corpus has no stable identifiers and no query ever quotes an exact string.
- No dense baseline + eval loop exists yet. Hybrid is a **Stage-3** optimization
([[llamaindex]] Stage 3 step 4): baseline and measure before fusing.
---
2. 核心心智模型 (Core Mental Model)
Three principles. Violating any of them is why teams "try hybrid and conclude it didn't help".
Principle 1 — Dense and sparse fail in opposite directions
Dense embedding models **destroy lexical identity by pooling token representations**: querying a specific error string yields a vector that captures *"document about SSL errors"* rather than *"document containing this exact string"*. BM25 does the inverse — it scores against an **inverted index of exact tokens** and is blind to synonyms and paraphrase. (TianPan, *Hybrid search in production*, 2026; cited in [[llamaindex]] Dilemma 2.)
> **Operational corollary**: the symptom "I pasted the exact code and got nothing" > is not a bug in the embedding model — it is the embedding model working as > designed. The fix is a second retriever that indexes tokens, not a better > embedding.
Principle 2 — Hybrid is traffic-driven, not theoretical
Whether to add sparse is decided by the **query-type distribution of real traffic**, not by a belief that "more retrievers = better". The decision threshold is the **lexical share**: the fraction of queries whose correct answer hinges on an exact token. Below ~5% → dense-only. 5–50% → hybrid. Above ~50% (code, logs, legal) → invert to sparse-first with dense as a rerank signal. (Cited in [[llamaindex]] OP-04 / Dilemma 2.)
Principle 3 — One global alpha underperforms; tune per query type
`alpha` is the dense↔sparse blend (`alpha=1` → pure dense, `alpha=0` → pure sparse). A semantic query wants high alpha; a lexical-identity query wants low alpha. A single **global** alpha picked to help lexical queries *hurts* the semantic slice — which is exactly why a flat alpha "loses to pure dense" and teams wrongly conclude hybrid failed. Tune alpha **per query type**, or route per type and pick alpha per route. (LlamaIndex alpha-tuning blog; [[llamain
Read more
name: agentsop-hybrid-retrieval version: 0.1.0 description: | 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-weighted), and per-query-type alpha tuning. Frame the work as recovering lexical identity that dense pooling destroys, not as "add keyword search for completeness". Cross-links [[llamaindex]]. overlay: true cross_links: [llamaindex, langchain] trigger_keywords: - "hybrid search" - "hybrid retrieval" - "BM25" - "sparse retrieval" - "dense plus sparse" - "QueryFusionRetriever" - "EnsembleRetriever" - "RRF" - "reciprocal rank fusion" - "alpha tuning" - "keyword search RAG" when_to_use: - "the corpus contains exact-match tokens: identifiers, error codes, SKUs, part numbers, API/function names, proper nouns, legal/medical citations, rare jargon" - "users report 'I searched the exact code/name and got nothing / the wrong doc' on a dense-only retriever" - "reviewing a retriever where traffic includes lexical-identity lookups but only embeddings are wired" - "tuning recall on a corpus where both meaning AND exact strings matter" - "deciding between pure dense, hybrid, or sparse-first for a new RAG corpus" when_not_to_use: - "traffic is purely semantic / conceptual with <5% lexical-identity queries — hybrid is over-engineering" - "the corpus has no stable identifiers and queries never reference exact strings" - "pre-baseline: ship dense-only and measure first; hybrid is a Stage-3 optimization (see [[llamaindex]])"
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(...)` with no sparse leg). 4. You are tuning recall and have already exhausted the cheap dense knobs (prompt, embedding model, chunk size) per the [[llamaindex]] optimization ladder — hybrid is the next rung. 5. The user mentions hybrid search, BM25, sparse retrieval, RRF, `QueryFusionRetriever`, `EnsembleRetriever`, or vector-store-native hybrid (Qdrant/Weaviate/Pinecone).
Do **not** activate when:
- Traffic is purely semantic ("what does X mean?", "summarize the policy") with a
lexical-identity share **<5%** — adding BM25 doubles index footprint for no gain.
- The corpus has no stable identifiers and no query ever quotes an exact string.
- No dense baseline + eval loop exists yet. Hybrid is a **Stage-3** optimization
([[llamaindex]] Stage 3 step 4): baseline and measure before fusing.
---
2. 核心心智模型 (Core Mental Model)
Three principles. Violating any of them is why teams "try hybrid and conclude it didn't help".
Principle 1 — Dense and sparse fail in opposite directions
Dense embedding models **destroy lexical identity by pooling token representations**: querying a specific error string yields a vector that captures *"document about SSL errors"* rather than *"document containing this exact string"*. BM25 does the inverse — it scores against an **inverted index of exact tokens** and is blind to synonyms and paraphrase. (TianPan, *Hybrid search in production*, 2026; cited in [[llamaindex]] Dilemma 2.)
> **Operational corollary**: the symptom "I pasted the exact code and got nothing" > is not a bug in the embedding model — it is the embedding model working as > designed. The fix is a second retriever that indexes tokens, not a better > embedding.
Principle 2 — Hybrid is traffic-driven, not theoretical
Whether to add sparse is decided by the **query-type distribution of real traffic**, not by a belief that "more retrievers = better". The decision threshold is the **lexical share**: the fraction of queries whose correct answer hinges on an exact token. Below ~5% → dense-only. 5–50% → hybrid. Above ~50% (code, logs, legal) → invert to sparse-first with dense as a rerank signal. (Cited in [[llamaindex]] OP-04 / Dilemma 2.)
Principle 3 — One global alpha underperforms; tune per query type
`alpha` is the dense↔sparse blend (`alpha=1` → pure dense, `alpha=0` → pure sparse). A semantic query wants high alpha; a lexical-identity query wants low alpha. A single **global** alpha picked to help lexical queries *hurts* the semantic slice — which is exactly why a flat alpha "loses to pure dense" and teams wrongly conclude hybrid failed. Tune alpha **per query type**, or route per type and pick alpha per route. (LlamaIndex alpha-tuning blog; [[llamain
Other skills on skillalchemy.
- /LEAP
LEAP — 落地执行引擎。内含两条管线:A 分支蒸馏(从 raw data 提取 skill)、 B 分支融合(多 skill 编织为一个)。被 SkillAlchemy 编排器调用。 Use when 编排器判断需要蒸馏或融合时。
Open skill - /Lens
Lens — 给你的问题加一层认知镜片。输入任意任务描述,输出增强版 description, 发现「你不知道自己不知道」的隐性维度、前置条件和认知路线。 Use when 用户说「帮我想想」「分析一下」「生成 skill」「蒸馏」「融合」 或输入看起来太简单需要展开。
Open skill - /agentsop-agent-topology-selection
Cross-framework enhancement overlay for choosing a multi-agent topology BEFORE writing any agent. A binary-question rubric — is single-agent + tools enough? do agents need to know about each other? does the output need one voice? — maps the answer to single-agent / supervisor /
Open skill - /agentsop-aider
SOP for terminal-based, git-native AI pair programming with Aider (git work-tree + tree-sitter repo-map + edit-format + human-in-loop REPL). Use when editing code in an existing git repo via an LLM, when you need to converge a change to 2-5 files, pick an edit format that fits
Open skill - /agentsop-bio-fraud-forensics
Screens biomedical / life-science papers for signs of data fabrication, image manipulation, and statistical anomalies, using the detection techniques distilled from the field's canonical exposure platforms (PubPeer, Data Colada, Science Integrity Digest, For Better Science) and
Open skill - /agentsop-bounded-loop
Universal discipline for any LM-driven loop — agent retries, plan-act-observe, multi-agent handoffs, optimiser passes, test-fix cycles. Encodes the one rule every framework documents quietly and every team relearns expensively: the LM in the loop is NEVER a reliable terminator.
Open skill

