[PR #13378] [CLOSED] feat(api): Expose Retrieved RAG Chunks and Sources in Chat Completion API Response #23173

Closed
opened 2026-04-20 04:40:51 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/13378
Author: @LosaLosSantos
Created: 5/1/2025
Status: Closed

Base: mainHead: feature/retrieving_RAG_context_via_api


📝 Commits (1)

  • 03f280f feat(api): expose RAG context and sources in /api/chat/completions response

📊 Changes

2 files changed (+12 additions, -2 deletions)

View changed files

📝 backend/open_webui/main.py (+4 -1)
📝 backend/open_webui/utils/middleware.py (+8 -1)

📄 Description

Feature: Expose RAG Context and Sources via /api/chat/completions

This PR introduces support for exposing the context and source chunks used in the RAG (Retrieval-Augmented Generation) process through the existing /api/chat/completions endpoint.

🔍 Motivation:

Currently, the RAG context used during the generation is not exposed, which limits:
Debugging and validation of the chunks retrieved by the retriever.
Monitoring of relevance and document retrieval performance.
I previously opened a discussion on this topic: #13304

🛠 Implementation:

This PR adds the following fields to the API response:
context_chunks_with_source: a list of the retrieved chunks and the corresponding file names used during the RAG step.
This makes it possible to externally inspect and evaluate the retrieval process without modifying the backend logic.


🔄 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/13378 **Author:** [@LosaLosSantos](https://github.com/LosaLosSantos) **Created:** 5/1/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feature/retrieving_RAG_context_via_api` --- ### 📝 Commits (1) - [`03f280f`](https://github.com/open-webui/open-webui/commit/03f280f8fe822a6c30f7b606a2c737c4052c73ae) feat(api): expose RAG context and sources in /api/chat/completions response ### 📊 Changes **2 files changed** (+12 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/main.py` (+4 -1) 📝 `backend/open_webui/utils/middleware.py` (+8 -1) </details> ### 📄 Description **Feature: Expose RAG Context and Sources via /api/chat/completions** This PR introduces support for exposing the context and source chunks used in the RAG (Retrieval-Augmented Generation) process through the existing /api/chat/completions endpoint. 🔍 **Motivation:** Currently, the RAG context used during the generation is not exposed, which limits: Debugging and validation of the chunks retrieved by the retriever. Monitoring of relevance and document retrieval performance. I previously opened a discussion on this topic: [#13304](https://github.com/open-webui/open-webui/discussions/13304) 🛠 **Implementation:** This PR adds the following fields to the API response: context_chunks_with_source: a list of the retrieved chunks and the corresponding file names used during the RAG step. This makes it possible to externally inspect and evaluate the retrieval process without modifying the backend logic. --- <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-04-20 04:40:51 -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#23173