feat: Public API for Knowledge Base and Support for Contextual Retrieval (Anthropic Approach) #5186

Closed
opened 2025-11-11 16:13:57 -06:00 by GiteaMirror · 0 comments
Owner

Originally created by @Soliver84 on GitHub (May 15, 2025).

Check Existing Issues

  • I have searched the existing issues and discussions.

Problem Description

Current large language models (LLMs) like ChatGPT often fail to provide accurate answers when it comes to specific or proprietary knowledge, mainly because the right training data is missing. The best solution for this is the Retrieval Augmented Generation (RAG) strategy, where documents are split into chunks, embedded, and stored in a vector database. However, a major problem occurs during the chunking process: if documents are split blindly into fixed-size chunks, important context is often lost. Even with chunk overlap, some chunks lack the necessary background information, leading to incomplete or irrelevant answers-especially with complex data like tables or financial reports.

Anthropic’s “Contextual Retrieval” approach addresses this issue by enriching each chunk with additional context from the original document. Their research shows this can reduce error rates by up to 49%. Without support for this contextual enrichment and without a public API to automate knowledge ingestion, it is currently impossible to build robust, scalable, and automated knowledge workflows with OpenWebUI and tools like n8n.

Desired Solution you'd like

Desired Solution you'd like
A public, documented CRUD API for the OpenWebUI Knowledge Base (e.g., /api/knowledge with POST/GET/PUT/DELETE), so external tools and automation platforms (like n8n) can programmatically add, update, and manage knowledge entries.

Support for Contextual Retrieval as described by Anthropic: Allow the enrichment of each chunk with relevant context from the entire document at import time, ideally via a prompt to a language model that adds the necessary background so every chunk is understandable and discoverable on its own.

Optional: Features like prompt caching for cost efficiency and support for external vector databases.

Alternatives Considered

Alternatives Considered
Manual entry via the web interface: Not scalable and cannot keep up with the pace of business data changes.

Direct database access (e.g., SQLite): Risky, not officially supported, and prone to breaking with updates.

Using external RAG frameworks (LangChain, LlamaIndex) with their own vector databases: Possible, but then OpenWebUI cannot act as the central knowledge hub, and seamless integration with its interface and features is lost.

Additional Context

Additional Context
Anthropic’s research (Contextual Retrieval, May 2024) demonstrates that enriching each chunk with document context can nearly halve the error rate of RAG systems. This is especially important for business use cases involving complex documents, tables, and proprietary data.
A public API and contextual retrieval support would make OpenWebUI much more attractive for enterprise and developer adoption, enabling robust, automated, and future-proof knowledge workflows.

Thank you for considering this feature!

Video:
https://www.youtube.com/watch?v=h4rm_z3eVrk&list=PL0Lo-Ohv62WWyGOtIl2xDY5C-hBliFnNo&index=54

Atatcht the N8N Workflow
N8N_43 Contextual_Retrieval_RAG.zip

N8N_43 Contextual_Retrieval_RAG.json

Originally created by @Soliver84 on GitHub (May 15, 2025). ### Check Existing Issues - [x] I have searched the existing issues and discussions. ### Problem Description Current large language models (LLMs) like ChatGPT often fail to provide accurate answers when it comes to specific or proprietary knowledge, mainly because the right training data is missing. The best solution for this is the Retrieval Augmented Generation (RAG) strategy, where documents are split into chunks, embedded, and stored in a vector database. However, a major problem occurs during the chunking process: if documents are split blindly into fixed-size chunks, important context is often lost. Even with chunk overlap, some chunks lack the necessary background information, leading to incomplete or irrelevant answers-especially with complex data like tables or financial reports. Anthropic’s “Contextual Retrieval” approach addresses this issue by enriching each chunk with additional context from the original document. Their research shows this can reduce error rates by up to 49%. Without support for this contextual enrichment and without a public API to automate knowledge ingestion, it is currently impossible to build robust, scalable, and automated knowledge workflows with OpenWebUI and tools like n8n. ### Desired Solution you'd like Desired Solution you'd like A public, documented CRUD API for the OpenWebUI Knowledge Base (e.g., /api/knowledge with POST/GET/PUT/DELETE), so external tools and automation platforms (like n8n) can programmatically add, update, and manage knowledge entries. Support for Contextual Retrieval as described by Anthropic: Allow the enrichment of each chunk with relevant context from the entire document at import time, ideally via a prompt to a language model that adds the necessary background so every chunk is understandable and discoverable on its own. Optional: Features like prompt caching for cost efficiency and support for external vector databases. ### Alternatives Considered Alternatives Considered Manual entry via the web interface: Not scalable and cannot keep up with the pace of business data changes. Direct database access (e.g., SQLite): Risky, not officially supported, and prone to breaking with updates. Using external RAG frameworks (LangChain, LlamaIndex) with their own vector databases: Possible, but then OpenWebUI cannot act as the central knowledge hub, and seamless integration with its interface and features is lost. ### Additional Context Additional Context Anthropic’s research ([Contextual Retrieval, May 2024](https://www.anthropic.com/news/contextual-retrieval)) demonstrates that enriching each chunk with document context can nearly halve the error rate of RAG systems. This is especially important for business use cases involving complex documents, tables, and proprietary data. A public API and contextual retrieval support would make OpenWebUI much more attractive for enterprise and developer adoption, enabling robust, automated, and future-proof knowledge workflows. Thank you for considering this feature! Video: https://www.youtube.com/watch?v=h4rm_z3eVrk&list=PL0Lo-Ohv62WWyGOtIl2xDY5C-hBliFnNo&index=54 Atatcht the N8N Workflow [N8N_43 Contextual_Retrieval_RAG.zip](https://github.com/user-attachments/files/20228085/N8N_43.Contextual_Retrieval_RAG.zip) [N8N_43 Contextual_Retrieval_RAG.json](https://github.com/user-attachments/files/20228090/N8N_43.Contextual_Retrieval_RAG.json)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#5186