2.3 KiB
Document-Based Question Answering with OpenWebUI
This document explains how to use the document-based question answering (RAG) functionality in the AI service.
Overview
The AI service now supports Retrieval Augmented Generation (RAG) by leveraging OpenWebUI's built-in knowledge database. This allows users to:
- Upload documents to OpenWebUI
- Ask questions about those documents
- Receive responses that incorporate information from the documents
How It Works
When RAG is enabled:
- The AI service forwards the request to OpenWebUI with
use_knowledge=True - OpenWebUI searches its knowledge database for relevant information
- The retrieved information is used to augment the model's response
- The response is returned to the user
Using RAG in API Requests
To enable RAG in your API requests, set the use_rag parameter to true:
POST /chats/{chat_id}/messages
{
"message": "What information do you have about project X?",
"user_id": "user123",
"use_rag": true
}
Testing RAG Functionality
You can test the RAG functionality using the /test-rag endpoint:
POST /test-rag?query=What information do you have about project X?
This will return a response that includes information from documents in OpenWebUI's knowledge database.
Uploading Documents to OpenWebUI
To use RAG effectively, you need to upload documents to OpenWebUI:
- Log in to OpenWebUI at your configured URL (default: http://104.225.217.215:8080)
- Navigate to the Knowledge section
- Upload your documents (PDF, TXT, DOCX, etc.)
- OpenWebUI will automatically process and index the documents
Troubleshooting
If RAG is not working as expected:
- Ensure OpenWebUI is running and accessible
- Check that documents are properly uploaded and indexed in OpenWebUI
- Verify that the
use_ragparameter is set totruein your requests - Check the logs for any errors related to OpenWebUI API calls
If there are connection issues with OpenWebUI, the AI service will automatically fall back to using the direct Ollama API without RAG.
Configuration
The following configuration settings affect RAG functionality:
OPENWEBUI_URL: URL of your OpenWebUI instanceOPENWEBUI_API_KEY: API key for OpenWebUI (if required)API_TIMEOUT: Timeout for API requests (in seconds)
These can be set in your environment variables or in the .env file.