mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-16 06:03:26 -05:00
[PR #13378] [CLOSED] feat(api): Expose Retrieved RAG Chunks and Sources in Chat Completion API Response #23173
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/13378
Author: @LosaLosSantos
Created: 5/1/2025
Status: ❌ Closed
Base:
main← Head:feature/retrieving_RAG_context_via_api📝 Commits (1)
03f280ffeat(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.