Thanks to visit codestin.com
Credit goes to github.com

Skip to content

NOISSUE - Guard chat against weak retrieval context#254

Merged
fbugarski merged 1 commit into
mainfrom
prompt-weak-context-guard
Jun 5, 2026
Merged

NOISSUE - Guard chat against weak retrieval context#254
fbugarski merged 1 commit into
mainfrom
prompt-weak-context-guard

Conversation

@fbugarski

Copy link
Copy Markdown
Contributor

What type of PR is this?

This is a bug fix because it prevents chat responses from being generated from empty or weak retrieval context.

What does this do?

This PR improves grounded chat behavior when retrieval returns no useful context.

Previously, if retrieval returned no chunks or returned unrelated chunks, the chat service could still call the LLM. That allowed the model to produce weak or misleading
answers from irrelevant records.

With this change:

  • chat skips the LLM call when retrieval finds no chunks
  • chat skips the LLM call when retrieved chunks do not appear lexically relevant to the user query
  • weak chunks are filtered out before building the RAG prompt
  • only grounded chunks are sent to the LLM
  • users receive a clear fallback message when indexed records do not contain relevant information
  • debug/citation behavior remains available for inspecting retrieval results

Which issue(s) does this PR fix/relate to?

N/A

Have you included tests for your changes?

Yes, I have included tests for this change.

The tests cover:

  • skipping the LLM call when retrieval returns no chunks
  • skipping the LLM call when retrieved chunks are weak/unrelated
  • filtering weak chunks before building the LLM prompt
  • lexical grounding through record names or chunk content

Verified with:

  • go test ./internal/embedder/service
  • go test ./internal/embedder/...

Did you document any new/modified features?

No, this is an internal chat retrieval behavior fix and does not add a new user-facing feature.

Notes

Manually verified that unrelated questions now return a no-relevant-information response, while relevant queries such as record/person name lookups only pass matching
chunks to the model.

@fbugarski fbugarski merged commit 204d9ab into main Jun 5, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant