This repository contains a RAG (Retrieval-Augmented Generation) chatbot application built using FastAPI. The application enables long-running conversations with an LLM grounded by information from a collection of academic papers on AI agents and multi-agent systems.
- FastAPI Backend: Provides endpoints for creating conversations and sending messages
- Vector Database Integration: Stores document embeddings for retrieval using Qdrant
- OpenAI Integration: Uses OpenAI for LLM chat completions and embeddings
- PDF Processing: Processes PDF files into vector embeddings for knowledge retrieval
- RAG Implementation: Enhances LLM responses with context from relevant documents
- Python 3.11+
- uv (for local development)
- Docker and Docker Compose (for containerized deployment)
- OpenAI API key
# Install dependencies with uv
uv venv
uv sync
# Activate a virtual environment
source .venv/bin/activate# Set your OpenAI API key
export OPENAI_API_KEY=your-api-key-here
# Run with docker-compose
docker-compose up -dPlace PDF documents in the data directory specified by the PDF_DIR environment variable. The default location is ./data.
During startup, the application will:
- Process all PDFs in the configured directory
- Convert them to text chunks
- Generate embeddings for each chunk
- Store the chunks and embeddings in Qdrant
# Activate a virtual environment
source .venv/bin/activate
# Start Qdrant
docker run -p 6333:6333 qdrant/qdrant:latest
# Start the FastAPI application with hot reload
uv run uvicorn app.main:app --reload# Start services
docker-compose up
# Stop services
docker-compose downPOST /api/create/{id}: Create a new chat session with the specified ID
POST /api/chats/{chat_id}/rag: Send a message to the RAG-enhanced chatbot
Example request:
{
"message": "What can you tell me about AI agents?"
}Example response:
{
"answer": "AI agents are systems that can perceive their environment, make decisions, and take actions to achieve specific goals...",
"sources_used": 3,
"message_count": 2
}# Run ruff linter to check for issues
ruff check .
# Run ruff formatter to automatically format code
ruff format .# Run all tests with verbose output and skipping document loading
source .venv/bin/activate
SKIP_DOC_LOADING=true pytest -xvs tests/The application follows these key components:
- FastAPI Routers: Organized by feature area
- Qdrant Vector Store: For efficient similarity search
- OpenAI Integration: For embeddings and LLM completion
- Document Processing Pipeline: Loads and processes documents at startup
- Chat Management: Maintains conversation history for continuity
The project includes GitHub Actions workflows for:
- Linting: Using Ruff to check code quality
- Formatting: Ensuring consistent code style with Ruff formatter
- Testing: Running automated tests with pytest
These checks run automatically on pull requests and pushes to the main branch.