Skip to content

A multi-agent AI platform for advanced document intelligence. This system orchestrates scalable, asynchronous workflows, using a team of specialized AI agents to manage the entire document lifecycle from ingestion and processing to deep analysis and semantic querying

License

Notifications You must be signed in to change notification settings

HarshilMaks/InsightDocs

Repository files navigation

InsightDocs

Python 3.11+ FastAPI License

An AI-driven agent architecture system for transforming unstructured documents into operational intelligence through multi-agent collaboration and RAG (Retrieval-Augmented Generation).

🎯 Overview

InsightDocs (formerly InsightDocs) is a production-ready platform that combines multi-agent AI architecture with RAG capabilities to process, analyze, and query documents intelligently. Built with modern microservices patterns, it demonstrates best practices for building scalable, maintainable AI applications.

Key Capabilities

  • πŸ“„ Document Intelligence: Upload and process PDFs, Word documents, and text files
  • πŸ€– Multi-Agent System: Coordinated AI agents working together on complex workflows
  • πŸ” Semantic Search: RAG-powered queries with vector similarity search
  • ⚑ Async Processing: Background task processing with Celery workers
  • 🎨 REST API: FastAPI-based high-performance API endpoints
  • 🐳 Docker Ready: Complete containerized deployment stack

🌟 Features

Multi-Agent Architecture

The system employs four specialized agents coordinated by an orchestrator:

  • Orchestrator Agent: Central workflow coordinator managing all agents
  • Data Agent: Handles document ingestion, storage, and transformation
  • Analysis Agent: Generates embeddings, summaries, and entity extraction
  • Planning Agent: Provides workflow planning and decision support

RAG (Retrieval-Augmented Generation)

  • Document chunking and intelligent segmentation
  • Vector embedding generation with sentence transformers
  • FAISS-powered similarity search
  • Context-aware response generation using Gemini
  • Source citation and attribution

Production Infrastructure

  • FastAPI: High-performance async API framework
  • PostgreSQL: Reliable metadata and document storage
  • Redis: Message queuing, task broker, and caching
  • S3/MinIO: Scalable object storage for files
  • Celery: Distributed async task processing
  • Docker Compose: Simple deployment orchestration

πŸ“Š Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        Presentation Layer                    β”‚
β”‚  CLI Tool  β”‚  FastAPI REST API  β”‚  API Docs (Swagger)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Business Logic Layer                    β”‚
β”‚  Orchestrator β†’ Data Agent β†’ Analysis Agent β†’ Planning Agentβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         Data Layer                           β”‚
β”‚  PostgreSQL (Metadata) ↔ FAISS (Vectors) ↔ Redis (Queue)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       Storage Layer                          β”‚
β”‚        S3/MinIO (Files) ↔ Local Storage (Temp)            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Workflow Example: Document Processing

User β†’ API β†’ Document Record (PostgreSQL)
           β†’ Celery Task β†’ Orchestrator Agent
                         β†’ Data Agent: Store file in S3, parse content
                         β†’ Data Agent: Chunk text into segments
                         β†’ Analysis Agent: Generate embeddings
                         β†’ Data Agent: Store in FAISS
           β†’ Task Complete β†’ Document ready for querying

πŸš€ Quick Start

Prerequisites

  • Python 3.11 or higher
  • Docker and Docker Compose
  • Gemini API key

Installation

  1. Clone the repository
git clone https://github.com/HarshilMaks/InsightDocs.git
cd InsightDocs
  1. Configure environment
cp .env.example .env
# Edit .env and add your GEMINI_API_KEY
  1. Start with Docker Compose (Recommended)
docker-compose up -d

Services will be available at:

Alternative: Manual Setup

# Create virtual environment (if not exists)
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install dependencies
uv pip install -r requirements.txt

# Start services (PostgreSQL, Redis, MinIO separately)

# Initialize database
python -c "from backend.models import Base, engine; Base.metadata.create_all(bind=engine)"

# Terminal 1: Start API
uvicorn insightdocs.api.main:app --reload

# Terminal 2: Start Celery worker
celery -A insightdocs.workers.celery_app worker --loglevel=info

πŸ’‘ Usage Examples

Using the CLI

