Skip to content

A production-ready end-to-end AI SaaS platform that allows users to query financial, technical, and business documents with AI-powered insights using LangGraph agent orchestration.

Notifications You must be signed in to change notification settings

swaroski/insightbot

Repository files navigation

InsightBot - AI-Powered Knowledge Platform

A production-ready end-to-end AI SaaS platform that allows users to query financial, technical, and business documents with AI-powered insights using LangGraph agent orchestration.

πŸš€ Features

  • LangGraph Agent Workflow: Multi-step agentic LLM behavior with query parsing, retrieval, analysis, summary, and evaluation
  • OpenAI Integration: Powered by GPT-4o for reasoning and text-embedding-ada-002 for embeddings
  • Vector Search: FAISS-based document embedding and similarity search
  • Modern Frontend: Next.js 14 with Tailwind CSS and shadcn/ui components
  • Document Processing: Support for PDF, TXT, and DOCX files
  • Real-time Evaluation: LLM-as-a-judge scoring for answer quality
  • Production Ready: Docker containerization and CI/CD pipeline
  • Analytics: Query history, performance metrics, and evaluation scores
  • MCP Server: Model Context Protocol integration for AI assistants

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend      β”‚    β”‚   Backend       β”‚    β”‚   Vector Store  β”‚
β”‚   (Next.js)     │────│   (FastAPI)     │────│   (FAISS)       β”‚
β”‚   - Query UI    β”‚    β”‚   - LangGraph   β”‚    β”‚   - Embeddings  β”‚
β”‚   - Upload      β”‚    β”‚   - Agents      β”‚    β”‚   - Similarity  β”‚
β”‚   - Analytics   β”‚    β”‚   - Evaluation  β”‚    β”‚   - Retrieval   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   MCP Server    β”‚
                    β”‚   (Protocol)    β”‚
                    β”‚   - Tools       β”‚
                    β”‚   - Integration β”‚
                    β”‚   - AI Assistantβ”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Agent Workflow

  1. Query Parser Agent: Extracts intent, entities, and query type
  2. Retriever Agent: Searches FAISS vector store for relevant documents
  3. Analysis Agent: Performs reasoning over retrieved content using GPT-4o
  4. Summary Agent: Creates final answer with citations and key points
  5. Evaluation Agent: Scores output quality using LLM-as-a-judge

πŸ› οΈ Tech Stack

Backend

  • FastAPI: Modern Python web framework
  • LangGraph: Agent workflow orchestration
  • FAISS: Vector similarity search
  • OpenAI: GPT-4o and text-embedding-ada-002
  • SQLAlchemy: Database ORM
  • PostgreSQL: Production database
  • Redis: Caching and session storage

Frontend

  • Next.js 14: React framework with App Router
  • Tailwind CSS: Utility-first CSS framework
  • shadcn/ui: Modern UI components
  • Framer Motion: Animation library
  • SWR: Data fetching and caching
  • TypeScript: Type safety

DevOps

  • Docker: Containerization
  • GitHub Actions: CI/CD pipeline
  • Vercel: Frontend deployment
  • Fly.io: Backend deployment

πŸ“¦ Installation

Prerequisites

  • Docker and Docker Compose
  • Node.js 18+
  • Python 3.11+
  • OpenAI API key

Quick Start with Docker

  1. Clone the repository
git clone https://github.com/your-username/insightbot.git
cd insightbot
  1. Set up environment variables
cp .env.example .env
# Edit .env with your OpenAI API key
  1. Start the services
docker-compose up -d
  1. Access the application

Local Development

Backend Setup

cd backend
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn app.main:app --reload

Frontend Setup

cd frontend
npm install
npm run dev

πŸ”§ Configuration

Environment Variables

Create a .env file in the root directory:

# OpenAI Configuration
OPENAI_API_KEY=your_openai_api_key_here

# Database Configuration
DATABASE_URL=postgresql://user:password@localhost:5432/insightbot

# Application Configuration
BACKEND_URL=http://localhost:8000
FRONTEND_URL=http://localhost:3000

# File Upload Configuration
UPLOAD_DIR=./uploads
MAX_FILE_SIZE=10485760  # 10MB

# FAISS Configuration
FAISS_INDEX_PATH=./faiss_index
EMBEDDING_MODEL=text-embedding-ada-002

# Evaluation Configuration
EVALUATION_MODEL=gpt-4o-mini
EVALUATION_THRESHOLD=3.0

# Security
SECRET_KEY=your_secret_key_here
CORS_ORIGINS=http://localhost:3000

πŸ“š API Documentation

Core Endpoints

