Skills hybrid-search-implementation
🔍

hybrid-search-implementation

Safe ⚡ Contains scripts📁 Filesystem access

Implement Hybrid Search for RAG

Pure vector search misses exact matches while keyword search fails on semantic queries. This skill provides ready-to-use templates for combining both approaches using RRF fusion, linear combination, and cross-encoder reranking.

Supports: Claude Codex Code(CC)
📊 70 Adequate
1

Download the skill ZIP

2

Upload in Claude

Go to Settings → Capabilities → Skills → Upload skill

3

Toggle on and start using

Test it

Using "hybrid-search-implementation". How do I combine vector and keyword search results?

Expected outcome:

  • Use Reciprocal Rank Fusion (RRF):
  • 1. Run both searches to get ranked lists
  • 2. For each result, calculate score = sum(weight / (k + rank))
  • 3. Fuse by sorting combined scores
  •  
  • Example:
  • vector_results = [('doc1', 0.9), ('doc2', 0.8)]
  • keyword_results = [('doc2', 0.95), ('doc3', 0.7)]
  • fused = rrf_fusion([vector_results, keyword_results])
  • # Returns [('doc2', 0.03), ('doc1', 0.016), ('doc3', 0.016)]

Using "hybrid-search-implementation". What's the difference between RRF and linear fusion?

Expected outcome:

  • RRF (Reciprocal Rank Fusion):
  • - Score = sum(1 / (k + rank))
  • - Rank-based, no score normalization needed
  • - k=60 is standard constant
  • - Works well without tuning
  •  
  • Linear Combination:
  • - Score = alpha * vector_score + (1-alpha) * keyword_score
  • - Requires score normalization to [0,1]
  • - Alpha needs empirical tuning per dataset
  • - More controllable but requires tuning

Using "hybrid-search-implementation". Should I add reranking to my hybrid search?

Expected outcome:

  • Yes, reranking improves quality significantly:
  •  
  • 1. Fetch more candidates from hybrid search (50-100)
  • 2. Use cross-encoder to score query-document pairs
  • 3. Return top-k reranked results
  •  
  • Trade-offs:
  • - + Better precision and relevance
  • - - Additional latency (cross-encoder inference)
  • - Model: cross-encoder/ms-marco-MiniLM-L-6-v2 is a good starting point

Security Audit

Safe
v5 • 1/21/2026

All static findings are false positives. The skill contains documentation templates for hybrid search algorithms (RRF, linear fusion) with PostgreSQL, Elasticsearch, and custom RAG pipelines. Static scanner misidentified mathematical formulas as crypto operations, markdown code fences as command execution, and benign terminology as security risks. No malicious code or credential exfiltration present.

2
Files scanned
1,169
Lines analyzed
2
findings
5
Total audits

Risk Factors

⚡ Contains scripts (1)
📁 Filesystem access (1)
Audited by: claude View Audit History →

Quality Score

38
Architecture
100
Maintainability
87
Content
30
Community
100
Security
87
Spec Compliance

What You Can Build

Build RAG Systems with Better Recall

Combine semantic understanding with exact matching to improve document retrieval for LLM context. Handle queries that need both conceptual similarity and specific terminology.

Implement Enterprise Search

Create search systems that find both semantically related content and documents containing exact terms like product codes, names, or identifiers.

Improve Search Quality Metrics

Apply fusion techniques like RRF to boost recall without sacrificing precision. Log individual scores to debug and tune search quality.

Try These Prompts

Basic RRF Fusion
Help me implement Reciprocal Rank Fusion to combine vector and keyword search results. I have two lists of (doc_id, score) tuples. Show me how to fuse them.
PostgreSQL Setup
Show me how to set up a PostgreSQL table with pgvector for embeddings and tsvector for full-text search. Include the HNSW and GIN index definitions.
Elasticsearch kNN
Help me write an Elasticsearch hybrid search query that combines dense vector kNN with BM25 text matching using the RRF rank feature.
Custom RAG Pipeline
Create a complete HybridRAGPipeline class that executes vector and keyword searches in parallel, fuses results with configurable methods (RRF or linear), and optionally reranks with a cross-encoder.

Best Practices

  • Start with RRF fusion as it works well without parameter tuning. Use k=60 as the standard constant.
  • Fetch more candidates from individual searches (3x the final limit) before fusion to ensure good recall.
  • Log both vector and keyword scores separately during development. This helps debug when results are missing.
  • Use cross-encoder reranking for production systems. The quality improvement is significant.

Avoid

  • Don't assume a single fusion weight works for all queries. Some queries need more semantic matching while others need keyword matching.
  • Don't skip keyword search entirely. Exact term matching handles names, codes, and specific phrases better than vectors.
  • Don't over-fetch candidates. Balance recall needs against latency. 50-100 candidates before reranking is usually sufficient.

Frequently Asked Questions

What fusion method should I start with?
Start with Reciprocal Rank Fusion (RRF). It performs well without tuning and is the default in many production systems. Use k=60 as the constant. Switch to linear combination only if you need explicit control over vector-to-keyword balance.
How do I handle different score ranges between vector and keyword search?
Normalize scores to [0, 1] before combining. For vectors, use min-max normalization. For BM25, scores are already somewhat normalized. Linear combination requires normalization; RRF does not because it uses ranks instead of raw scores.
What vector dimensions should I use?
Common choices are 768 (Sentence Transformers), 1024 (large models), or 1536 (OpenAI ada-002). Match your embedding model. PostgreSQL pgvector and Elasticsearch both support configurable dimensions.
How do I choose the vector-to-keyword weight (alpha)?
Start with alpha=0.5 (equal weighting). Test on your specific queries and adjust based on whether you need more semantic recall or exact matching. Some queries need alpha=0.7-0.8, others need 0.3-0.4.
Can I use hybrid search without a reranker?
Yes, hybrid search without reranking works well for many use cases. The fusion step (RRF or linear) already combines results intelligently. Add reranking when you need the highest quality results and can tolerate additional latency.
What databases support hybrid search?
PostgreSQL with pgvector extension, Elasticsearch 8.x (native kNN + RRF), Vespa, Milvus, Qdrant, and Weaviate all support hybrid search patterns. The choice depends on your existing infrastructure and scaling requirements.