Block V · Automation with AI · Lesson 26
RAG: an AI that knows your company's documents
You'll understand how to make AI answer with your own information: hybrid search, reranking and contextual retrieval. And when it's simpler to put the documents straight into the context with caching.
- 10 min
- 9 animated slides
- 4-question quiz
- Narrated in 6 languages
What you'll see in this lesson
- RAG: have the AI search before answering
RAG (retrieval-augmented generation) finds the useful pieces in your documents and gives them to the AI along with the question.
- First: does it all fit in the context?
If your documents add up to less than about 200,000 tokens, roughly 500 pages, it's often better to include them whole with caching.
- The fast track: the API's file search
OpenAI and Google offer ready-made RAG: you upload the files and the model searches them on its own and cites the source.
- Step 1: chunk the documents
If you build your own RAG, first split the documents into chunks of a few hundred tokens: search and delivery happen chunk by chunk.
- Step 2: embeddings and a vector database
An embedding turns each chunk into a list of numbers that sums up its meaning: similar texts end up close together.
- Hybrid search: words plus meaning
Combine exact-word search (BM25, the one classic search engines use) with meaning search and merge the two lists.
- Reranking: a second, smarter filter
A reranker rereads the question with each candidate and sorts them by real relevance before passing them to the AI.
- Contextual retrieval: each chunk with its context
Before indexing, the AI adds one or two sentences to each chunk explaining which document and section it comes from.
- Summary
Start with the simplest thing that works and add techniques only when your tests show they're needed.
Tools and concepts
- pgvector
- Qdrant
- Reranker
- File search
Sign in with your Google account to access this lesson and the whole course.