AI Engineering · Module 05
RAG: answering from your own data
- Lessons
- 16
- Free
- 1
- Reading
- ~5 h
Your progress
0 / 16 lessons done
Sign in to trackLessons
- RAG: grounding answers in your own documentsFreeMost AI features that answer questions about a company’s products or rules are built this way. Knowing where the facts enter the prompt, and where they can go missing, is how you decide whether to trust an answer and find out why one was wrong.
- Long context or RAG: when to send the whole documentEvery feature that answers from documents starts with this choice, and windows of a million tokens make sending everything look free. The wrong choice can cost dozens of times more per request, or leave you maintaining a search index you never needed.
- Document ingestion: parsing PDFs, pages and tablesA search or assistant feature over company documents can only be as right as the text in its index. A scrambled table raises no error: it turns into a wrong answer weeks later, so engineers who build these features spend much of their time on ingestion.
- Chunking: splitting documents for retrievalEvery RAG system splits its documents before it can search them. Where the cuts fall decides which facts reach the model together, and a rule separated from its exception produces a confident, wrong answer.
- Contextual retrieval: giving each chunk its contextMost retrieval failures in a RAG system start at ingestion, long before the model writes an answer. A short context written once per chunk is one of the cheapest fixes you can make there, and you need to know what it costs and how to prove it worked.
- Hybrid search: combining keywords and vectorsEvery search box and every RAG feature over company data gets two kinds of questions: ones described in words and ones that hinge on an exact code. Hybrid search is the usual way to serve both from one result list.
- Reranking: putting the best passages firstMost production RAG systems retrieve dozens of candidates and keep only a few. The step that picks those few decides what the model reads, so it decides whether the answer is right.
- Query rewriting: improving what gets searchedUsers rarely type a clean search query. In chat and support products the latest message is often a follow-up, so every RAG feature that searches with it finds the wrong passages.
- Citations: showing where each answer came fromAny feature that answers from documents needs a way for a person to check the answer before acting on it. Citations turn “trust the model” into a one-click check, and they make a wrong answer show up instead of slipping through.
- Keeping a RAG index fresh: updates and deletesThe first index you build is correct for one day. After that, every edit, new document and delete has to reach it, or the assistant quotes rules that no longer exist and shows data that should be gone.
- Access control in RAG: who may see whatEvery RAG feature over company data has readers who may see different things: one customer against another, staff against customers, managers against everyone else. If the permission check sits in the wrong place, the model quotes a document to someone who was never allowed to read it.
- Debugging RAG: the common failure modesEvery RAG feature produces wrong answers in production. An engineer who can trace one to the stage that caused it fixes that stage; one who can’t tends to change the prompt or the model and hope.
- Text-to-SQL: answering questions from databasesSooner or later someone asks your AI feature a question whose answer is a number in a database. A model that writes SQL answers it in seconds; without the right limits, it also shows one customer another’s data, or a wrong number that looks right.
- Advanced retrieval: multi-step, graph and agenticEvery RAG system meets questions that one search can’t answer, and every vendor offers a cleverer retrieval loop. Knowing what each loop costs per question, and which questions actually need it, keeps you from paying three times as much for answers that were already right.
- Case: Intercom’s custom reranker for support RAGEvery team that runs RAG on a hosted reranker eventually asks whether to build its own. Intercom’s published case shows what that takes and what it pays back, so you can tell whether your situation is like theirs.
- Design: a support assistant over company docsMost RAG products at work are this shape: many customers, each with their own documents, a person who checks every answer, and a bill that grows with use. The techniques are in the earlier lessons; making them work together, on time and within budget, is the job.
Practise with
Terms this module teaches 54
Open glossaryAgentic retrieval
Retrieval where search is offered to the model as a tool, so the model decides whether, where and how often to search before it answers.
Backtest
Replaying past production traffic through a new version and scoring its output against what is known about those cases, before any live user sees it.
Bi-encoder
A model that turns the query and each document into separate vectors, so document vectors can be made ahead of time and compared with the query vector by a similarity score.
Canary document
A planted test document holding a unique made-up phrase, used to detect when restricted content reaches someone it shouldn’t.
Chunk
A piece of a longer document, cut out so it can be embedded, searched and sent to a model on its own.
Chunk overlap
Text repeated at the end of one fixed-size chunk and the start of the next, so a short passage near a cut appears whole in at least one chunk.
Chunking
Splitting a document into passages small enough to search and send to a model. Each passage gets its own embedding in the index.
Citation (in an AI answer)
A link from one claim in a model’s answer to the passage in a source document that supports it: which document, the exact quoted text and where it sits.
Community detection
An algorithm that finds groups of nodes in a graph that are linked more to each other than to the rest, often in nested levels.
Community summary
A model-written summary of one community in a knowledge graph, made at index time so global questions can read summaries instead of source documents.
Content hash
A short fixed-length value computed from content, such as a SHA-256 digest, that changes whenever the content changes, used to detect what needs reprocessing.
Contextual retrieval
A retrieval technique described by Anthropic: before indexing, a model reads the whole document and writes a short context for each chunk, which is prepended to the chunk for both the embedding and the keyword index.
Cross-encoder
A model that reads a query and one document together as a single input and outputs one relevance score, which is more accurate than comparing separate vectors but needs a full model run for every pair.
Document block
A content block in a Claude API request that holds one whole source document, such as plain text or a PDF, with an optional title and context. With citations enabled, the model can cite sentences from it.
Document ingestion
The pipeline that turns uploaded files and web pages into clean text records a search index can use: fetch, extract, clean, check and attach metadata, then chunk and embed.
Document metadata
Facts stored with a document’s text about where it came from: owner, source, title, updated date and checksum. Search filters, citations and freshness checks depend on it.
Draft job
A queued background task that writes an AI draft reply for one ticket after the customer’s messages go quiet, so the draft is ready before an agent opens the ticket.
Full-text search (PostgreSQL)
PostgreSQL’s built-in keyword search: text is stored as a tsvector of normalised words, indexed with a GIN index, matched against a tsquery and ranked with ts_rank or ts_rank_cd.
Global question
A question about a whole collection, such as its main themes or most common complaints, which no small set of retrieved passages can answer.
Hybrid search
Running keyword search and vector search on the same query and merging their two ranked lists into one, so results can match on exact words or on meaning.
HyDE (hypothetical document embeddings)
A retrieval method in which a model writes a made-up answer to the query, and search uses that answer’s embedding instead of the query’s.
Index reconciliation
A scheduled check that compares a derived index with its source data and repairs differences that change events missed, such as stale or orphaned entries.
Ingestion
The offline job in a retrieval system that turns source documents into indexed chunks: parsing, splitting, optional enrichment, embedding and storing.
Kendall tau
A measure of how closely two orderings of the same items agree, from −1 (exactly reversed) to 1 (identical), based on how many pairs they put in the same order.
Knowledge graph
Facts stored as entities (nodes) and labelled relationships between them, so connected facts can be found by following links.
Long-context prompting
Sending a whole document set to the model in every request, instead of searching it first and sending only the relevant parts.
Mean average precision (MAP)
A ranking measure: for each query, average the precision at each position where a relevant item appears, then average over queries. Higher when every relevant item sits near the top.
Multi-hop question
A question whose answer joins facts from several documents, where finding one fact needs a word or value from another.
Multi-query retrieval
Writing several wordings of the same question, searching with each, and merging the result lists into one.
Multi-step retrieval
Retrieval that searches, has a model read the results and write the next search, and repeats until a stop rule ends the loop.
Namespace (vector store)
A separately stored partition of a vector index; every read and write names exactly one, so data in one can’t be returned by a query on another.
NOT IN SOURCES note
A line a grounded draft adds for the person reviewing it, naming a question the retrieved documents don't answer, instead of guessing an answer for the customer.
OCR (optical character recognition)
Software that reads the text in an image of a page and returns it as characters. It is needed for scans and photos, which have no text layer.
Orphan chunk
A chunk still stored in a search index after the text it came from was edited away or deleted from the source document.
Pairwise ranking loss
A training loss that looks at two items at a time and penalises the model when it scores the item that should rank lower above the one that should rank higher. RankNet is a common form.
Parent-document retrieval
Searching over small chunks, then sending the larger document each matching chunk came from, so the model sees the text around the match.
Permission filter
A search condition built on the server from the signed-in user, applied inside retrieval so only chunks that user may read are returned.
Permission metadata
Fields stored with each chunk that say who may read it, such as its tenant, its visibility and the roles allowed to see it.
Query rewriting
Using a model call to turn a user’s raw message, and the conversation around it, into one or more standalone search queries before retrieval.
RAG (retrieval-augmented generation)
A pattern where the application first searches its own documents for passages relevant to a question, then sends those passages to the model with the question so the answer can rest on them.
Reading order
The order a person would read the words on a page in. A PDF stores characters by position, so an extractor has to rebuild it, and it often guesses wrong on columns and tables.
Regression test
A test that checks a failure fixed earlier has not come back, run after every change to the system.
Reranker
A model that takes a query and a short list of candidates from a first search, scores each candidate against the query, and returns them in a new order so the most relevant come first.
Resolution rate
The share of support conversations an AI agent resolves, as the vendor defines resolved. Used to judge a support assistant by its outcome rather than by its text.
Result-set comparison
Testing generated SQL by running it and a correct query on the same test database and comparing the rows they return, rather than comparing the SQL text. Also called execution accuracy.
Retrieval log
A record per request of who asked, the filter applied and the ids and versions of the chunks returned, kept so an answer can be traced to its sources.
Retrieval miss
A search that fails to return the passage needed to answer, so the model never sees it.
Schema context
The part of a text-to-SQL prompt that describes the tables or views the model may query: columns, notes on their meaning, allowed values and example questions with their SQL.
Source version check
A check, when a stored AI output is about to be shown, that the documents it was made from are still at the versions it recorded; if one changed or was removed, the output is made again.
Stable chunk id
An identifier for a chunk computed from its document, such as the document id plus the chunk’s position, so re-indexing the same document produces the same ids and replaces rows instead of adding them.
Statement timeout
A database or warehouse setting that cancels any statement running longer than a set time, such as PostgreSQL’s statement_timeout or Snowflake’s STATEMENT_TIMEOUT_IN_SECONDS.
Syntax tree
The tree a parser builds from code, with one node for each statement, clause, table, function and value. Checks on the tree can’t be fooled by comments, spacing or extra semicolons the way string checks can.
Text-to-SQL
Turning a question in plain words into a SQL query with a model, then running the query on a database and showing the result.
View (database)
A saved query that can be read like a table. It can show only some columns and rows, and by default it runs with its owner’s rights, not the reader’s.