RAG Live

A real, runnable RAG pipeline — watch every step happen
← Trefolio Learning
Checking status…

This is an educational demo (source on GitHub). The interface is in English, but the knowledge base and the assistant's answers are in Spanish — the demo simulates a Spanish-language patient-support bot for a synthetic healthcare-booking platform. That's intentional: the point is to see how the pipeline works, not to read the sample content.

See Retrieval-Augmented Generation actually work

RAG is how you make an LLM answer from your own documents instead of only what it memorized during training: retrieve the relevant text at request time, hand it to the model as context, and let it answer from that — citing its source. This page walks through a real, runnable RAG pipeline end to end: every chunk, every vector, every retrieval, every metric, computed live in front of you as you use it, not simulated or pre-recorded.

How it works

Two pipelines, run at different times. Every box below becomes a clickable, inspectable step once the demo starts.

Offline — build the index once (or whenever documents change)

📄
Documents
✂️
Chunking
🧮
Embeddings
🗂️
Vector index

Online — every time you ask a question

Question
🧮
Embedding
🔍
Search
🏆
Top-K
📝
Prompt
🤖
LLM
💬
Answer

What you'll explore

1. Build the Index

Watch documents get split into overlapping chunks and turned into vectors by a real embedding model, batch by batch, in real time.

2. Ask a Question

Ask anything — see your question become a vector, get compared against every chunk by cosine similarity, and watch the answer stream in, citing its source. Includes a 2D map of where your question landed relative to every chunk.

3. Explore the Data

Browse the raw documents and chunks, inspect the actual stored vectors, and read the real Python source that produced everything — fetched live from the server, never a hand-written copy.

4. Metrics & Concepts

Real Recall@K and Faithfulness scores (not illustrative numbers), where the latency of your questions actually goes, and a glossary of the concepts this demo uses — and a few it deliberately doesn't.

Concepts you'll see in action

Chunking

Documents are too long to embed or feed to an LLM whole, so they're split into smaller, overlapping word windows — small enough for the embedding model, with enough overlap that an answer never gets cut in half right at a chunk boundary.

Embeddings

A neural network turns each chunk (and later, your question) into a vector — a list of numbers where texts with similar meaning end up close together in that space. That's what lets search work by meaning instead of exact keywords.

Cosine similarity & top-K

Your question's vector gets compared against every chunk's vector by the angle between them (cosine similarity, -1 to 1). Only the K highest-scoring chunks are kept as context — everything else is discarded, even chunks with a decent score.

Prompt assembly

The top-K chunks plus your question get assembled into one block of text sent to the LLM, with instructions to answer only from that context and cite its source — so the model can't quietly fall back on what it memorized during training.

RAG vs fine-tuning

Fine-tuning bakes new knowledge into the model's weights through additional training. RAG keeps the model frozen and injects knowledge at request time instead — easier to keep current (edit a document, rebuild the index) and every answer can cite an exact source.

Recall@K & Faithfulness

Recall@K asks whether the retriever found the right document at all. Faithfulness asks whether the generated answer is actually supported by what it retrieved, or invented something — graded by a second LLM call (LLM-as-a-judge).