Skip to content

About

A production-style Retrieval-Augmented Generation system that enables users to upload documents (PDFs, code, text) and query them with context-aware, citation-backed answers. Instead of hallucinating, the system retrieves relevant information from your own data and injects it into the LLM prompt ensuring grounded, reliable responses.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ RAG Codebase Documentation Assistant

An end-to-end Retrieval-Augmented Generation (RAG) system that lets you upload documents (PDFs, code, text) and ask questions grounded in their content โ€” no hallucinations, just answers backed by your own data.

Built with FastAPI ยท ChromaDB ยท sentence-transformers ยท Groq (LLaMA 3)


๐Ÿง  What Is RAG?

Large Language Models are powerful, but they suffer from two hard limitations: they hallucinate, and they have no access to your private or recent data.

RAG solves this by retrieving relevant context from your documents and injecting it directly into the prompt โ€” so the model answers from your knowledge base, not from memory.

User Query  โ†’  Embed  โ†’  Vector Search  โ†’  Top-K Chunks  โ†’  Rerank  โ†’  Prompt  โ†’  LLM  โ†’  Grounded Answer + Citations

โœจ Features

Core

  • ๐Ÿ“„ Upload documents โ€” .pdf, .txt, .md, code files
  • โœ‚๏ธ Smart chunking with overlap for context continuity
  • ๐Ÿ”Ž Semantic search via sentence-transformer embeddings
  • ๐Ÿง  Persistent vector store with ChromaDB
  • ๐Ÿค– LLM generation via Groq (LLaMA 3) โ€” low-latency inference
  • ๐Ÿ“Œ Grounded answers with chunk citations [Chunk X]
  • ๐Ÿงพ Raw retrieved chunks returned alongside the answer

Advanced

  • ๐Ÿ” Retrieval reranking via keyword overlap scoring
  • ๐ŸŽฏ Metadata filtering by document_id
  • ๐Ÿ“Š Multi-document support
  • โšก Fast, async-ready API with FastAPI

๐Ÿ› ๏ธ Tech Stack

Layer Technology
API FastAPI + Uvicorn
Embeddings sentence-transformers (all-MiniLM-L6-v2)
Vector Store ChromaDB (persistent, local)
LLM Groq โ€” LLaMA 3
Validation Pydantic
Containerisation Docker (optional)

๐Ÿ“‚ Project Structure

rag-doc-assistant/
โ”œโ”€โ”€ ๐Ÿ“ backend/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ app/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ api/                     # Routes
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ upload.py            # POST /upload/ โ€” ingest docs, chunk & embed
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ ask.py               # POST /ask/   โ€” retrieve, rerank & generate
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ services/                # AI Logic
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ chunker.py           # Fixed-size overlapping text chunking
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ embedder.py          # all-MiniLM-L6-v2 โ†’ 384-dim vectors
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ retriever.py         # ChromaDB top-K cosine similarity search
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ reranker.py          # Keyword overlap re-scoring
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ generator.py         # Groq / LLaMA 3 grounded generation
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ core/                    # DB
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ vector_store.py      # ChromaDB client, collections & upserts
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ schemas/
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ main.py                  # Entry โ€” FastAPI app factory & router setup
โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ requirements.txt
โ”‚   โ””โ”€โ”€ ๐Ÿณ Dockerfile
โ”œโ”€โ”€ ๐Ÿ—„๏ธ  chroma_db/                      # Persistent vector store (mount as volume)
โ””โ”€โ”€ ๐Ÿ“„ README.md

๐Ÿš€ Getting Started

1. Clone the repo

git clone https://github.com/ApplexX7/rag-doc-assistant.git
cd rag-doc-assistant/backend

2. Install dependencies

pip install -r requirements.txt

3. Set environment variables

export GROQ_API_KEY="your_api_key"

4. Run the server

uvicorn app.main:app --reload

5. Open Swagger UI

http://127.0.0.1:8000/docs

๐Ÿงช API Usage

Upload a document

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

Response

{
  "document_id": "abc123",
  "filename": "resume.pdf",
  "chunk_count": 6
}

Ask a question

POST /ask/
Content-Type: application/json
{
  "question": "What backend technologies does he know?",
  "top_k": 3,
  "document_id": "abc123"
}

Response

{
  "question": "What backend technologies does he know?",
  "answer": "He has experience with Node.js, Fastify, and FastAPI... [Chunk 1]",
  "results": [
    { "chunk_id": 1, "text": "...", "score": 0.91 }
  ]
}

๐Ÿง  Key Design Decisions

1. Chunking strategy

Fixed-size chunks with overlap ensure context continuity across boundaries. The tradeoff is precision (smaller chunks) vs. recall (larger chunks with more context).

2. Embeddings

all-MiniLM-L6-v2 from sentence-transformers โ€” lightweight (80MB), fast, and strong on semantic similarity tasks. No GPU required.

3. Vector store

ChromaDB runs locally with persistence out of the box. No external service needed โ€” just mount chroma_db/ as a Docker volume to survive restarts.

4. Retrieval + reranking

Top-K semantic search gives high recall. The reranker then re-scores by keyword overlap to improve precision before passing chunks to the LLM.

5. Grounded generation

The prompt template explicitly instructs the model to cite sources as [Chunk X] and to not answer beyond the retrieved context โ€” minimising hallucinations by design.


โš ๏ธ Current Limitations

  • Retrieval quality is sensitive to chunk size tuning
  • No hybrid search (BM25 + vector) โ€” pure semantic only
  • No conversation memory across turns
  • Reranker is keyword-based, not ML (cross-encoder)
  • No evaluation metrics or benchmarking yet

๐Ÿ”ฎ Roadmap

๐Ÿ”ฅ High Impact

  • Hybrid search โ€” BM25 + dense embeddings
  • Cross-encoder reranking
  • Code-aware chunking (by function / class)
  • Streaming responses (SSE)

๐Ÿง  AI Enhancements

  • Multi-hop retrieval
  • Query rewriting before embedding
  • Context compression
  • Hallucination detection layer

๐ŸŽจ Product / UX

  • Next.js frontend with chat UI
  • File upload dashboard
  • Source highlighting in answers
  • Chunk visualisation

โš™๏ธ System Design

  • Async ingestion pipeline with background workers
  • Redis caching for repeated queries
  • Postgres metadata layer

๐Ÿ’ก Interview Talking Points

"I built a full RAG system from scratch โ€” document ingestion, embedding, vector storage, semantic retrieval, reranking, and grounded LLM generation. I made deliberate tradeoffs around chunking strategy, embedding model size, and reranking approach, and the prompt architecture enforces citation-based answers to reduce hallucinations."

What this project demonstrates:

  • AI system design and LLM integration
  • Production-style backend engineering
  • Data pipeline design
  • Tradeoff thinking โ€” latency vs. accuracy, precision vs. recall
  • Practical knowledge of RAG patterns used in real AI products

๐Ÿ“Œ Author

Mohammed Hilali


This is not just a demo โ€” it's a production-style RAG system reflecting real-world AI engineering patterns used in modern startups and AI products.

About

A production-style Retrieval-Augmented Generation system that enables users to upload documents (PDFs, code, text) and query them with context-aware, citation-backed answers. Instead of hallucinating, the system retrieves relevant information from your own data and injects it into the LLM prompt ensuring grounded, reliable responses.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages