← Back to Portfolio

AI Knowledge Assistant (RAG Engine)

An advanced, production-ready RAG system built to solve the contextual limitations of base LLMs by dynamically indexing complex research papers.

Business Context

Enterprise knowledge bases are massive and unstructured. Precise retrieval saves thousands of hours of manual document review.

Technical Context

Required a sophisticated hybrid search (Dense + Sparse) coupled with a neural cross-encoder reranker to handle massive document ingestion.

Architecture Flow

PDF
→
Chunking
→
Embeddings
→
FAISS
→
BM25
→
Cross Encoder
→
Llama 3
→
Streaming Response

Component Breakdown

  • Ingestion Pipeline: Document loaders and text splitters for PDFs and arXiv API.
  • Retrieval Engine: FAISS (dense) and BM25 (sparse) running in parallel.
  • Re-Ranking Phase: HuggingFace ms-marco-TinyBERT Cross-Encoder.
  • Generation Engine: FastAPI backend streaming Server-Sent Events from Groq Llama 3.

Data Flow

  • Raw documents are ingested, chunked, and embedded.
  • User query hits both FAISS and BM25 indices.
  • Candidate chunks are scored and resorted by the Cross-Encoder.
  • Top-K chunks are injected into the LLM prompt and streamed to the UI.

Infrastructure

ModelsLlama 3 (8B), Sentence-Transformers, ms-marco-TinyBERT
DatabasesFAISS, Local File System
CachingIn-memory LRU Cache
APIsarXiv API, Groq API

Engineering Deep Dive

Challenges

  • Keyword Loss: Pure vector search (FAISS) consistently failed to retrieve documents when the user queried for exact acronyms or specific part numbers.
  • Context Window limits: Stuffing too many retrieved chunks into the LLM caused performance degradation and API limits.
  • PDF Parsing: Extracting clean text from multi-column academic PDFs with math equations.

Technical Decisions

Implementing Hybrid Search (BM25 + FAISS)

FAISS excels at semantic meaning, while BM25 guarantees that exact technical keywords and acronyms are never missed.

Adding a Cross-Encoder Re-Ranker

Retrieving 20 chunks from hybrid search and re-ranking them neutrally proved far more accurate than just taking the top 5 from vector search directly.

Results & Metrics

0%
Hallucinations
In verifiable closed-book queries.
92%
Retrieval Precision
Top-K after Cross-Encoder re-ranking.

Lessons Learned

  • Vector databases alone are insufficient for production RAG. Hybrid search is mandatory.
  • Cross-encoders add ~200ms latency but double retrieval accuracy; it's a necessary tradeoff.

Recruiter Takeaways

AI Engineer

Understands advanced RAG concepts (Hybrid Search, Re-Ranking, Chunking Strategies) beyond basic tutorials.

ML Engineer

Familiar with deploying and running HuggingFace Cross-Encoders locally.

Startup Founder

Built a highly performant, production-ready enterprise knowledge tool.

Software Engineer

Solid architectural boundaries between ingestion, retrieval, and generation.