# Check system health
python cli.py health

# Upload a document
python cli.py upload document.pdf

# Query documents
python cli.py query "What are the key findings?"

# List all documents
python cli.py list-documents

# Check task status
python cli.py status <task-id>

Using the REST API

Upload a document:

curl -X POST "http://localhost:8000/documents/upload" \
  -F "file=@document.pdf"

Query documents:

curl -X POST "http://localhost:8000/query/" \
  -H "Content-Type: application/json" \
  -d '{"query": "What is this about?", "top_k": 5}'

List documents:

curl "http://localhost:8000/documents/"

Using Python

import requests

# Upload document
with open('document.pdf', 'rb') as f:
    response = requests.post(
        'http://localhost:8000/documents/upload',
        files={'file': f}
    )
    result = response.json()
    print(f"Document ID: {result['document_id']}")
    print(f"Task ID: {result['task_id']}")

# Query documents
response = requests.post(
    'http://localhost:8000/query/',
    json={'query': 'What are the main topics?', 'top_k': 5}
)
answer = response.json()
print(f"Answer: {answer['answer']}")
print(f"Sources: {len(answer['sources'])} chunks retrieved")

πŸ“¦ Project Structure

InsightDocs/
β”œβ”€β”€ insightdocs/           # Main application package
β”‚   β”œβ”€β”€ agents/            # Multi-agent system
β”‚   β”‚   β”œβ”€β”€ orchestrator.py    # Central coordinator
β”‚   β”‚   β”œβ”€β”€ data_agent.py      # Data operations
β”‚   β”‚   β”œβ”€β”€ analysis_agent.py  # Analysis & embeddings
β”‚   β”‚   └── planning_agent.py  # Workflow planning
β”‚   β”œβ”€β”€ api/               # FastAPI endpoints
β”‚   β”‚   β”œβ”€β”€ main.py            # Application entry
β”‚   β”‚   β”œβ”€β”€ documents.py       # Document management
β”‚   β”‚   β”œβ”€β”€ query.py           # RAG query endpoint
β”‚   β”‚   β”œβ”€β”€ tasks.py           # Task monitoring
β”‚   β”‚   └── schemas.py         # Pydantic models
β”‚   β”œβ”€β”€ core/              # Core framework
β”‚   β”‚   β”œβ”€β”€ agent.py           # Base agent class
β”‚   β”‚   └── message_queue.py   # Message passing
β”‚   β”œβ”€β”€ models/            # Database models
β”‚   β”‚   β”œβ”€β”€ schemas.py         # SQLAlchemy models
β”‚   β”‚   └── database.py        # DB connection
β”‚   β”œβ”€β”€ utils/             # Utilities
β”‚   β”‚   β”œβ”€β”€ document_processor.py  # Document parsing
β”‚   β”‚   β”œβ”€β”€ embeddings.py          # Vector operations
β”‚   β”‚   └── llm_client.py          # Gemini integration
β”‚   β”œβ”€β”€ workers/           # Celery workers
β”‚   β”‚   β”œβ”€β”€ celery_app.py      # Celery config
β”‚   β”‚   └── tasks.py           # Background tasks
β”‚   β”œβ”€β”€ storage/           # Storage layer
β”‚   β”‚   └── file_storage.py    # S3/MinIO integration
β”‚   └── config/            # Configuration
β”‚       └── settings.py        # App settings
β”œβ”€β”€ tests/                 # Test suite
β”œβ”€β”€ docs/                  # Documentation
β”œβ”€β”€ cli.py                 # Command-line interface
β”œβ”€β”€ docker-compose.yml     # Docker orchestration
β”œβ”€β”€ Dockerfile             # Container definition
β”œβ”€β”€ Makefile               # Development commands
└── requirements.txt       # Dependencies

πŸ§ͺ Testing

# Run all tests
pytest tests/

# Run with coverage
pytest --cov=insightdocs --cov-report=html

# Run specific test module
pytest tests/test_core_agent.py -v

πŸ› οΈ Development

Using Make Commands

