Geração Aumentada por Recuperação (RAG)
Combine seus próprios dados com um LLM recuperando documentos relevantes e inserindo-os no prompt para produzir respostas fundamentadas e atualizadas.
Geração Aumentada por Recuperação (RAG) é uma aula grátis de AI Powered SaaS: Stripe + Auth + Billing + Deploy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de AI Powered SaaS: Stripe + Auth + Billing + Deploy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de AI Powered SaaS: Stripe + Auth + Billing + Deploy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
What is RAG?
Retrieval-Augmented Generation gives an LLM access to external knowledge at query time. Instead of relying only on training data, you fetch relevant text and add it to the prompt.
- Answers stay current without retraining
- Reduces hallucinations
- Lets the model cite your private documents
The RAG Pipeline
A typical pipeline has two phases:
- Indexing: split documents into chunks, embed them, store vectors
- Retrieval + generation: embed the query, find similar chunks, feed them to the LLM
Chunking Documents
Split long documents into smaller chunks (often 200-500 tokens) with slight overlap. Good chunking keeps related ideas together so retrieval returns coherent context.
Creating Embeddings
An embedding model turns text into a numeric vector. Similar meanings produce nearby vectors. You embed every chunk during indexing.
const emb = await client.embeddings.create({
model: "text-embedding-3-small",
input: chunkText,
});
const vector = emb.data[0].embedding;Storing Vectors
Vectors live in a vector database such as pgvector, Pinecone, or Qdrant. Each record stores the vector plus metadata (source, title, chunk id) for later filtering and citation.
Retrieving Relevant Chunks
At query time you embed the user question and run a similarity search (cosine distance) to get the top-k closest chunks.
SELECT content FROM docs
ORDER BY embedding <=> $1
LIMIT 5;Building the Augmented Prompt
Insert the retrieved chunks into the prompt as context, then ask the model to answer using only that context.
const prompt = "Context:\n" + chunks.join("\n---\n") +
"\n\nQuestion: " + userQuestion +
"\nAnswer using only the context above.";Citing Sources
Because each chunk carries metadata, you can show citations next to the answer. This builds trust and lets users verify claims against the original document.
Handling No Good Match
If similarity scores are all low, the knowledge base probably lacks the answer. Detect this with a threshold and have the model reply that it does not know, rather than guessing.
Keeping the Index Fresh
When source documents change, re-embed and upsert the affected chunks. Track a content hash per chunk so you only re-index what actually changed, saving embedding cost.
Evaluating RAG Quality
Measure two things: retrieval quality (did we fetch the right chunks?) and answer quality (is the response grounded?). Use a test set of question and answer pairs and check whether the cited chunks contain the supporting facts.
Quick Check
Check your understanding of RAG.
Recap
You learned the full RAG flow:
- Chunk and embed documents into a vector store
- Embed the query and retrieve top-k similar chunks
- Augment the prompt and answer with citations
- Handle low-confidence matches and keep the index fresh
RAG grounds your AI features in your own data without retraining.
Perguntas Frequentes
A aula “Geração Aumentada por Recuperação (RAG)” é grátis?
Sim — o texto completo de “Geração Aumentada por Recuperação (RAG)” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de AI Powered SaaS: Stripe + Auth + Billing + Deploy, atualize para CoddyKit PRO. O curso de AI Powered SaaS: Stripe + Auth + Billing + Deploy inclui 4 aulas no total.
O que vou aprender em “Geração Aumentada por Recuperação (RAG)”?
Combine seus próprios dados com um LLM recuperando documentos relevantes e inserindo-os no prompt para produzir respostas fundamentadas e atualizadas. Você pratica AI Powered SaaS: Stripe + Auth + Billing + Deploy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar AI Powered SaaS: Stripe + Auth + Billing + Deploy?
Nenhuma experiência prévia é necessária. AI Powered SaaS: Stripe + Auth + Billing + Deploy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Geração Aumentada por Recuperação (RAG)”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de AI Powered SaaS: Stripe + Auth + Billing + Deploy?
Sim. Cada aula de AI Powered SaaS: Stripe + Auth + Billing + Deploy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Ajuste fino de LLMs
- Processamento de IA em tempo real
- Monitoramento do desempenho da IA
- Geração Aumentada por Recuperação (RAG)