A Retrieval Augmented Generation (RAG) API that allows users to upload PDF documents and ask questions about their content using natural language. The system uses OpenAI embeddings and Elasticsearch for efficient document retrieval, combined with LLM-powered question answering.
-
PDF Document Processing
- Upload multiple PDF files concurrently
- Automatic text extraction and chunking
- Vector embeddings generation using OpenAI's embedding model
- Efficient storage and indexing in Elasticsearch
-
Question Answering
- Natural language question processing
- Semantic search using vector embeddings
- Context-aware answers using RAG
- Source chunks provided with answers
-
System Health Monitoring
- Elasticsearch cluster health checks
- Index status monitoring
- Real-time system status reporting
- Docker and Docker Compose
- OpenAI API Key
- (Optional) DeepSeek API Key for alternative LLM provider
- Clone the repository:
git clone git@github.com:TulioChiodi/rag_challenge_api.git
cd rag_challenge_api- Create a
.envfile in the project root by copying.env.example:
The project includes three services:
- API Service (FastAPI): Handles document processing and RAG queries
- UI Service (Streamlit): Provides a user-friendly web interface
- Elasticsearch: Stores and indexes document embeddings
- Build and start all services:
docker compose up --build- Access the services:
- Web UI:
http://localhost:8501 - API Documentation:
http://localhost:8000/docs - Elasticsearch:
http://localhost:9200
Once the service is running, you can access:
- Swagger UI documentation:
http://localhost:8000/docs - ReDoc documentation:
http://localhost:8000/redoc
You can interact with the system either through the Web UI or directly via the API:
- Open the Streamlit interface in your browser:
http://0.0.0.0:8501
- Use the intuitive interface to:
- Upload PDF documents using the file upload widget
- View processing status and document information
- Ask questions and see answers with source context
- Monitor system health
- Upload PDF documents:
curl -X POST "http://localhost:8000/documents" \
-H "accept: application/json" \
-H "Content-Type: multipart/form-data" \
-F "files=@manual1.pdf" \
-F "files=@manual2.pdf"- Ask questions about the documents:
curl -X POST "http://localhost:8000/question" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d '{"question": "What are the maintenance procedures?"}'For local development, we'll use a Python virtual environment and run Elasticsearch in Docker:
- Create virtual environment
python -m venv venv- Activate it
source venv/bin/activate- Install project dependencies:
# For API development
pip install -r requirements.txt
# For UI development (Streamlit)
pip install -r ui-requirements.txt- Setup Elasticsearch:
# Pull the image
docker pull elasticsearch:9.0.1
# Run Elasticsearch container
docker run -d \
-p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e "xpack.security.enabled=false" \
-e "ES_JAVA_OPTS=-Xms1g -Xmx1g" \
--name es-dev \
elasticsearch:9.0.1- Run the services:
# Terminal 1: Run the FastAPI application
python -m src.main
# Terminal 2: Run the Streamlit UI
streamlit run streamlit_app/app.pyThe services will be available at:
- API: http://localhost:8000
- UI: http://0.0.0.0:8501
- Elasticsearch: http://localhost:9200
- Prometheus + Grafana
- System metrics collection and visualization
- Performance monitoring
- Resource usage tracking
- Conversational interface
- Chat history persistence
- Context-aware follow-up questions
- Improve retrieval query quality
- Two-step prompts for query preprocessing
- Agentic RAG
- Multilayer storage
- File metadata (name, description)
- Graph database integration for relationships
- Hybrid Search on Elasticsearch
- Combine semantic and keyword search
- Boost results based on metadata
- Semantic Chunker
- Experimental implementation
- Parameter tuning for optimal chunks
- Database control endpoints
- Recreate database
- Remove files (whole document)
- Retrieve file list
- Change document content/metadata
Contributions and feedback on these improvements are welcome!