When nothing matches

Take your time, follow the code and check your understanding.

The codeRAG fundamentals
const hits = search(question, 3);
const prompt = `Context:\n${hits.join("\n")}\n\nQuestion: ${question}`;
// search always returns 3 chunks, even for unrelated questions.
Your answer4 min · no timer
What needs fixing?

Show solution and explanation

Returning the least-bad chunks encourages the model to answer from irrelevant text. A relevance threshold and an explicit "not found" path make answers more honest.

Add a minimum score. If nothing passes it, say the documents do not cover the question instead of forcing weak context.