Fix: streaming response reference mismatch with answer#13835
Open
Lntanohuang wants to merge 2 commits intoinfiniflow:mainfrom
Open
Fix: streaming response reference mismatch with answer#13835Lntanohuang wants to merge 2 commits intoinfiniflow:mainfrom
Lntanohuang wants to merge 2 commits intoinfiniflow:mainfrom
Conversation
…ence In streaming mode, the final SSE event contains the correctly filtered reference (from decorate_answer) but the answer field was blanked to "". This caused a mismatch: the client accumulated raw answer text (without citation markers) while the reference was filtered based on citation analysis of the decorated answer. Chat history was unaffected because conv.reference was correctly persisted from the final event. By keeping the decorated answer in the final event, clients can replace accumulated text with the citation-processed answer that matches the reference, consistent with the non-streaming code path. Closes infiniflow#13828 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…enError
When searching words like "cat", synonym expansion produces phrases such as
"big cat" and "computerized tomography". These are embedded in a single-quoted
SQL string for filter_fulltext(), but any single quote in the matching text
breaks sqlglot's tokenizer. Escape single quotes using the standard SQL
convention (' -> '') before interpolation.
Closes infiniflow#13823
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4 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
Fixes #13828 — streaming response references are mismatched with the answer, while chat history references are correct.
Root Cause
In
async_chat()(api/db/services/dialog_service.py), the streaming code path:reference: {}(empty) — expected, since references are computed after the full answer is available.decorate_answer()which:##N$$) into the answer textdoc_aggsbased on which chunks were actually citedfinal["answer"] = ""), discarding the citation-processed text while keeping the citation-filtered references.This means the client accumulates raw answer text (no citation markers) from delta events, but receives references filtered based on citation analysis it never sees — causing the mismatch reported in the issue.
Chat history is unaffected because
structure_answer()correctly persistsconv.reference[-1]from the final event's reference data.Fix
Remove
final["answer"] = ""so the final SSE event includes the full decorated answer (with citation markers) alongside its matching references. This is consistent with the non-streaming code path behavior.Behavior Change
Previously, the final streaming SSE event had
answer: "". After this fix, it contains the complete citation-processed answer. Clients that accumulate delta text should use the final event's answer as the authoritative text (replacing accumulated deltas), which is the same pattern used in the non-streaming response.Test plan
POST /api/v1/chats/{chat_id}/completionswithstream=trueand citation enabledstream=false) behavior is unchanged🤖 Generated with Claude Code