OLUMIDE ADENIYI

Report

Fintech RAG Prototype

LangChain · ChromaDB · CBN Regulations

Overview

Built a working RAG (Retrieval-Augmented Generation) system that answers questions about Nigerian fintech regulations using real CBN documents. The system chunks, embeds, stores, and retrieves regulatory content — then passes only the most relevant chunks to Claude for grounded answer generation.

The Problem

LLMs cannot reliably answer questions about specific Nigerian regulatory documents because: (1) training data has a knowledge cutoff, (2) CBN circulars and NCS guidelines change frequently, (3) pasting entire documents into a prompt is expensive and causes the model to drown in noise — retrieving irrelevant sections and missing the specific provision that answers the question.

The Solution: RAG Pipeline

Stage 1 — Document Ingestion

Loaded two CBN documents: the Regulatory Framework for Mobile Money Services (16 pages) and the Consumer Protection Regulations (39 pages). Total: 55 pages.

Stage 2 — Chunking

Used RecursiveCharacterTextSplitter with chunk_size=800, chunk_overlap=100, splitting by paragraph then sentence. Result: 108 chunks from 55 pages.

Stage 3 — Embedding

Used HuggingFace all-MiniLM-L6-v2 (free, runs locally). Each chunk converted to a 384-dimension vector. Embedded once, reused on every query.

Stage 4 — Vector Storage

Stored all 108 vectors in ChromaDB locally. Retrieves top-5 most semantically similar chunks per query in milliseconds.

Stage 5 — Retrieval + Generation

User query is embedded. ChromaDB finds 5 closest chunks. Only those chunks are sent to Claude with the question. Claude generates a grounded answer citing the specific regulatory source.

Key Result

$ query --mode without-rag
 
"The bill exceeds the recommended recency threshold."
 
$ query --mode with-rag
 
"The bill exceeds the 90-day threshold required under
CBN Guidelines on Mobile Money Services (Revised) 2015,
Section 10.3 for Tier 2/3 KYC onboarding."

Production Issue Caught and Fixed

The first run showed duplicate chunks in retrieval — Chunks 1 and 2 were identical, Chunks 3 and 4 were identical. The deduplication fix: retrieve top-10, compare first 200 characters of each chunk, remove near-duplicates, keep best 5 unique chunks. Unique chunks = better context = better answers.

Vector DB Recommendation

Tech Stack

Python, LangChain, ChromaDB, HuggingFace Embeddings (all-MiniLM-L6-v2), Anthropic API, PyPDFLoader, RecursiveCharacterTextSplitter, python-dotenv