Overview
A work-in-progress project to build a RAG (retrieval-augmented generation)
system over a hand-curated knowledge base of Canada Revenue Agency (CRA) audit
methodology: organization structure, audit-methodology practices, statistics,
software-controls, risk-control frameworks, and 6 public audit/evaluation case studies,
sourced from official canada.ca documentation rather than any forum or community
content. Current state: retrieval foundation only, not shipped: the hybrid
retrieval layer (semantic + keyword + graph) is built and evaluated, but the generation
step that would make this a complete RAG system hasn't been built yet; today a query
returns ranked, explained source notes, not a synthesized answer. It's also worth being
upfront that the retrieval code (rag/, eval/) is currently local-only and not yet
pushed to the public GitHub repo, which today only reflects the earlier vault-content
commits.
Problem
Public CRA audit documentation is comprehensive but scattered across many separate official pages and methodology documents, so finding the right source note for a specific audit question means either already knowing where to look or manually searching each source. The goal was a retrieval layer that could surface the most relevant, properly-sourced notes for a question, with a transparent explanation of why each result was ranked where it was. A black-box answer wouldn't work, since audit findings need to be traceable to their source.
What I built
- A hand-curated Obsidian vault of ~444 markdown notes (~289 substantive, ~155
infrastructure/index notes) organized into numbered folders (
00-Startthrough99-Sources), each source note carrying YAML frontmatter withsource_url,publisher, andaccessed_onpointing back to the originating canada.ca page corpus.py/chunking.py: walk the vault and split notes into retrieval-sized chunksembeddings.py: embed chunks locally withsentence-transformers/all-MiniLM-L6-v2(no API key or per-call cost) into a flat NumPy array used directly as the vector store, with no external vector DB servicelexical.py: a parallel BM25 keyword index (rank-bm25) for exact-term matching semantic search can missgraph.py: anetworkxgraph built from the vault's own note-to-note wikilinks (Obsidian-style double-bracket links between notes), used for n-hop graph-proximity expansionretrieve.py: blends semantic similarity, BM25 score, graph proximity, and an authoritative-source bonus into one weighted hybrid score, with awhy_includedexplanation attached to every result- A CLI (
python -m rag.cli {index|search|stats}) as the only interface (no web UI or chat interface yet) - A real evaluation harness (
eval/retrieval_eval.py,eval/questions.json, 10 hand-written Q&A pairs with expected notes) computing Hit@1/3/5, Recall@5/10, and MRR across multiple retrieval modes
Architecture
Vault markdown (vault/public/...-style folder structure, curated by hand) →
corpus.py/chunking.py build chunked documents → embeddings.py produces a local
NumPy embedding matrix (rag_data/embeddings.npy) while lexical.py builds a BM25
index (rag_data/lexical_bm25.pkl) and graph.py builds a wikilink graph
(rag_data/graph.json) in parallel. retrieve.py queries all three signals plus a
source-authority bonus and combines them into a single ranked, explained result list,
exposed only via the CLI. No LLM is called anywhere in the pipeline.

generated by gitdiagram · click to explore interactively ↗ · full size
Decisions
- Local embeddings over an API-based embedding model:
sentence-transformersrunning locally means no per-query cost and no external dependency, at the cost of lower embedding quality than a larger hosted model. - A flat NumPy array over a dedicated vector database: reasonable at the current corpus size (~289 substantive notes); would need revisiting if the corpus grew by an order of magnitude.
- Hybrid retrieval (semantic + BM25 + graph) over semantic search alone: combines what embeddings are good at (conceptual similarity) with what BM25 is good at (exact term matches embeddings can miss) and what the graph adds (notes the author explicitly linked as related), rather than betting on one signal.
- Building and proving out retrieval before generation: the plan is a full RAG system, but getting hybrid retrieval right first (and evaluating it) means the eventual generation step will be grounded in results already shown to be accurate, rather than layering an LLM on top of unproven retrieval over audit-sensitive content.
Results
On the 10-question hand-written eval set, the hybrid_graph retrieval mode reaches Hit@1 = 0.9 and MRR = 0.91. That's strong on this small set, but 10 questions is not a statistically robust benchmark and shouldn't be read as a general accuracy number.
What I learned
- Building the eval harness alongside the retrieval pipeline (rather than after) made it possible to compare hybrid and single-signal retrieval modes with real numbers instead of eyeballing results.
- Each retrieval signal covers a different weakness. Embeddings find conceptually similar notes but blur exact terms; BM25 catches exact terms like program names and acronyms; the wikilink graph brings in notes I had explicitly linked as related. Blending them is more robust than betting on any one.
- Curation is half the work in a RAG system. Sourcing every note from official canada.ca
pages, with
source_url,publisherandaccessed_onin its frontmatter, is what makes each result traceable and itswhy_includedexplanation meaningful. - A small eval set is still worth having. Ten hand-written questions were enough to compare modes and catch regressions, as long as the numbers aren't presented as a general accuracy figure.
- Proving retrieval before adding generation keeps problems separable: if a future answer is wrong, I can check whether retrieval surfaced the right notes before blaming the LLM.
What's next
- Build the generation layer on top of this retrieval foundation to complete the planned RAG implementation: an LLM that answers a question using the retrieved, source-traceable notes as grounding
- Commit the
rag/andeval/retrieval code so the public repo reflects the actual current state of the project - Grow the eval question set beyond 10 questions for a more robust accuracy signal