feat(suggestions): hybrid retrieval-grounded follow-ups behind feature flag#116
Open
yashgoel1331 wants to merge 2 commits into
Open
feat(suggestions): hybrid retrieval-grounded follow-ups behind feature flag#116yashgoel1331 wants to merge 2 commits into
yashgoel1331 wants to merge 2 commits into
Conversation
Introduce retrieval evidence extraction, quality-gated hybrid input, prompt guardrails, observability logs, and updated API/FE documentation behind SUGGESTIONS_HYBRID_ENABLED.
KDwevedi
requested changes
Jul 15, 2026
KDwevedi
left a comment
Collaborator
There was a problem hiding this comment.
Solid on the things that matter most — error isolation is good (task queueing try/except'd in the generator tail, broad except → [] in the task, pending-key cleared in finally), chat latency is untouched (all new stream-path work is after the last yield), and the flag default is off. Branch is 23 commits behind main but test-merges clean. Two things block it as-is:
- Major — the flag doesn't gate all new behavior. Commit 2's system-prompt changes (
assets/prompts/suggestions_system.md: answerability guardrails, language-switch ban, hybrid-input section) and the per-turn shadow-evidence extraction + Redis SET (app/services/chat.py:1084-1109) run unconditionally. WithSUGGESTIONS_HYBRID_ENABLED=false, prod is not the pre-PR conversation-only baseline, so flipping the flag off doesn't restore old behavior and any on/off comparison is confounded. Please gate the prompt delta and the shadow writes behind the same flag. - Major — stale vs the micro-loan feature.
suggestions_system.md:22-24("do not generate questions about bank accounts or non-milk financial transactions") predates the micro-loan flow that merged to main since this branched (4a68746, 8e41557, 8e52db9) — bank/loan questions are now a supported product flow, and this guardrail would suppress follow-ups for it. Needs rebase-time reconciliation with product.
Also worth fixing:
- No turn identifier in the shadow payload (write chat.py:1094, read app/tasks/suggestions.py:149-151): if the generator tail is skipped (client disconnect mid-stream), the background task still runs and can ground suggestions in the previous turn's 10-min-TTL evidence. A per-request nonce passed to the task makes the gate turn-exact.
_extract_query_from_search_header/_extract_snippets_from_search_return(chat.py:180-190) are string-coupled to the exact output formatting of agents/tools/search.py:527,545 — any format change silently yields 0 snippets and permanently degrades hybrid to fallback with no alert. Fail-safe but silent; at least log a counter.- suggestions.py:149-156 does the Redis GET + gate computation before the flag check — check
hybrid_enabledfirst so flag-off costs nothing. - Snippets hard-truncate mid-sentence at 600 chars and drop the document name from evidence; and the hybrid path passes any
target_lang(:172) while the new prompt declares only English/Gujarati supported.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
search_documentsretrieval evidence plus recent conversation context.SUGGESTIONS_HYBRID_ENABLED(defaultfalse) so production stays on conversation-only baseline until explicitly enabled.This PR contains exactly 2 commits cherry-picked onto current
main:02f46a8— suggestions scope guardrail (non-milk transaction limits)4ebd1d6— hybrid suggestions pipeline + feature flag + docsWhat changed
app/services/chat.py): after each chat turn, distill current-turnsearch_documentstool returns into bounded snippets and cache assuggestions_shadow_{session_id}_{target_lang}.app/tasks/suggestions.py): when flag is enabled and retrieval passes deterministic checks, suggestions use last 3 conversation pairs + distilled evidence; otherwise fallback to last 5 pairs (conversation-only).assets/prompts/suggestions_system.md): hybrid input usage rules, answerability constraints, and milk/cooperative scope limits.app/config.py,example.env):SUGGESTIONS_HYBRID_ENABLED.suggestions_task_queued,chat_stream_complete,suggestions_shadow_evidence,suggestions_task_started,suggestions_input_mode,suggestions_cache_written.API_DOC.mdanddocs/CHAT_ENDPOINT_FE_INTEGRATION.mdwith current/api/suggest/behavior and pipeline details.Design notes
Test plan
SUGGESTIONS_HYBRID_ENABLED=false, verifysuggestions_input_mode ... mode=conversation_only retrieval_reason=hybrid_feature_flag_disabled.SUGGESTIONS_HYBRID_ENABLED=trueand a retrieval-heavy ag query, verifymode=hybrid retrieval_reason=ok.conversation_onlywith explicitretrieval_reason./api/suggest/returns JSON string array after generation.Made with Cursor