Hybrid Search Architect
Skill9 starsChanged 8 months agoMITView on GitHub
Designs a hybrid retrieval pipeline combining dense vector search and BM25 sparse search with reciprocal rank fusion, and explains when to use each configuration.
- Installs packages
In this repository61 other files it gives its agents.
- Accessibility Audit HelperSkill
- Agent Context File WriterSkill
- Agent Evaluation Framework BuilderSkill
- AI Feature Spec WriterSkill
- API Documentation GeneratorSkill
- REST API Endpoint DesignerSkill
- Architecture ExplainerSkill
- Article RepurposerSkill
- Auth Flow PlannerSkill
- Blog Outline GeneratorSkill
- Breaking Change DetectorSkill
- Bug Root Cause AnalyzerSkill
- Caching Strategy AdvisorSkill
- Changelog CuratorSkill
- Code Review ChecklistSkill
- Database Schema ReviewerSkill
- Docker Compose GeneratorSkill
- Documentation Gap FinderSkill
- Edge Case DiscoverySkill
- Error Log SummarizerSkill
- FAQ GeneratorSkill
- Flaky Test AnalyzerSkill
- Form UX OptimizerSkill
- Git Commit WriterSkill
- Hallucination Risk ReviewerSkill
- Incident Postmortem WriterSkill
- Issue to PR PlannerSkill
- Landing Page Copy ImproverSkill
- LangGraph State Machine DesignerSkill
- LLM Cost OptimizerSkill
- LLM Tracing and Observability SetupSkill
- MCP Integration AssistantSkill
- MCP Server BuilderSkill
- Migration Guide WriterSkill
- Newsletter Summary WriterSkill
- Observability ChecklistSkill
- Playwright Test BuilderSkill
- PR Description WriterSkill
- Prompt Injection Defense AuditorSkill
- Prompt RefinerSkill
- Prompt Version Control WorkflowSkill
- RAG Chunking Strategy AdvisorSkill
- RAG Workflow PlannerSkill
- React Component ReviewerSkill
- README WriterSkill
- Refactor PlannerSkill
- Release Notes GeneratorSkill
- Responsive Layout ReviewerSkill
- SDK Quickstart WriterSkill
- SEO Content OptimizerSkill
- SEO Metadata GeneratorSkill
- Social Post Thread WriterSkill
- Sprint Summary GeneratorSkill
- SQL Query OptimizerSkill
- Stack Trace AnalyzerSkill
- Technical Blog Post WriterSkill
- Tech Debt AuditorSkill
- Troubleshooting Guide BuilderSkill
- Unit Test ImproverSkill
- Unit Test WriterSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
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
- Distinctive: line 158
If your backend supports an alpha/weight parameter:
- Distinctive: line 168
Test with your actual query distribution — sample 50 real queries and compare precision at k=5 across alpha values.
- Distinctive: line 172
After hybrid retrieval, a cross-encoder reranker re-scores the top results with full query-document attention.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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.
Files
Hybrid Search Architect
What this skill does
This skill designs a hybrid search pipeline that combines dense vector search (semantic similarity) with BM25 sparse search (keyword matching). Hybrid search outperforms either method alone on most retrieval benchmarks because vector search handles semantic meaning while BM25 handles exact keyword matches, product names, codes, and rare terms. This skill picks the right combination and fusion strategy for your use case.
How to use
Claude Code / Cline
Copy this file to .agents/skills/hybrid-search-architect/SKILL.md in your project root.
Then ask:
- "Use the Hybrid Search Architect to improve our RAG pipeline's retrieval."
- "Design a hybrid search system for our product documentation."
Provide:
- What you're searching (type of documents)
- What queries look like (keywords, natural language, codes/IDs)
- Your current search stack (Pinecone, Weaviate, Elasticsearch, pgvector, etc.)
- Latency requirements
Cursor / Codex
Describe your current retrieval setup and query patterns alongside these instructions.
The Prompt / Instructions for the Agent
Step 1 — Determine if hybrid search is needed
| Query pattern | Pure vector | Pure BM25 | Hybrid |
| Natural language questions | ✓ | — | ✓ |
| Exact product names / SKUs | — | ✓ | ✓ |
| Technical codes / IDs | — | ✓ | ✓ |
| Conceptual / semantic | ✓ | — | ✓ |
| Mixed (most real-world) | — | — | ✓ |
Use hybrid search when: queries are mixed (some keyword, some semantic), documents contain both prose and structured data, or pure vector search misses obvious keyword matches.
Step 2 — Choose a stack
Option A: Weaviate (easiest hybrid, built-in)
# pip install weaviate-client
import weaviate
from weaviate.classes.query import HybridFusion
client = weaviate.connect_to_local()
collection = client.collections.get("Documents")
results = collection.query.hybrid(
query="payment processing error",
fusion_type=HybridFusion.RELATIVE_SCORE, # or RANKED
alpha=0.5, # 0 = pure BM25, 1 = pure vector, 0.5 = balanced
limit=10,
return_metadata=["score", "explain_score"]
)Option B: Elasticsearch / OpenSearch (production-grade)
from elasticsearch import Elasticsearch
es = Elasticsearch("http://localhost:9200")
query = {
"query": {
"bool": {
"should": [
# BM25 component
{"match": {"content": {"query": user_query, "boost": 1.0}}},
# Dense vector component (kNN)
{"knn": {
"field": "embedding",
"query_vector": get_embedding(user_query),
"num_candidates": 100,
"boost": 1.0
}}
]
}
},
"size": 10
}
results = es.search(index="documents", body=query)Option C: pgvector + custom BM25 (for PostgreSQL users)
# pip install pgvector psycopg2
# Run both queries, then fuse results
async def hybrid_search(query: str, k: int = 10) -> list[dict]:
embedding = await get_embedding(query)
# Dense search
vector_results = await db.fetch("""
SELECT id, content, 1 - (embedding <=> $1::vector) as score
FROM documents
ORDER BY embedding <=> $1::vector
LIMIT $2
""", embedding, k * 2)
# Sparse search (tsvector full-text search)
bm25_results = await db.fetch("""
SELECT id, content, ts_rank(to_tsvector('english', content), plainto_tsquery($1)) as score
FROM documents
WHERE to_tsvector('english', content) @@ plainto_tsquery($1)
ORDER BY score DESC
LIMIT $2
""", query, k * 2)
return reciprocal_rank_fusion(vector_results, bm25_results, k=k)Step 3 — Implement Reciprocal Rank Fusion (RRF)
RRF is the standard way to combine results from multiple ranked lists. It's simple, effective, and doesn't require tuning score scales:
def reciprocal_rank_fusion(
*ranked_lists: list[dict],
k: int = 60,
top_n: int = 10
) -> list[dict]:
"""
Combine multiple ranked result lists using Reciprocal Rank Fusion.
k=60 is the standard constant (from the original RRF paper).
"""
scores: dict[str, float] = {}
docs: dict[str, dict] = {}
for ranked_list in ranked_lists:
for rank, doc in enumerate(ranked_list, start=1):
doc_id = doc["id"]
scores[doc_id] = scores.get(doc_id, 0) + 1 / (k + rank)
docs[doc_id] = doc
sorted_ids = sorted(scores, key=lambda x: scores[x], reverse=True)
return [docs[doc_id] for doc_id in sorted_ids[:top_n]]Step 4 — Tune the alpha parameter
If your backend supports an alpha/weight parameter:
| Use case | Alpha (vector weight) |
| Technical docs with many exact terms | 0.3 |
| General knowledge / FAQ | 0.5 |
| Semantic / conceptual search | 0.7 |
| Code search | 0.4 |
| Mixed content (default) | 0.5 |
Test with your actual query distribution — sample 50 real queries and compare precision at k=5 across alpha values.
Step 5 — Add a reranker (optional but high-impact)
After hybrid retrieval, a cross-encoder reranker re-scores the top results with full query-document attention. This is the single highest-impact quality improvement after hybrid search:
# pip install sentence-transformers
from sentence_transformers import CrossEncoder
reranker = CrossEncoder("cross-encoder/ms-marco-MiniLM-L-6-v2")
def rerank(query: str, results: list[dict], top_n: int = 5) -> list[dict]:
"""Re-rank results using a cross-encoder. Retrieve wide, rerank narrow."""
pairs = [(query, r["content"]) for r in results]
scores = reranker.predict(pairs)
ranked = sorted(zip(results, scores), key=lambda x: x[1], reverse=True)
return [doc for doc, _ in ranked[:top_n]]
# Usage: retrieve top 20 via hybrid, rerank to top 5
candidates = hybrid_search(query, k=20)
final_results = rerank(query, candidates, top_n=5)Step 6 — Evaluation
Measure retrieval quality with Recall@K and Mean Reciprocal Rank:
def recall_at_k(relevant_ids: set, retrieved_ids: list[str], k: int) -> float:
return len(relevant_ids & set(retrieved_ids[:k])) / len(relevant_ids)
def mrr(relevant_ids: set, retrieved_ids: list[str]) -> float:
for rank, doc_id in enumerate(retrieved_ids, 1):
if doc_id in relevant_ids:
return 1 / rank
return 0.0Benchmark: run 50 labeled queries, compare Recall@5 for pure vector vs. pure BM25 vs. hybrid. Hybrid should outperform both by 10–25% on mixed query sets.
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
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.

