Symptom
When a customer asks "Is the UltraBoost 5 waterproof?", the knowledge retriever returns "Gift Card Terms" and "Return Policy Overview" instead of the relevant product articles. The AI agent confidently answers with completely wrong information.
What you know
The knowledge retriever embeds the customer's query, searches a vector database, and filters results by a similarity threshold. The scoring system uses cosine distance where:
0.0= identical (most relevant)1.0= completely unrelated (least relevant)
The threshold is 0.35 — articles with a distance below this threshold should be kept (they are similar enough to be relevant).
But the results are backwards: relevant articles are discarded and irrelevant ones are returned.
Pipeline Flow
Customer Message → ... → Knowledge Retriever → Response Generator
↑
Embeds query, searches vector DB,
filters by similarity threshold (0.35)
Log excerpt
[knowledge] Vector search results (pre-filter):
- "UltraBoost 5 Product Specs" score: 0.05 (very relevant)
- "Shoe Care & Waterproofing" score: 0.11 (relevant)
- "Gift Card Terms" score: 0.85 (irrelevant)
- "Return Policy Overview" score: 0.92 (irrelevant)
threshold: 0.35
score_description: "cosine distance: 0.0 = identical, 1.0 = unrelated"
[knowledge] Vector search results (post-filter):
- "Gift Card Terms" score: 0.85
- "Return Policy Overview" score: 0.92
Hints
TypeScript
TypeScript ready
Test Output
▶
Click "Run Tests" to execute your code