Document Intelligence RAG
Hybrid enterprise RAG pipeline on Azure AI Search (BM25 + dense vector + RRF + semantic reranking) with Cosmos DB session state over 5,000+ documents (10K+ pages) and an async FastAPI service handling 1,000+ daily requests with page-grounded citations.
PythonFastAPIAzure AI SearchAzure OpenAICosmos DBRAG
Problem
Keyword-only enterprise search misses semantic intent, while dense-vector-only retrieval drops exact product codes, policy clauses, and acronyms. Production document assistants need hybrid retrieval, stateful conversation tracking, and deterministic source attribution across multi-thousand-document corpora.
Architecture
1. Ingestion & Indexing Pipeline
- Multi-Format Extraction: Parses PDF, DOCX, and TXT files with page-number metadata preserved through recursive overlapping chunking (
256tokens,50-token overlap). - Azure AI Search Hybrid Index: Stores dense Azure OpenAI embeddings alongside tokenized lexical fields for parallel BM25 + vector search.
2. Async Retrieval & Session Service
- Hybrid Search + Semantic Reranking: Queries execute parallel BM25 keyword and dense vector search fused with Reciprocal Rank Fusion (
RRF) and Azure semantic reranking. - FastAPI + Cosmos DB: An async FastAPI backend manages conversation history and user sessions in Azure Cosmos DB, serving 1,000+ daily requests across 5,000+ documents (10K+ pages) with page-verified citations.
Technical Highlights
- Exact + Semantic Recall: RRF eliminates fragile raw-score normalization between unbounded BM25 scores and cosine similarity.
- Grounded Generation: Prompts constrain synthesis to retrieved chunks and return explicit document titles and page anchors for verification.
- Async Throughput: Batched embedding calls, index partitioning, and non-blocking I/O keep API tail latency predictable under concurrent load.