← Back
RAG · k=5
Production · KUB

RAG Knowledge System

Sole architect & developer · 2025–2026

5 min → 30 sec document lookup

Problem

KUB's 17-person business analytics team relied on 20+ internal operational documents to answer day-to-day questions. When the document owner was unavailable, tracking down an answer took anywhere from five minutes to over an hour. External AI tools were off the table entirely — KUB's data governance policy prohibits sending internal operational data outside the network.


System Design

The core constraint — no external API calls — shaped every architectural decision. The entire system runs locally using Ollama as the LLM host. Nothing leaves KUB's network.

Retrieval runs two approaches in parallel: BM25 for exact keyword matching and dense vector search for semantic similarity. Results from both paths are pooled into up to 40 candidates, deduplicated by content hash, then passed to a cross-encoder reranker that scores each candidate against the original query before narrowing to the top five. The cross-encoder is slower than cosine similarity alone but substantially more accurate for operational text where precise terminology matters.

Every response streams to the user in real time. All interactions are logged through LangSmith, building a dataset for future retrieval improvements.


What I Built


Architecture

Click any node to learn more.

User queryhybrid retrievalBM25Exact keyword matchVector searchSemantic similarityChromaDBCandidate poolUp to 40 · hash dedupedCross-encoder rerankerTop 5 resultsLocal LLM (Ollama)No external API callsStreamed answerLangSmithInteraction log

Engineering Challenge

The initial retrieval version relied primarily on semantic search, and it failed on domain-specific terminology. KUB's operational documents use precise technical vocabulary that semantic search alone misrepresented. Adding BM25 as a parallel path and tuning the fusion weights between the two approaches was the fix that made retrieval reliable.


Evaluation

Answer quality was measured using the RAGAS framework, establishing an objective baseline for tracking improvement across iterations rather than relying on qualitative judgment.


Results

<10s

Per query (was 5+ min)

17

Analysts using it daily

0

External API calls

Document lookups that previously took five or more minutes now complete in under 10 seconds. Seventeen analysts use the system daily across 20+ operational documents, all running without a single external API call.


Stack

LangChainChromaDBOllamaBM25Cross-encoderRAGASLangSmithDockerStreamlitPython
GitHub

Next Project

DeepAR Gas Forecasting