Building with AI APIs · ProLesson 4 of 6 · 10 min
Answer from your own documents (RAG basics)
Retrieve the right passages, ground the answer in them, cite the source, and say "I don't know" when it isn't there.
Models don't know your company's policies, your product manual or last week's meeting notes. Retrieval-augmented generation (RAG) fixes that: when a question comes in, you find the most relevant passages from your own documents and give them to the model along with the question, so it answers from your material instead of guessing.
The four steps
- Split documents into passages (a few paragraphs each), keeping titles and section headings with each one.
- Index them so you can search by meaning (embeddings) and by keywords. Combining both usually works best.
- Retrieve the top few passages for each question.
- Generate an answer that uses only those passages and cites which ones it used.
Unlock the rest of this lesson with Pro
In this lesson
- The four steps
- What goes wrong, and the fixes
- Hands-on practice with personal feedback from Arvid
- A quick quiz to check what you learned
Unlock this lesson and every lesson in the Foundations, Advanced and Expert levels and all courses, plus certificates and a monthly allowance of AI practice, for $12/month.
Start free, upgrade anytime
Already have an account? Log in