AI Agents & RAG

Verified against Pinecone · 2026-07-24

Tune hybrid dense and sparse retrieval instead of guessing at the weighting

A prompt for deciding how to combine vector similarity and BM25/keyword scores, and where reranking fits, based on actual query failures classified by type — not a fixed 50/50 blend picked without evidence.

PineconeElasticsearchCohere RerankLangChain4 fillable variables

The prompt

Ready to copy — highlighted parts are example details you can swap.

You are tuning a hybrid retrieval system that combines dense vector similarity with sparse/BM25 keyword scoring. Your job is to propose a fusion method and weighting, and justify it against the real failures below, not to recommend "reciprocal rank fusion, weighted evenly" as a default with no diagnosis behind it.

CURRENT RETRIEVAL SETUP
Pinecone dense retrieval (cosine similarity, top 20) run independently from an Elasticsearch BM25 query (top 20), currently merged by taking the top 10 from each with no deduplication

QUERY FAILURES OBSERVED
Query 'error code E4021' returns zero relevant results from dense retrieval despite the code appearing verbatim in three chunks; query 'how do I cancel a subscription' misses a chunk titled 'Ending your plan' that never uses the word cancel

RERANKING STAGE AVAILABLE
Cohere Rerank 3.5 available, currently unused, budget for one reranking call per query on up to 40 candidates

TOP-K AND LATENCY BUDGET
p95 retrieval latency budget of 400ms total, currently at 180ms for the two independent calls

FUSION METHODS TO WEIGH
1. Weighted linear combination of normalized dense + sparse scores — simple, but normalization across two different score distributions is the actual hard part, not the weight itself.
2. Reciprocal Rank Fusion (RRF) — rank-based, avoids the normalization problem entirely, but discards score magnitude, so it can't distinguish a near-perfect match from a mediocre one at the same rank.
3. Sparse as a pre-filter, dense for final ranking (or vice versa) — cheaper, but only correct if one signal is reliably a superset of the other's relevant results, which needs evidence, not an assumption.

DECISION RULES
- For each failure in the observed failures, classify it: did dense retrieval miss an exact keyword, code, or identifier match that sparse would have caught, or did sparse miss a paraphrase or synonym match that dense would have caught? The weighting decision must be justified against which failure type dominates, not a generic "combine both to be safe."
- If a reranker is available, state explicitly whether the fusion stage's job is now just cheap high-recall candidate generation, in which case fusion can lean permissive with a wider top-k and less precise weighting, versus fusion being the final ranking, in which case weighting precision matters far more since there's no second stage to correct it.
- State the actual score ranges each signal produces on 3-5 real queries from the observed failures, and show what a naive average would have done wrong before proposing the fix.
- Respect the stated latency budget — a fusion method that requires calling both retrievers at k=100 and then reranking is only viable if the budget allows two round trips plus a reranking pass.

OUTPUT FORMAT
1. Chosen fusion method with concrete parameters (RRF constant, or linear weights, or filter threshold).
2. For each observed failure, a one-line prediction of whether the new method fixes it, with the reasoning.
3. The one failure type this fix does NOT address, stated honestly, and what would be needed to fix that one too.

Customize

Optional — swap in your own details for the highlighted parts above.

Why this works

Classifying failures — separating 'dense missed an exact match' from 'sparse missed a paraphrase' — turns tuning from guesswork into a diagnosis, because the two failure types have opposite fixes. Dense embeddings systematically underweight exact tokens like error codes, SKUs, and product identifiers: an embedding model is optimized to place semantically similar text nearby, and a code like 'E4021' carries almost no semantic content the model can hook into, so it gets embedded closer to other short alphanumeric strings than to the paragraph that actually explains it. That's a structural property of how these models are trained, not noise that averages out with more data, which is why retrying dense-only never fixes it and a keyword signal reliably does. Treating the presence of a reranker as changing what the fusion stage is even for is the second real lever here. Without a reranker, the fusion weighting is the final relevance decision a user will see, so getting it wrong is directly visible in bad top results. With a cross-encoder reranker sitting downstream, fusion's only job is making sure the right chunk is somewhere in the candidate set the reranker gets to see — which means fusion can be tuned for recall and let the reranker, which actually reads query and chunk together instead of comparing precomputed vectors, make the precision call. Conflating these two modes is why teams sometimes spend real tuning effort perfecting fusion weights a downstream reranker was going to overturn anyway. Requiring actual score ranges from real queries before touching the weights matters because dense cosine similarity and BM25 scores are not on comparable scales — cosine similarity clusters tightly between roughly 0.7 and 0.95 for anything remotely relevant, while raw BM25 scores are unbounded and vary with document length and term rarity. A naive 50/50 average of these two raw numbers doesn't produce a 50/50 blend of influence; it typically lets whichever score has the larger numeric range dominate the sum almost completely, which is a silent bug that only shows up as 'weird' results, never as an error.

What you get back

E4021 query: dense score for the correct chunk was 0.71 (barely above the relevance threshold), BM25 score was 18.4 (a strong exact-term hit) — a naive average with unnormalized scores lets BM25's larger raw magnitude dominate by accident, which happens to fix this case for the wrong reason. Recommendation: RRF with k=60, since it sidesteps the normalization problem entirely and the reranker (Cohere Rerank 3.5) is available to handle final precision on a k=40 candidate set.

Verified against

Pinecone hybrid search API, 2026.06 · 2026-07-24

Cohere Rerank rerank-v3.5 · 2026-07-24

Changelog

  • 2026-07-24 Initial publish, verified against Pinecone hybrid search and Cohere Rerank 3.5.

Building this for real?

This is a free starting point. If you'd rather have AI agents & automation built and running for your business, that's Scult's day job.

EXPLORE AI AGENTS & AUTOMATION
Design a chunking strategy before you write a single line of ingestion codeA decision prompt that forces you to pick chunk size, overlap, and splitting method based on the actual document structure and query patterns in front of you, instead of defaulting to a generic 512-token window because it's the number every tutorial uses.LangChainLlamaIndex2026-07-22Build an automated eval harness for your RAG pipeline instead of eyeballing answersA prompt for designing a repeatable retrieval and generation evaluation suite — precision/recall@k, faithfulness, answer relevance, latency — with numeric regression thresholds, so a chunking or prompt change gets blocked automatically instead of shipping on a good-looking spot check.RAGASLangfuse2026-07-29Build a text-to-SQL agent that can't accidentally write to your databaseAn agent prompt for natural-language database querying with hard read-only guardrails, an EXPLAIN-before-execute validation step, and an explicit refusal path for ambiguous metrics instead of silently picking one interpretation and returning a confident number.Claude (tool use)GPT-5.12026-07-30Design a planner-executor split so one agent doesn't do everything badlyA system-design prompt for architecting a multi-agent system before any orchestration code exists — choosing between hierarchical, sequential, and peer-negotiation patterns, and defining a named handoff schema at every boundary instead of letting agents pass free-form context between each other.LangGraphCrewAI2026-07-27
All AI Agents & RAG prompts

Check your AI visibility

One URL in, a 0–100 score and the exact fixes out.

RUN THE CHECK

Browse all the tools

15 tools across six categories
13 of them never send your data anywhere

Free · No signup · No trial clock

SEE THE DIRECTORY