cat ./projects/doclens.md
[LIVE]07 /
DocLens
RAG document intelligence that actually cites its sources.

// stack
- Python
- FastAPI
- Streamlit
- ChromaDB
- BM25
- BAAI/bge-large-en-v1.5
- Reciprocal Rank Fusion
- Cross-encoder reranking
- Groq
- RAGAS
// THE PROBLEM
Most RAG tutorial implementations use cosine similarity on dense embeddings and call it done. In testing on a 20-question evaluation set, this baseline consistently missed relevant passages that used different terminology from the query — keyword-heavy legal text being a prime example. The system needed to answer "did this exact clause appear?" as reliably as "explain this section to me."
// WHAT I BUILT
A hybrid retrieval pipeline: BM25 (keyword matching) + dense vector retrieval using BAAI/bge-large-en-v1.5 (top-5 MTEB benchmark) fused via Reciprocal Rank Fusion. A cross-encoder reranking pass as the final relevance filter before the LLM sees the context. FastAPI REST backend with a hallucination self-check. Evaluated on a 20-question RAGAS test set: Faithfulness +25%, Answer Relevancy +24%, Context Recall +29%, Context Precision +31% over the cosine-similarity baseline.
// THE KEY DECISION
BAAI/bge-large-en-v1.5 over OpenAI embeddings. The MTEB leaderboard showed comparable retrieval quality at zero API cost — and once the model is cached locally, retrieval latency is lower than a network round-trip to the Embeddings API. For a document-heavy workload, that cost and latency difference compounds with every query.
// WHAT IT TAUGHT ME
RAG quality is measurable. RAGAS gave me four concrete metrics with ground-truth question/answer pairs. Without that framework, I would have been subjectively judging whether answers "seemed better" — not a reproducible test. The 20-question evaluation set forced me to write expected answers explicitly, which surfaced several retrieval failures I would not have caught manually.
// REAL-WORLD IMPACT
A document-heavy professional (lawyer, accountant, researcher) can upload a PDF and ask precise factual questions with measurably higher accuracy than a standard RAG implementation. The +31% Context Precision improvement means fewer hallucinations caused by irrelevant context — a meaningful reliability difference in any professional context where wrong answers have consequences.