make help           # Show all available commands
make install        # Install production dependencies
make install-dev    # Install development dependencies
make test           # Run test suite
make test-cov       # Run tests with coverage
make clean          # Clean cache and temp files
make run-api        # Start API server
make run-worker     # Start Celery worker
make docker-up      # Start all services
make docker-down    # Stop all services
make docker-logs    # View service logs

Development Workflow

  1. Create a feature branch
  2. Make changes and test locally
  3. Run tests: make test
  4. Clean up: make clean
  5. Submit pull request

πŸ“š Documentation

βš™οΈ Configuration

Environment variables (.env file):

# Database
DATABASE_URL=postgresql://insightdocs:insightdocs@localhost:5432/insightdocs

# Redis
REDIS_URL=redis://localhost:6379/0
CELERY_BROKER_URL=redis://localhost:6379/0
CELERY_RESULT_BACKEND=redis://localhost:6379/1

# Gemini
GEMINI_API_KEY=sk-your-api-key-here

# Storage (S3/MinIO)
S3_ENDPOINT=http://localhost:9000
AWS_ACCESS_KEY_ID=minioadmin
AWS_SECRET_ACCESS_KEY=minioadmin
S3_BUCKET_NAME=insightdocs

# Application
APP_ENV=development
LOG_LEVEL=INFO
SECRET_KEY=your-secret-key-here

# Vector Database
VECTOR_DIMENSION=384

🎯 Use Cases

  1. Document Intelligence Platform: Build Q&A systems over document collections
  2. Knowledge Base Management: Create searchable organizational knowledge repositories
  3. Research Assistant: Query and analyze across multiple research documents
  4. Content Analysis: Extract entities, generate summaries, analyze document content
  5. Workflow Automation: Coordinate complex multi-step AI-powered workflows

πŸ”’ Security Features

  • Environment-based configuration for sensitive data
  • Pydantic input validation on all endpoints
  • SQL injection prevention via SQLAlchemy ORM
  • File upload validation and sanitization
  • Secrets management via environment variables

πŸ“ˆ Performance & Scalability

  • Async I/O: Non-blocking operations throughout the stack
  • Connection Pooling: Efficient database connection management
  • Batch Processing: Optimized embedding generation
  • Horizontal Scaling: Scale API servers and workers independently
  • Caching: Redis-based caching for frequently accessed data
  • Vector Search: FAISS for fast similarity search at scale

πŸ› οΈ Technology Stack

Category Technology
Language Python 3.11+
API Framework FastAPI
Task Queue Celery
Database PostgreSQL
Cache/Queue Redis
Vector DB FAISS
Storage S3/MinIO
LLM Gemini GPT
Embeddings Sentence Transformers
Containerization Docker, Docker Compose

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Please ensure your code:

  • Follows the existing code style
  • Includes appropriate tests
  • Updates documentation as needed
  • Passes all tests (make test)

πŸ› Troubleshooting

Services won't start

# Check if ports are in use
lsof -i :8000  # API
lsof -i :5432  # PostgreSQL
lsof -i :6379  # Redis
lsof -i :9000  # MinIO

# Restart services
docker-compose down
docker-compose up -d

Database connection errors

# Check PostgreSQL
docker-compose ps postgres
docker-compose logs postgres

# Recreate database
docker-compose down -v
docker-compose up -d

Worker not processing tasks

# Check worker logs
docker-compose logs worker

# Check Redis
docker-compose ps redis

πŸ“Š Project Statistics

  • 29 Python modules implementing the complete system
  • 2,271 lines of code in the main application
  • 200+ lines of test coverage
  • 4 specialized agents working in coordination
  • 3 API routers (documents, query, tasks)
  • 5 documentation files covering all aspects

πŸ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Built with modern Python frameworks and best practices
  • Inspired by agent-based architectures and microservices patterns
  • Demonstrates practical implementation of RAG systems

πŸ“ž Support

  • Issues: GitHub Issues
  • Documentation: See the docs/ directory
  • Examples: Check out cli.py for usage examples

Built with ❀️ using Python, FastAPI, Celery, PostgreSQL, Redis, FAISS, and Gemini

About

A multi-agent AI platform for advanced document intelligence. This system orchestrates scalable, asynchronous workflows, using a team of specialized AI agents to manage the entire document lifecycle from ingestion and processing to deep analysis and semantic querying

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •