Skip to content

fix(rag): keep sources when the LLM omits the citation tag - #847

Open
Ahmath-Gadji wants to merge 3 commits into
developfrom
fix/uncited-sources-fallback
Open

fix(rag): keep sources when the LLM omits the citation tag#847
Ahmath-Gadji wants to merge 3 commits into
developfrom
fix/uncited-sources-fallback

Conversation

@Ahmath-Gadji

@Ahmath-Gadji Ahmath-Gadji commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Why

Sources are not cited in a lot of messages: PR #807 changed the fallback so a missing [Sources: ...] tag hides all sources instead of keeping them. In practice the model often skips the tag on answers that are genuinely grounded in retrieved documents, so those sources were being dropped from the response.

Fix

  • filter_sources_by_citations now keeps all retrieved sources when no tag is found, instead of returning none.
  • Added extra.retrieved_sources: always the full, unfiltered retrieval set, alongside the (possibly citation-filtered) extra.sources.

Summary by CodeRabbit

  • Bug Fixes
    • Sources are now retained when responses do not include citation markers.
    • Structured-output responses no longer process citation markers incorrectly.
    • Source handling is now consistent across chat, streaming, conversational, and completion workflows.
    • Responses now distinguish between cited sources and all retrieved sources, preserving the complete retrieval context.

No [Sources: ...] tag means the model didn't report which sources it
used, not that it used none. filter_sources_by_citations now keeps all
retrieved sources in that case instead of hiding them, since answers
were frequently coming back with no cited sources at all.
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Ahmath-Gadji, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 24 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 664219ef-1d52-4109-93ca-4303e921c714

📥 Commits

Reviewing files that changed from the base of the PR and between 7d45146 and f4bd28a.

📒 Files selected for processing (5)
  • CLAUDE.md
  • openrag/core/utils/source_filtering.py
  • openrag/services/orchestrators/query_service.py
  • tests/unit/core/utils/test_source_filtering.py
  • tests/unit/services/orchestrators/test_query_service.py
📝 Walkthrough

Walkthrough

filter_sources_by_citations now retains all sources when citations are absent. Query flows detect structured outputs and skip citation processing. Responses include filtered sources and complete retrieved_sources. Tests cover chat, streaming, and completion paths.

Changes

Citation source handling

Layer / File(s) Summary
Source filtering contract and behavior
openrag/core/utils/source_filtering.py, tests/unit/core/utils/test_source_filtering.py, CLAUDE.md
The filtering APIs remove uncited-source options. Missing citations retain all sources. Stream metadata includes filtered sources and complete retrieved_sources. Documentation describes this behavior.
Structured output and query flows
openrag/services/orchestrators/query_service.py
Chat, streaming chat, and text completion detect JSON-object and JSON-schema response formats. Structured outputs bypass citation processing. Responses include filtered and retrieved sources.
Query service validation
tests/unit/services/orchestrators/test_query_service.py
Tests conditionally provide prepared sources for document or web inputs. No-citation responses retain retrieved sources.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • linagora/openrag#807: Modifies source citation filtering and query-service source attribution behavior.

Suggested labels: bug, fix

Suggested reviewers: enjoybacon7, hedhoud

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: retaining sources when the LLM omits a citation tag.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/uncited-sources-fallback

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added bug Something isn't working fix Fix issue labels Aug 2, 2026
Adds extra.retrieved_sources, carrying every source retrieval produced
regardless of citation filtering, so clients can see what was searched
even when extra.sources ends up narrower than the full retrieval set.
@Ahmath-Gadji Ahmath-Gadji mentioned this pull request Aug 2, 2026
Clearer than retrieved_sources for a field meant for debugging and RAG
evaluation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fix Fix issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant