Personal Project AI / RAG

CFA2 Helper

A lightweight end-to-end RAG study assistant for CFA Level II preparation — built from scratch: PDF ingestion, hybrid retrieval with reranking, grounded answer generation with citations, and a web UI. Answers in Chinese or English, at ~2 seconds per query, entirely on local models except the LLM call.

Python RAG DeepSeek bge-m3 bge-reranker-v2-m3 Streamlit
Motivation

Answers You Can Check

CFA Level II spans thousands of pages of curriculum. Off-the-shelf assistants hallucinate and cite nothing. This project builds the retrieval pipeline from scratch so every answer is grounded in the study corpus and cites its source down to the passage level — with an optional "genetic" mode that explains how each concept was discovered historically.

Architecture

From PDF to Cited Answer

1
Ingestion

PDFs converted to retrieval-friendly Markdown with YAML metadata (pymupdf4llm); corpus chunked by paragraph with sentence-boundary fallback for long blocks.

2
Hybrid Retrieval

BM25-style keyword search (IDF-weighted unigrams + bigrams) fused with multilingual dense embeddings (bge-m3) via reciprocal rank fusion — ~1s per query.

3
Reranking

Top-20 candidates precision-reranked by a cross-encoder (bge-reranker-v2-m3).

4
Grounded Generation

DeepSeek API (OpenAI-compatible) with strict anti-hallucination prompting, passage-level citations [P1234], and a notes-first / web-supplements rule; optional live web search.

5
UI & Preferences

Streamlit web UI or CLI; filter by topic or corpus and boost a preferred source (e.g. official curriculum over prep notes).

Results

Measured Retrieval Quality

40-Question Golden Set · 10 CFA Topics

MRR
0.94
hit@1
92%
hit@5
98%
Latency (warm, MPS)
1–2s
Corpus Scale Tested
50,000+ passages
Without Rerank (Ablation)
MRR 0.91 / hit@1 88%

Evaluation is built into the pipeline: 40 golden questions with expected sources labeled, hit@k and MRR metrics, and rerank ablation. Multilingual retrieval handles questions in either language across three corpora (English prep notes, English official curriculum, Chinese textbook).

The copyrighted study corpora are intentionally not included; the repo ships a small original demo corpus so the pipeline runs out of the box. The project deck (7 slides) covers design decisions, pitfalls found and fixed, and measured results.