Muhammad Ahmad Faizan
Back to Portfolio
AI

RAG Knowledge Assistant

Retrieval-augmented Q&A system with citation-aware, grounded answers for internal knowledge bases.

PythonLangChainOpenAIChromaDBFastAPINext.js

Overview

Built a production RAG (Retrieval-Augmented Generation) system that enables natural language Q&A over internal documentation, knowledge bases, and technical manuals. The system retrieves relevant context chunks, generates grounded answers with inline citations, and provides confidence indicators for each response.

Business Problem

Teams accumulate vast internal documentation that becomes effectively inaccessible. Traditional search requires knowing the right keywords, and LLMs alone hallucinate on proprietary content. Teams needed a system that combines the flexibility of natural language queries with the reliability of grounded, source-cited answers.

Solution

Built a multi-stage RAG pipeline: document chunking with overlap strategies, embedding generation for semantic search, vector storage in ChromaDB, retrieval with hybrid search (semantic + keyword), and LLM-based answer generation with citation extraction. Added a re-ranking step to improve retrieval precision before generation.

Architecture

RAG Knowledge Assistant — Architecture Documents Chunking + Overlap Embedding Model ChromaDB Vector Store User Query Query Embedding + Hybrid Search Retrieve Top-K k=5 chunks Re-ranker Cross-encoder scoring Response Generation Grounded + Citations Grounded Answer

Key Features

  • Hybrid search combining semantic embeddings with keyword (BM25) retrieval
  • Cross-encoder re-ranking for improved precision in top results
  • Citation-aware answer generation with source document links
  • Confidence scoring for each generated answer
  • Configurable chunk overlap strategy for context preservation
  • FastAPI backend with async support for concurrent queries

Gallery

RAG pipeline flow showing document chunking, embedding generation, retrieval, re-ranking, and grounded answer generation

RAG pipeline flow showing document chunking, embedding generation, retrieval, re-ranking, and grounded answer generation

Tech Stack

PythonLangChainOpenAI EmbeddingsChromaDBFastAPINext.jsDocker

Engineering Challenges

Chunk Boundary Artifacts

Naive document chunking breaks logical paragraphs mid-sentence, losing context. Implemented recursive character text splitting with overlap windows that respect paragraph and sentence boundaries.

Relevance Tuning

Initial retrieval often returned semantically similar but contextually irrelevant chunks. Added a cross-encoder re-ranking step that improved top-1 precision by 35% over pure embedding similarity.

Citation Accuracy

LLMs sometimes cite the wrong source document for a given claim. Built a citation verification step that cross-references each claim against retrieved chunks before rendering the final answer.

Lessons Learned

  • Retrieval quality matters more than generation quality — invest in chunking strategy and re-ranking
  • Hybrid search catches edge cases that pure semantic search misses
  • Citation transparency builds user trust even when answers are imperfect

Results

The system answers technical queries with 92% grounded-answer accuracy (verified against held-out Q&A pairs). Average end-to-end latency is 1.8 seconds, with retrieval accounting for just 200ms of that.

Related Projects

Let's Build Something Similar

Have a project in mind? Let's discuss how we can architect and build it together.

Discuss Your Project