A Retrieval-Augmented Generation (RAG) system for querying and extracting insights from your documents using LLMs.
- Document Ingestion: Process files (PDF, DOCX, TXT, CSV, XLSX, images), web pages, and database content
- Vector Search: Semantic similarity search using ChromaDB with embedding models
- Hybrid Retrieval: Combine vector search with keyword filtering for more relevant results
- Question-Answering: Generate accurate responses based on context from your documents
- Structured Extraction: Extract specific data from documents using customizable schemas
- Modern Web Interface: React-based UI for document management and querying
- RESTful API: Comprehensive API for integration with other systems
- WebSocket Support: Real-time updates and notifications
- Multiple Data Sources: Connect to file systems, databases, websites, and APIs
- Health Monitoring: System health checks for all components
- Python 3.8+
- PostgreSQL database (optional, can use SQLite for development)
- MinIO or S3-compatible object storage (optional)
- ChromaDB for vector storage
- Node.js and npm for frontend development
- Install Python 3.8 or higher
- Install PostgreSQL (optional)
- Install MinIO (optional)
- Install ChromaDB (optional for local development)
- Install Node.js and npm for frontend
-
Clone the repository:
git clone https://github.com/yourusername/rag.git cd rag -
Create a virtual environment:
python -m venv rag_env -
Copy the example environment file and edit it:
cp .env.example .env- Edit
.envwith your configuration (database URL, API keys, etc.)
- Edit
-
Activate the virtual environment:
- Windows:
rag_env\Scripts\activate - macOS/Linux:
source rag_env/bin/activate
- Windows:
-
Install dependencies:
pip install -r requirements.txt -
Create required directories:
mkdir -p data/uploads data/raw data/processed -
Start the backend:
python run.py
-
Navigate to the frontend directory:
cd frontend -
Install dependencies:
npm install -
Set the environment variable for the API URL:
- Create
.env.localwithNEXT_PUBLIC_API_URL=http://localhost:8080
- Create
-
Start the development server:
npm run dev -
Access the frontend at
http://localhost:3000
- Make sure Docker and Docker Compose are installed
- Configure environment variables in
docker-compose.yml - Build and start the containers:
docker-compose up -d
rag/
├── backend/ # Backend application
│ ├── app/ # Application code
│ │ ├── api/ # API endpoints
│ │ ├── core/ # Core configuration
│ │ ├── db/ # Database models and connection
│ │ ├── models/ # SQLAlchemy models
│ │ ├── schemas/ # Pydantic schemas
│ │ ├── services/ # Business logic
│ │ └── static/ # Static files
│ ├── data/ # Data directory
│ ├── tests/ # Test files
│ ├── .env # Environment variables
│ └── requirements.txt # Python dependencies
├── frontend/ # Frontend application
│ ├── public/ # Public assets
│ ├── src/ # Source code
│ │ ├── app/ # Next.js app directory
│ │ ├── components/ # React components
│ │ └── lib/ # Utility functions and types
│ ├── .env.local # Local environment variables
│ └── package.json # Node.js dependencies
└── docker-compose.yml # Docker configuration
The system is configured using environment variables in the .env file:
DATABASE_URL: Connection string for the databaseCHROMA_HOST: ChromaDB hostCHROMA_PORT: ChromaDB portMINIO_URL: MinIO/S3 URLMINIO_ACCESS_KEY: MinIO/S3 access keyMINIO_SECRET_KEY: MinIO/S3 secret keyOPENAI_API_KEY: OpenAI API key for embeddings and LLMOPENAI_MODEL: OpenAI model to use (default: gpt-4o)EMBEDDING_MODEL: Embedding model to use- Check
.env.examplefor all available configuration options
- Upload Documents: Use the web interface to upload files or add web pages
- View Documents: Browse and manage your uploaded documents
- Data Sources: Configure external data sources for automatic ingestion
- Chat Interface: Use the chat interface to ask questions about your documents
- Document Retrieval: View which documents were used to generate answers
- Performance Metrics: See retrieval and generation metrics for each query
Extract specific data from documents using a schema definition:
{
"document_id": "your-document-id",
"schema_definition": {
"title": "string",
"author": "string",
"publication_date": "date",
"abstract": "string",
"keywords": "list"
}
}-
Documents:
/api/v1/documentsGET: List all documentsPOST /upload: Upload a documentPOST /web: Process a web pageDELETE /{id}: Delete a document
-
Query:
/api/v1/queryPOST /retrieve: Retrieve relevant documentsPOST /generate: Generate an answer
-
Data Sources:
/api/v1/datasourcesGET: List all data sourcesPOST: Add a new data sourceDELETE /{id}: Delete a data source
-
Extraction:
/api/v1/extraction/structured-extractPOST: Extract structured data from documents
-
Health:
/api/v1/healthGET: Check system health
The system supports WebSockets for real-time updates:
- WebSocket endpoint:
/api/ws - Test page:
/websocket
-
Database Connection Error
- Verify database credentials in
.env - Check if PostgreSQL is running
- Verify database credentials in
-
MinIO Connection Error
- Verify MinIO/S3 credentials in
.env - Check if MinIO is running
- Verify MinIO/S3 credentials in
-
OpenAI API Key Error
- Verify your OpenAI API key in
.env - Check API key permissions
- Verify your OpenAI API key in
Run the application in debug mode for more detailed logs:
LOG_LEVEL=debug python run.py
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
MIT License