Prompt Details
Model
(claude-5-sonnet)
Token size
3,822
Example input
[SYMPTOMS]: Our storefront assistant often returns broad help-center articles instead of the exact policy paragraph or product specification. Exact product codes sometimes find a nearby model, while paraphrased policy questions retrieve unrelated warranty pages. Increasing the result count occasionally reveals the correct article near the bottom, but not for policy-synonym queries.
[EMBEDDING_MODEL]: text-embedding-3-small
[QUERY_EXAMPLES]: “Can I return an opened blender after three weeks?” → Expected: Returns policy paragraph stating the conditions for opened appliances within the allowed window / Got: Manufacturer warranty overview with no store-return conditions “XR-410 replacement battery compatibility” → Expected: XR-410 accessory compatibility table / Got: XR-400 product page; the XR-410 table appears only when more results are requested “Is splash resistant the same as waterproof for the TrailWatch?” → Expected: TrailWatch water-exposure limitations / Got: Lifestyle marketing article about outdoor use
Example output
### BLOCK 0: INPUT STATUS
Mode: ⟪FULL INPUT⟫
All required fields are present. The supplied traces do not include retrieved chunk IDs, scores by rank, corpus contents, or ranked relevance judgments. Exact candidate-set membership and retrieval metrics are therefore **NOT_MEASURED**.
### BLOCK 1: FAILURE CLASSIFICATION
Primary pattern: ⟪Mixed⟫
| Example | Coverage? | Pool or Ordering? | Basis |
|---|---|---|---|
| Opened blender return | Plausibly absent from the initial candidate pool because the result shifts to warranty content | Pool failure or coverage gap | ESTIMATED |
| XR-410 battery | Yes; the expected table appears when more results are requested | Ordering failure | COMPUTED from the supplied trace |
| TrailWatch water exposure | Unclear; the wording may not bridge “splash resistant” and “waterproof” | Pool failure or coverage gap | ESTIMATED |
Severity: ⟪High⟫ — **ESTIMATED**. The failure affects both policy conditions and product-specific facts, and the supplied cases point to more than one retrieval stage.
### BLOCK 2: ROOT CAUSES
1. Weak exact-identifier handling — explains **1/3 supplied examples — COMPUTED** — add sparse retrieval or an identifier-preserving field boost for model codes.
2. Vocabulary mismatch between user language and indexed policy/specification language — explains **2/3 supplied examples — ESTIMATED** — add query expansion and verify that the relevant paragraphs are independently retrievable.
3. Broad pages competing with narrow answer-bearing chunks — explains **2/3 supplied examples — ESTIMATED** — re-chunk around policy clauses and specification rows, then rerank only after candidate coverage is confirmed.
### BLOCK 3: EMBEDDING DIAGNOSIS
Model: text-embedding-3-small (dimension configuration **NOT_MEASURED** from the supplied setup)
Strengths: a general-purpose semantic embedding model suited to similarity search and capable of bridging many paraphrases.
Weaknesses relevant here: dense similarity alone is not designed to guarantee exact SKU matching, and embeddings cannot retrieve content that was omitted or split into a non-answer-bearing chunk.
Recommendation: ⟪PROJECTED⟫ Retain the current dense model during the first repair cycle and add exact-term retrieval plus chunk inspection. This isolates whether the failures come from candidate coverage before a model migration introduces another variable.
### BLOCK 4: POOL vs. ORDERING FIX MAP
The return-policy and water-exposure cases require a coverage-side test: confirm that a self-contained answer chunk exists, then add synonym-aware query expansion or sparse retrieval. A reranker cannot rescue a missing candidate.
The XR-410 case requires a ranking-side fix because the expected table is already reachable at a deeper result depth. Identifier-aware sparse scoring and fusion should precede an optional reranker.
### BLOCK 5: RETRIEVAL ARCHITECTURE
Recommended: ⟪Hybrid+Reranker⟫
Components, staged:
- Clause- and table-aware chunks with product code and document-type metadata.
- Dense retrieval for paraphrased intent.
- Sparse retrieval for SKUs, policy terms, and exact attributes.
- Reciprocal-rank fusion to create a shared candidate pool.
- Lightweight reranking for the fused pool, with product-code mismatch penalties.
Performance Expectations:
- ⟪PROJECTED⟫ Higher candidate coverage for exact product codes because sparse matching preserves tokens that dense similarity may blur.
- ⟪PROJECTED⟫ Better ordering of narrow policy/specification chunks because reranking evaluates the query against chunk text after coverage is established.
- ⟪PROJECTED⟫ No guaranteed improvement for missing or badly split source content; those cases require corpus repair.
### BLOCK 6: PRODUCTION CODE
The following runnable standard-library harness demonstrates the recommended fusion and identifier guard. Replace `dense_rank` with the existing retriever adapter in production.
```python
import math
import re
from collections import Counter
DOCS = {
"returns_opened": "Opened appliances may be returned when the store return conditions are met.",
"xr410_battery": "XR-410 replacement battery compatibility table and approved accessories.",
"xr400_page": "XR-400 blender product overview and accessories.",
"trailwatch_limits": "TrailWatch is splash resistant; it is not rated for submersion or swimming.",
}
def tokens(text):
if not isinstance(text, str) or not text.strip():
raise ValueError("query must be a non-empty string")
return re.findall(r"[a-z0-9-]+", text.lower())
def sparse_rank(query):
q = Counter(tokens(query))
scored = []
for doc_id, text in DOCS.items():
d = Counter(tokens(text))
overlap = sum(q[t] * d[t] for t in q)
norm = math.sqrt(sum(v * v for v in d.values())) or 1.0
scored.append((doc_id, overlap / norm))
return [doc_id for doc_id, _ in sorted(scored, key=lambda x: x[1], reverse=True)]
def dense_rank(query):
# POOL adapter: replace with the buyer's current vector search results.
return sparse_rank(query)
def rrf(*rankings, offset=60):
scores = Counter()
for ranking in rankings:
for rank, doc_id in enumerate(ranking, start=1):
scores[doc_id] += 1.0 / (offset + rank)
return [doc_id for doc_id, _ in scores.most_common()]
def identifiers(text):
return set(re.findall(r"\b[A-Z]{2,}-\d+\b", text.upper()))
def rerank(query, candidates):
required = identifiers(query)
def score(doc_id):
present = identifiers(DOCS[doc_id])
exact_bonus = 1 if required and required <= present else 0
mismatch = -1 if required and present and not required <= present else 0
return exact_bonus + mismatch
return sorted(candidates, key=score, reverse=True)
def retrieve(query):
fused = rrf(dense_rank(query), sparse_rank(query))
return rerank(query, fused)
if __name__ == "__main__":
try:
for q in [
"Can I return an opened blender after three weeks?",
"XR-410 replacement battery compatibility",
"Is splash resistant the same as waterproof for the TrailWatch?",
]:
print(q, "=>", retrieve(q)[:3])
except (TypeError, ValueError) as exc:
raise SystemExit(f"Invalid retrieval input: {exc}") from exc
```
### BLOCK 7: REPAIR DEMONSTRATION
| Buyer query | Before | Repair path | Expected change |
|---|---|---|---|
| Opened blender after three weeks | Warranty overview | Retrieve return-policy clauses through sparse+dense fusion | ⟪PROJECTED⟫ The relevant policy chunk is more likely to enter the candidate pool because return conditions are indexed separately from warranties. |
| XR-410 battery compatibility | XR-400 page | Preserve the exact identifier and penalize mismatched identifiers | ⟪PROJECTED⟫ The XR-410 table should outrank the nearby XR-400 page when both are candidates. |
| Splash resistant vs waterproof | Outdoor lifestyle article | Expand the relation between resistance terms and retrieve the limitations chunk | ⟪PROJECTED⟫ The answer-bearing limitations text is more likely to replace marketing content. |
Ranked relevance judgments were not supplied; NDCG and related ranked metrics are omitted.
By purchasing this prompt, you agree to our terms of service
CLAUDE-5-SONNET
Diagnose why a RAG retriever misses the right evidence before changing models or adding a reranker. This prompt separates coverage, candidate-pool, and ordering failures; ranks root causes from supplied query traces; recommends a matching architecture; and produces runnable repair code plus a before/after demonstration without fabricated metrics.
...more
Added 4 days ago
