A powerful Retrieval-Augmented Generation (RAG) system built with LangGraph, FastAPI, and Qdrant Cloud. This project provides an intelligent document processing and question-answering system that can ingest PDFs and other documents, then answer questions using advanced AI techniques.
- π Fast Document Ingestion: Upload PDFs and other documents via REST API
- π§ Intelligent RAG Pipeline: LangGraph-powered multi-step retrieval and generation
- π Advanced Vector Search: Qdrant Cloud integration for efficient similarity search
- π RESTful API: Clean FastAPI endpoints for easy integration
- π§ Configurable: Flexible chunking, embedding, and generation parameters
- βοΈ Cloud-Ready: Built for production with Qdrant Cloud and OpenAI
graph TB
A[π Documents] --> B[π§ Document Processor]
B --> C[π Vector Store<br/>Qdrant Cloud]
C --> D[π LangGraph RAG Pipeline]
D --> E[π€ OpenAI LLM]
E --> F[π¬ Answer]
G[π FastAPI] --> H[π€ /ingest]
G --> I[β /query]
H --> B
I --> D
Our RAG system uses an innovative Query Decomposition + Parallel Retrieval architecture that significantly improves retrieval accuracy:
Key Features:
- Query Decomposition: Breaks complex queries into focused, searchable components
- Parallel Retrieval: Simultaneous searches across multiple query aspects
- Semantic Fusion: Intelligent combination of results from different searches
- Component-Level Rewriting: Targeted improvement of failed query components
- Relevance Judgment: LLM-powered evaluation of retrieved context quality
Example Flow:
- Input: "eye surgery in Dubai"
- Decomposition: ["What is covered for eye surgery procedures?", "What coverage is available for medical treatment in Dubai or UAE?", "What are the international medical coverage terms?"]
- Parallel Search: All three queries search simultaneously
- Fusion: Results are intelligently combined and deduplicated
- Answer: Comprehensive response with page references
- Python 3.9+
- OpenAI API key
- Qdrant Cloud account (free tier available)
# Clone the repository
git clone https://github.com/yourusername/agentic-rag-pipeline.git
cd agentic-rag-pipeline/app
# Install dependencies
pip install -e .
# Copy environment template
cp env.example .envEdit your .env file:
# OpenAI Configuration (Required)
OPENAI_API_KEY=your_openai_api_key_here
# Qdrant Cloud Configuration (Required)
QDRANT_URL=https://your-cluster-url.qdrant.tech
QDRANT_API_KEY=your_qdrant_api_key_here
QDRANT_COLLECTION=documents
# Optional: API Configuration
API_HOST=0.0.0.0
API_PORT=8000python run.pyThe API will be available at http://localhost:8000
curl -X POST "http://localhost:8000/ingest" \
-H "Content-Type: multipart/form-data" \
-F "files=@document1.pdf" \
-F "files=@document2.pdf"{
"message": "Successfully processed 2 files",
"processed_files": [
{
"filename": "document1.pdf",
"chunks": 15,
"status": "success"
}
]
}curl -X POST "http://localhost:8000/query" \
-H "Content-Type: application/json" \
-d '{"query": "What is machine learning?"}'{
"answer": "Machine learning is a subset of artificial intelligence...",
"sources": [
{
"content": "Relevant document excerpt...",
"metadata": {"source": "document1.pdf", "page": 1}
}
]
}curl -X GET "http://localhost:8000/"src/agent/
βββ simple_api.py # FastAPI application
βββ graph.py # LangGraph RAG pipeline
βββ simple_processor.py # Document processing
βββ simple_vector_store.py # Qdrant integration
- Document Processor (
simple_processor.py): Handles PDF parsing and text extraction - Vector Store (
simple_vector_store.py): Manages Qdrant Cloud operations - RAG Pipeline (
graph.py): LangGraph workflow for retrieval and generation - API Layer (
simple_api.py): FastAPI endpoints and request handling
- New Document Types: Extend
SimpleDocumentProcessorwith additional loaders - Custom Chunking: Modify chunking logic in the processor
- Enhanced RAG: Add new nodes to the LangGraph pipeline
- API Endpoints: Add new routes in
simple_api.py
- Chunk Size: Text chunk size (default: 1000 characters)
- Chunk Overlap: Overlap between chunks (default: 200 characters)
- Supported Formats: PDF, TXT, MD, HTML, DOCX
- Collection Name: Qdrant collection identifier
- Embedding Model: OpenAI text-embedding-3-small (default)
- Similarity Threshold: Minimum similarity score for retrieval
- Max Tokens: Maximum response length
- Temperature: Response creativity (0.0-1.0)
- Retrieval Count: Number of relevant chunks to retrieve
OPENAI_API_KEY=your_production_key
QDRANT_URL=your_production_cluster
QDRANT_API_KEY=your_production_key
QDRANT_COLLECTION=production_docsWe welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
