Learn RAG from the inside out.
See how documents become context, and how context becomes an answer.
Module 01 · Basic RAG
The problem RAG solves
What happens when an LLM needs information it was never trained on?
“Quanto custa a consulta na DentCare?”
“I don't know.” (or presents an invented hallucinated price)
“A consulta odontológica inicial custa R$ 250.”
“Quanto custa a consulta na DentCare?”
“A consulta odontológica inicial custa R$ 250.”
Documents: The External Knowledge Source
RAG starts with unstructured external information. In this interactive guide, we use a Dental Clinic sample document.
A clínica DentCare funciona de segunda a sexta-feira, das 8h às 18h.
Evidence AA consulta odontológica inicial custa R$ 250.
A Dra. Ana é especialista em ortodontia e atende às terças e quintas.
O Dr. Carlos realiza tratamentos de canal e procedimentos de endodontia.
Cancelamentos devem ser feitos com pelo menos 24 horas de antecedência.
A clínica aceita pagamentos via PIX, cartão de crédito e cartão de débito.
document = """
A clínica DentCare funciona de segunda a sexta-feira, das 8h às 18h.
A consulta odontológica inicial custa R$ 250.
A Dra. Ana é especialista em ortodontia e atende às terças e quintas.
O Dr. Carlos realiza tratamentos de canal e procedimentos de endodontia.
Cancelamentos devem ser feitos com pelo menos 24 horas de antecedência.
A clínica aceita pagamentos via PIX, cartão de crédito e cartão de débito.
"""
Chunking: Splitting Large Documents
Large documents need smaller, manageable pieces to fit into vector search and context windows.
Generated Chunks (0)
“A consulta odontológica inicial custa 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.
“Quanto custa uma consulta?”
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.
“A consulta odontológica inicial custa R$ 250.”
“A consulta odontológica inicial custa 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.