[PR #2011] [MERGED] feat: show RAG query results as citations #124518

Closed
opened 2026-05-21 04:33:03 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/2011
Author: @cheahjs
Created: 5/6/2024
Status: Merged
Merged: 5/6/2024
Merged by: @tjbck

Base: devHead: feat/rag-citations


📝 Commits (10+)

📊 Changes

35 files changed (+772 additions, -488 deletions)

View changed files

📝 backend/apps/rag/utils.py (+27 -22)
📝 backend/config.py (+12 -10)
📝 backend/main.py (+36 -3)
📝 src/lib/apis/streaming/index.ts (+11 -0)
src/lib/components/chat/Messages/CitationsModal.svelte (+75 -0)
📝 src/lib/components/chat/Messages/ResponseMessage.svelte (+473 -420)
📝 src/lib/i18n/locales/ar-BH/translation.json (+4 -1)
📝 src/lib/i18n/locales/bg-BG/translation.json (+4 -1)
📝 src/lib/i18n/locales/bn-BD/translation.json (+4 -1)
📝 src/lib/i18n/locales/ca-ES/translation.json (+4 -1)
📝 src/lib/i18n/locales/de-DE/translation.json (+4 -1)
📝 src/lib/i18n/locales/dg-DG/translation.json (+4 -1)
📝 src/lib/i18n/locales/en-GB/translation.json (+4 -1)
📝 src/lib/i18n/locales/en-US/translation.json (+4 -1)
📝 src/lib/i18n/locales/es-ES/translation.json (+4 -1)
📝 src/lib/i18n/locales/fa-IR/translation.json (+4 -1)
📝 src/lib/i18n/locales/fr-CA/translation.json (+4 -1)
📝 src/lib/i18n/locales/fr-FR/translation.json (+4 -1)
📝 src/lib/i18n/locales/it-IT/translation.json (+4 -1)
📝 src/lib/i18n/locales/ja-JP/translation.json (+4 -1)

...and 15 more files

📄 Description

Pull Request Checklist

  • Description: Briefly describe the changes in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
  • Testing: Have you written and run sufficient tests for the changes?
  • Code Review: Have you self-reviewed your code and addressed any coding standard issues?

Description

Return RAG query results as citations to show to the user. This is done by injecting a new event/object into the streaming responses in the RAG middleware, and handling this on the frontend. To avoid breaking external clients, this is an opt-in behaviour with citations: true.

Some open questions:

  1. Right now the file loaders use the full file path as the source for metadata, do we want to sanitize this before returning it?
  2. Web loader has more metadata such as a title and description, do we want to use any of these bits of metadata?
  3. This is currently not working correctly with collections, as a collection can return multiple documents with different sources in a single query. Code was updated to group by source instead of grouping by collections.

image
image


Changelog Entry

Added

  • 📚 Citations for RAG Responses: Get source information for responses generated using Retrieval Augmented Generation (RAG). This helps you understand the context and origin of the information provided.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/2011 **Author:** [@cheahjs](https://github.com/cheahjs) **Created:** 5/6/2024 **Status:** ✅ Merged **Merged:** 5/6/2024 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `feat/rag-citations` --- ### 📝 Commits (10+) - [`0872bea`](https://github.com/open-webui/open-webui/commit/0872bea790d5582a8cff68ce5865e776009bf1fc) feat: show RAG query results as citations - [`2571f3c`](https://github.com/open-webui/open-webui/commit/2571f3c43b1760a7860f73c210986e618d000630) fix: remove stray debug logs - [`c3425f3`](https://github.com/open-webui/open-webui/commit/c3425f3bf1cfb084c74c71c7cecd698ab792f0ae) fix: update translation files - [`4c6567c`](https://github.com/open-webui/open-webui/commit/4c6567c46fcaf3ac4c6ea33c143820c8d8389e55) feat: group citations by source - [`e70cdf1`](https://github.com/open-webui/open-webui/commit/e70cdf118bb7fc8be9a0b48e03bf09a7dcea07b4) refac: styling - [`38590da`](https://github.com/open-webui/open-webui/commit/38590da0b1eceb8665ed65716764c38609165958) fix: styling - [`4c49013`](https://github.com/open-webui/open-webui/commit/4c490132ba77e78433d3b7b2474b69b07bf60eb8) refac: styling - [`64ed0d1`](https://github.com/open-webui/open-webui/commit/64ed0d10897695c4753cd3e77dd7f7cbba2da3e5) refac: include source name to citation - [`aef2a51`](https://github.com/open-webui/open-webui/commit/aef2a514d15f78921932621398097c1d2fd3f8bf) refac: citation rendering - [`c84e0aa`](https://github.com/open-webui/open-webui/commit/c84e0aa2a3606b8c0ba224f0936ee40bbed5a171) fix: .env load ### 📊 Changes **35 files changed** (+772 additions, -488 deletions) <details> <summary>View changed files</summary> 📝 `backend/apps/rag/utils.py` (+27 -22) 📝 `backend/config.py` (+12 -10) 📝 `backend/main.py` (+36 -3) 📝 `src/lib/apis/streaming/index.ts` (+11 -0) ➕ `src/lib/components/chat/Messages/CitationsModal.svelte` (+75 -0) 📝 `src/lib/components/chat/Messages/ResponseMessage.svelte` (+473 -420) 📝 `src/lib/i18n/locales/ar-BH/translation.json` (+4 -1) 📝 `src/lib/i18n/locales/bg-BG/translation.json` (+4 -1) 📝 `src/lib/i18n/locales/bn-BD/translation.json` (+4 -1) 📝 `src/lib/i18n/locales/ca-ES/translation.json` (+4 -1) 📝 `src/lib/i18n/locales/de-DE/translation.json` (+4 -1) 📝 `src/lib/i18n/locales/dg-DG/translation.json` (+4 -1) 📝 `src/lib/i18n/locales/en-GB/translation.json` (+4 -1) 📝 `src/lib/i18n/locales/en-US/translation.json` (+4 -1) 📝 `src/lib/i18n/locales/es-ES/translation.json` (+4 -1) 📝 `src/lib/i18n/locales/fa-IR/translation.json` (+4 -1) 📝 `src/lib/i18n/locales/fr-CA/translation.json` (+4 -1) 📝 `src/lib/i18n/locales/fr-FR/translation.json` (+4 -1) 📝 `src/lib/i18n/locales/it-IT/translation.json` (+4 -1) 📝 `src/lib/i18n/locales/ja-JP/translation.json` (+4 -1) _...and 15 more files_ </details> ### 📄 Description ## Pull Request Checklist - [x] **Description:** Briefly describe the changes in this pull request. - [ ] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [ ] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources? - [ ] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? - [x] **Testing:** Have you written and run sufficient tests for the changes? - [ ] **Code Review:** Have you self-reviewed your code and addressed any coding standard issues? --- ## Description Return RAG query results as citations to show to the user. This is done by injecting a new event/object into the streaming responses in the RAG middleware, and handling this on the frontend. To avoid breaking external clients, this is an opt-in behaviour with `citations: true`. Some open questions: 1. Right now the file loaders use the full file path as the source for metadata, do we want to sanitize this before returning it? 2. Web loader has more metadata such as a title and description, do we want to use any of these bits of metadata? 3. ~~This is currently not working correctly with collections, as a collection can return multiple documents with different sources in a single query.~~ Code was updated to group by source instead of grouping by collections. ![image](https://github.com/open-webui/open-webui/assets/818368/8fd1a59a-273f-4af1-be44-4fdbf29104a9) ![image](https://github.com/open-webui/open-webui/assets/818368/cb308578-9600-4f31-95a3-ddcd6d16de9b) --- ### Changelog Entry ### Added - **📚 Citations for RAG Responses**: Get source information for responses generated using Retrieval Augmented Generation (RAG). This helps you understand the context and origin of the information provided. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-21 04:33:03 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#124518