Query Documents

POST /api/query
Content-Type: application/json

{
  "query": "Compare Tesla and NVIDIA performance in 2023",
  "session_id": "optional-session-id"
}

Upload Documents

POST /api/upload
Content-Type: multipart/form-data

file: <PDF/TXT/DOCX file>

Get Query History

GET /api/queries?page=1&page_size=10&session_id=optional

Re-evaluate Query

POST /api/eval
Content-Type: application/json

{
  "query_id": "query-uuid"
}

Response Format

{
  "query": "User's question",
  "answer": "AI-generated answer with citations",
  "sources": [
    {
      "content": "Relevant text snippet",
      "filename": "document.pdf",
      "page": 1,
      "relevance_score": 0.95
    }
  ],
  "evaluation": {
    "score": 4.2,
    "rationale": "Well-structured answer with good sources",
    "criteria": {
      "accuracy": 4.5,
      "completeness": 4.0,
      "relevance": 4.3,
      "clarity": 4.1,
      "coherence": 4.2
    }
  },
  "session_id": "session-uuid",
  "timestamp": "2024-01-15T10:30:00Z"
}

πŸ§ͺ Testing

Backend Tests

cd backend
pytest tests/ -v

Frontend Tests

cd frontend
npm test

Integration Tests

docker-compose -f docker-compose.test.yml up --build

πŸš€ Deployment

Production Deployment with Docker

  1. Build and push images
docker build -f docker/Dockerfile.backend -t insightbot-backend .
docker build -f docker/Dockerfile.frontend -t insightbot-frontend .
  1. Deploy with Docker Compose
docker-compose -f docker-compose.prod.yml up -d

Cloud Deployment

Vercel (Frontend)

cd frontend
vercel --prod

Fly.io (Backend)

fly deploy -f fly.toml

AWS ECS

Use the provided docker-compose.yml with AWS ECS CLI or create ECS task definitions.

πŸ“Š Monitoring and Analytics

Available Metrics

  • Query volume and patterns
  • Response evaluation scores
  • Document processing statistics
  • Agent execution times
  • Error rates and types

Health Checks

  • Backend: GET /health
  • Database: Connection status
  • Vector Store: Index status
  • OpenAI: API connectivity

πŸ” Security

  • API Keys: Securely stored in environment variables
  • File Uploads: Type and size validation
  • CORS: Configured for specific origins
  • Rate Limiting: Implemented for API endpoints
  • Input Validation: Pydantic models for request validation

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Commit changes: git commit -m 'Add your feature'
  4. Push to branch: git push origin feature/your-feature
  5. Submit a pull request

Code Style

  • Backend: Black formatting, Ruff linting
  • Frontend: Prettier formatting, ESLint
  • Commits: Conventional commit messages

πŸ“ License

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

πŸ†˜ Support

  • Documentation: Check the /docs endpoint for API documentation
  • Issues: Create an issue on GitHub
  • Discord: Join our Discord community

πŸš€ Roadmap

  • Multi-user authentication with Supabase
  • Real-time chat interface
  • Advanced analytics dashboard
  • Mobile app support
  • Enterprise features (SSO, audit logs)
  • Multi-language support
  • Advanced evaluation metrics

πŸ“ˆ Performance

  • Query Response: < 5 seconds average
  • File Processing: < 30 seconds for 10MB documents
  • Concurrent Users: 100+ supported
  • Uptime: 99.9% target

πŸ”— MCP Server Integration

InsightBot includes a Model Context Protocol (MCP) server for seamless integration with AI assistants like Claude Code.

Quick Start

# Start MCP server with Docker
docker-compose up mcp-server

# Or run locally
python -m mcp_server.main

Available Tools

  • query_documents: Query documents using AI workflow
  • upload_document: Upload and process documents
  • get_document_stats: Get collection statistics
  • search_similar_documents: Find similar documents
  • get_query_history: Retrieve query history
  • evaluate_response: Evaluate response quality

Claude Code Integration

Add to your ~/.claude-code/settings.json:

{
  "mcpServers": {
    "insightbot": {
      "command": "python",
      "args": ["-m", "mcp_server.main"],
      "cwd": "/path/to/insightbot/backend",
      "env": {
        "OPENAI_API_KEY": "your-api-key"
      }
    }
  }
}

For detailed MCP integration guide, see MCP_INTEGRATION.md.


Built with ❀️ by the InsightBot team. Powered by OpenAI, LangGraph, and modern web technologies.

About

A production-ready end-to-end AI SaaS platform that allows users to query financial, technical, and business documents with AI-powered insights using LangGraph agent orchestration.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published