Built with Python · LangChain · Azure OpenAI · FAISS · FastAPI · Deployed on Azure Container Apps
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.
| 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 |
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
- Python 3.11+
- Azure OpenAI resource or OpenAI API key
- Docker (optional, for containerized deployment)
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.txtcp .env.example .env
# Edit .env with your Azure OpenAI or OpenAI credentialsuvicorn app:app --reload --port 8000
# API docs: http://localhost:8000/docsOpen frontend/index.html in your browser (or serve with python -m http.server 3000 from the frontend/ directory).
# 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 externalAdd secrets to your GitHub repo:
AZURE_CREDENTIALS— service principal JSONAZURE_RESOURCE_GROUP— resource group nameOPENAI_API_KEY— for tests
Then push to main — the pipeline builds, tests, and deploys automatically.
| 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 |
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"])RecursiveCharacterTextSplitter(
chunk_size=1000,
chunk_overlap=200,
separators=["\n\n", "\n", ". ", " ", ""]
)MMR is used instead of simple similarity search to ensure retrieved chunks are both relevant and diverse — avoiding redundant context that wastes token budget.
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?"
The agent.py module demonstrates a ReAct-style agent with two tools:
search_documents— targeted retrieval for specific factssummarize_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."
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
- 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
MIT — feel free to use this as a template for your own RAG applications.