Skip to content

poojadshende/AI-DocSense

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧠 DocMind — AI-Powered RAG Document Intelligence

Built with Python · LangChain · Azure OpenAI · FAISS · FastAPI · Deployed on Azure Container Apps

Deploy to Azure Python LangChain FastAPI License: MIT

A production-ready Retrieval-Augmented Generation (RAG) system that enables intelligent Q&A over private documents using vector embeddings, LangChain orchestration, and Azure OpenAI — with conversational memory and an AI agent layer.


✨ Features

Capability Details
RAG Pipeline Chunking → Embedding → FAISS retrieval → LLM generation
Multi-format ingestion PDF, DOCX, TXT, Markdown
Conversation memory 5-turn sliding window per session
AI Agent ReAct-style agent with multi-hop document reasoning
Azure OpenAI GPT-4o + text-embedding-3-large (falls back to OpenAI)
REST API FastAPI with Swagger docs at /docs
Cloud-native Docker + Azure Container Apps + GitHub Actions CI/CD

🏗️ Architecture

User Query
    │
    ▼
FastAPI REST API
    │
    ├─► Document Upload ──► PyPDF/Docx Loader
    │                           │
    │                       Text Splitter (RecursiveCharacterTextSplitter)
    │                           │
    │                       AzureOpenAI Embeddings (text-embedding-3-large)
    │                           │
    │                       FAISS Vector Store ◄──────────────────┐
    │                                                             │
    └─► Query ──► MMR Retrieval ──► ConversationalRetrievalChain  │
                      │                     │                     │
                  top-k chunks         Conversation         Vector Store
                                         Memory
                                           │
                                    AzureChatOpenAI (GPT-4o)
                                           │
                                       Answer + Sources

🚀 Quick Start

Prerequisites

  • Python 3.11+
  • Azure OpenAI resource or OpenAI API key
  • Docker (optional, for containerized deployment)

1. Clone & Install

git clone https://github.com/YOUR_USERNAME/docmind-rag.git
cd docmind-rag/backend

python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt

2. Configure Environment

cp .env.example .env
# Edit .env with your Azure OpenAI or OpenAI credentials

3. Run the API

uvicorn app:app --reload --port 8000
# API docs: http://localhost:8000/docs

4. Open the Frontend

Open frontend/index.html in your browser (or serve with python -m http.server 3000 from the frontend/ directory).


☁️ Azure Deployment

Option A — Azure Container Apps (recommended)

# Build & push Docker image
docker build -t docmind-api ./backend
docker tag docmind-api ghcr.io/YOUR_USERNAME/docmind-api:latest
docker push ghcr.io/YOUR_USERNAME/docmind-api:latest

# Deploy to Azure Container Apps
az containerapp create \
  --name docmind-api \
  --resource-group YOUR_RG \
  --image ghcr.io/YOUR_USERNAME/docmind-api:latest \
  --env-vars AZURE_OPENAI_ENDPOINT=... AZURE_OPENAI_API_KEY=... \
  --target-port 8000 \
  --ingress external

Option B — GitHub Actions CI/CD

Add secrets to your GitHub repo:

  • AZURE_CREDENTIALS — service principal JSON
  • AZURE_RESOURCE_GROUP — resource group name
  • OPENAI_API_KEY — for tests

Then push to main — the pipeline builds, tests, and deploys automatically.


📡 API Reference

Method Endpoint Description
POST /upload Upload and index a document
POST /query Ask a question (RAG)
GET /stats Index statistics
DELETE /reset Clear all indexed documents
GET /health Health check

Example: Upload + Query

import httpx

# Upload document
with open("report.pdf", "rb") as f:
    res = httpx.post("http://localhost:8000/upload", files={"file": f})
print(res.json())  # {"doc_id": "...", "chunks_indexed": 47}

# Query
res = httpx.post("http://localhost:8000/query", json={
    "question": "What are the key findings?",
    "top_k": 4
})
print(res.json()["answer"])

🧪 RAG Pipeline Details

Chunking Strategy

RecursiveCharacterTextSplitter(
    chunk_size=1000,
    chunk_overlap=200,
    separators=["\n\n", "\n", ". ", " ", ""]
)

Retrieval: Maximal Marginal Relevance (MMR)

MMR is used instead of simple similarity search to ensure retrieved chunks are both relevant and diverse — avoiding redundant context that wastes token budget.

Conversation Memory

Each session maintains a ConversationBufferWindowMemory(k=5) — the last 5 turns are included in every prompt, enabling follow-up questions like "Can you explain that in simpler terms?"


🤖 AI Agent

The agent.py module demonstrates a ReAct-style agent with two tools:

  • search_documents — targeted retrieval for specific facts
  • summarize_topic — broad retrieval for comprehensive overviews

Useful for multi-hop questions like: "Compare the revenue figures in Q1 and Q3, then calculate the percentage change."


📁 Project Structure

docmind-rag/
├── backend/
│   ├── app.py              # FastAPI application
│   ├── rag_pipeline.py     # Core RAG logic (LangChain + FAISS)
│   ├── agent.py            # AI Agent with tools
│   ├── requirements.txt
│   ├── Dockerfile
│   └── .env.example
├── frontend/
│   └── index.html          # Single-page UI
├── .github/
│   └── workflows/
│       └── deploy.yml      # CI/CD → Azure Container Apps
└── README.md

🛠️ Tech Stack

  • LangChain 0.3 — RAG chain, document loaders, memory, agents
  • Azure OpenAI — GPT-4o (generation) + text-embedding-3-large (embeddings)
  • FAISS — local vector store with MMR retrieval
  • FastAPI — async REST API with automatic Swagger docs
  • Docker — containerization
  • Azure Container Apps — serverless container hosting
  • GitHub Actions — CI/CD pipeline

📄 License

MIT — feel free to use this as a template for your own RAG applications.

About

AI-powered document intelligence platform — upload PDFs & docs, ask questions in natural language. Built with RAG pipeline, LangChain, Azure OpenAI (GPT-4o), FAISS vector search & FastAPI. Deployed on Azure Container Apps.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages