See how retrieval becomes an answer.
Follow information through a Basic RAG system, inspect every transformation, and connect each visual step to code.
See → Understand → Interact → Code → Connect
One connected system, six visible stages.
Use this map first. The guided sections below unpack each stage without losing the full flow.
- 01DocumentExternal knowledge enters the system.
- 02ChunksThe source becomes retrievable units.
- 03EmbeddingsMeaning is represented as vectors.
- 04SearchThe closest evidence is ranked.
- 05ContextSelected evidence forms the prompt.
- 06AnswerThe model responds from evidence.
The problem RAG solves
What happens when an LLM needs information it was never trained on?
“How much does a consultation at DentCare cost?”
“I don't know.” (or presents an invented hallucinated price)
“The initial dental consultation costs R$ 250.”
“How much does a consultation at DentCare cost?”
“The initial dental consultation costs R$ 250.”
Documents: The External Knowledge Source
RAG starts with unstructured external information. In this interactive guide, we use a Dental Clinic sample document.
DentCare Clinic is open from Monday to Friday, from 8 AM to 6 PM.
Evidence AThe initial dental consultation costs R$ 250.
Dr. Ana is an orthodontics specialist and works on Tuesdays and Thursdays.
Dr. Carlos performs root canal treatments and endodontics procedures.
Cancellations must be made at least 24 hours in advance.
The clinic accepts payments via PIX, credit card, and debit card.
document = """
DentCare Clinic is open from Monday to Friday, from 8 AM to 6 PM.
The initial dental consultation costs R$ 250.
Dr. Ana is an orthodontics specialist and works on Tuesdays and Thursdays.
Dr. Carlos performs root canal treatments and endodontics procedures.
Cancellations must be made at least 24 hours in advance.
The clinic accepts payments via PIX, credit card, and debit card.
"""
Chunking: Splitting Large Documents
Large documents need smaller, manageable pieces to fit into vector search and context windows.
Generated Chunks (0)
“The initial dental consultation costs R$ 250.”
Resolving current chunk and retrieval status…chunks = split_text(
document,
chunk_size=140,
overlap=30,
)
Embeddings: Converting Meaning into Vectors
This browser lesson uses simulated educational feature vectors to demonstrate the retrieval mechanism. It does not run a real embedding model.
Query Embedding: Vectorizing the Question
The user's question must be converted into the exact same vector space so we can compare it to document chunks.
query_embedding = embed(query)
Similarity Search: Comparing Vectors
Which chunks point in a similar direction to the query in the simulated educational vector space?
Ranked Chunks by Dense Cosine Similarity
Select a row to compare its geometryGeometric cosine comparison
Query ↔ top-ranked chunk
scores = cosine_similarity(
query_embedding,
chunk_embeddings
)
ranked_chunks = sort_by_score(scores)
Top-K Retrieval
Top-K selects the highest-ranked dense results that will enter the context.
Retrieved Chunks Selection (Top K = 3)
results = similarity_search(
query_embedding,
chunk_embeddings,
k=3,
)
Context: Assembly of Retrieved Knowledge
Retrieved chunks become context.
Crucial Distinction: The LLM does not search the vector database itself. The Retriever performs the search and places the facts into the Context buffer.
context = "\n\n".join(
chunk.text for chunk in results
)
Augmented Prompt: Constructing the Payload
Now we augment the prompt by uniting system instructions, retrieved context, and the user's question.
Answer using only the provided context below. If you don't know, state clearly that information is unavailable.
“How much does a consultation cost?”
prompt = build_prompt(
context=context,
query=query,
)
Simulated Generation & Grounding
Only now is a deterministic simulated answer produced. It is marked grounded only when its complete canonical evidence is present in the active context.
“The initial dental consultation costs R$ 250.”
“The initial dental consultation costs R$ 250.”Currently in Chunk 02 · Included in context
answer = llm.generate(prompt)
Complete Basic RAG Pipeline
Now that every concept has been learned individually, see how the Basic RAG components connect.
Scroll horizontally inside a pipeline row when needed →
You now know the components.
Continue in the Lab to experiment, adjust parameters, break assumptions, and inspect the complete pipeline as a debugger.
Future modules will cover Hybrid Retrieval, Reranking, and Evaluation as separate advanced topics.