Retrieval-Augmented Generation (RAG) with Azure AI Search
Retrieval-Augmented Generation (RAG) with Azure AI Search
1 Overview: Teaching the Model What It Doesn't Know
A model knows only what it saw in training. It has never read your product manuals, your internal policies, last quarter's report, or the ticket a customer opened yesterday — and when asked about them it will often produce a confident hallucination rather than admit ignorance. RAG, Retrieval-Augmented Generation, closes that gap without retraining anything. The idea is simple and powerful: before the model answers, retrieve the most relevant passages from your own data and put them into the prompt, then instruct the model to answer from that supplied context and cite it. The model's fluency meets your organization's facts.
This tutorial builds the whole pipeline in .NET. You will see why enterprises reach for RAG over fine-tuning; how a vector database and embeddings make retrieval by meaning possible; how Azure AI Search provides that retrieval as a managed service; how to create an index and define its fields and schema; the difference between keyword and semantic search and why hybrid usually wins; how to integrate search results into a RAG pipeline behind the same IChatService from earlier tutorials; how to enhance prompts with retrieved context; and how to enforce grounding and return citations so answers are trustworthy and verifiable.
2 Learning Objectives
- Explain why enterprises need RAG and when it beats fine-tuning or a bigger context window.
- Describe how a vector database, embeddings, and vector search retrieve passages by meaning.
- Use Azure AI Search as a retrieval backend, creating an index and defining its fields and schema.
- Contrast keyword search, semantic search, and hybrid search, and choose the right mode.
- Integrate search results into a RAG pipeline in .NET, retrieving context before calling the model.
- Enhance prompts with retrieved context and a grounding system prompt so the model answers only from sources.
- Return grounding and citations so users can trace and verify every claim in an answer.
3 Prerequisites
- Tutorial 11: the embeddings API — turning text into vectors and comparing them with cosine similarity.
- Tutorials 13–14: an IChatService behind DI with resilience and logging, exposed over a streaming web endpoint.
- C# comfort with async/await, records, and calling an Azure SDK client (you will add the Azure AI Search client).
- An Azure OpenAI resource with a chat deployment and an embedding deployment (text-embedding-3-small), plus an Azure AI Search service to create an index in.
4 Key Concepts: Retrieve, Augment, Generate
RAG is three steps named in its expansion. Retrieve: given the user's question, find the most relevant passages from your indexed data. Augment: insert those passages into the prompt as context, alongside a system prompt telling the model to answer only from them. Generate: the model produces an answer grounded in the supplied passages, with citations back to the sources. Everything in this tutorial is an elaboration of those three steps and the machinery that makes retrieval fast and accurate.
| Step | What happens | Key technology |
|---|---|---|
| Retrieve | Find passages relevant to the question | Azure AI Search (keyword + vector + semantic ranker) |
| Augment | Build a prompt: system rule + retrieved context + question | Prompt construction in the service layer |
| Generate | Model answers from the context and cites sources | Chat completion with a grounding system prompt |
Two ingredients from earlier tutorials power retrieval. Embeddings turn both your documents and each question into vectors, so similarity of meaning becomes distance in vector space; a vector database indexes those vectors and answers nearest-neighbor queries quickly. But retrieval by meaning alone misses exact terms — a product code, an error number — which is where keyword search and the combination called hybrid search come in. Azure AI Search bundles all of it, so most of your work is preparing data well (chunking, schema) and constructing the augmented prompt carefully.
5 Deep Dive 1: Why Enterprises Need RAG
Enterprises need answers grounded in private, current, verifiable knowledge, and a raw model provides none of those. Its training data is frozen at a cutoff, so it cannot know this morning's policy change. It never saw your internal documents at all. And it cannot show its work — an ungrounded answer is a claim with no source, unusable where being right and being checkable both matter. RAG addresses all three: it injects current, private passages at question time, and it makes every answer traceable through citations.
The natural question is why not fine-tune the model on company data instead. Fine-tuning changes a model's style and behavior, but it is a poor and expensive way to inject facts: it must be redone whenever the data changes, it blurs rather than stores exact information (so it still hallucinates specifics and cannot cite), and it risks memorizing sensitive data into weights. RAG keeps knowledge in an index you can update in seconds, add and remove documents from, apply access control to, and cite precisely. As a rule: fine-tune to change how the model behaves; use RAG to change what it knows.
| Need | Raw model | Fine-tuning | RAG |
|---|---|---|---|
| Private / internal knowledge | No | Baked in, hard to update | Injected at query time, always current |
| Fresh / changing data | Frozen at cutoff | Stale until retrained | Update the index instantly |
| Citations / verifiability | None | None | Every claim traces to a source |
| Access control per document | N/A | No | Filter retrieval by permissions |
| Cost to update knowledge | Retrain | Retrain | Re-index a document |
6 Deep Dive 2: Vector Databases and Retrieval by Meaning
Keyword systems match words; RAG needs to match meaning, because a user asking 'how do I get my money back?' should find a passage titled 'Refund Policy' that shares not one keyword with the question. Embeddings make this possible: the embedding API maps text to a vector such that similar meanings produce nearby vectors. Embed the refund policy and embed the question, and their vectors sit close together even with no shared words. Closeness is measured by cosine similarity — the cosine of the angle between vectors, near 1 for very similar meaning.
A vector database is the store built to exploit this. It indexes embedding vectors and answers the query 'give me the k nearest vectors to this one' efficiently — the operation called vector search — even across millions of vectors, using approximate nearest-neighbor algorithms so it stays fast at scale. Conceptually you could compute cosine similarity against every stored vector yourself (as in tutorial 11), but that is linear and collapses at scale; a vector database is what makes retrieval by meaning practical in production.
7 Deep Dive 3: Azure AI Search — Index, Fields, and Schema
You could run a vector database yourself, but Azure AI Search provides retrieval as a managed service that does keyword, vector, and hybrid search plus a semantic ranker in one place — which is why it is a common RAG backend. Its central object is the index: a searchable collection of documents. Before you add anything you define the index's schema — the set of fields, each with a name, a type, and attributes controlling how it behaves. Getting the schema right is most of the setup work.
A field's attributes decide its role. Searchable makes a text field full-text searchable (keyword search). A field typed as a collection of singles with a vector-search configuration holds an embedding for vector search. Filterable lets you restrict results (by category, or by an allowed-users field for access control). Retrievable means the value is returned with results — your content and any source id for citations must be retrievable. Key marks the unique document id. A typical RAG index carries at least: an id (key), the chunk content (searchable, retrievable), a content vector (vector-searchable), a title or source path (retrievable, for citations), and often filter fields.
using Azure.Search.Documents.Indexes;
using Azure.Search.Documents.Indexes.Models;
// One searchable document = one chunk of a source file.
var index = new SearchIndex("knowledge-index")
{
Fields =
{
new SimpleField("id", SearchFieldDataType.String) { IsKey = true },
new SearchableField("content") { IsFilterable = false }, // full-text keyword search
new SearchableField("title") { IsFilterable = true }, // shown in citations, filterable
new SimpleField("sourcePath", SearchFieldDataType.String) { IsFilterable = true }, // citation link
new VectorSearchField("contentVector", 1536, "vector-profile") // embedding for vector search
},
// Vector search + semantic ranking configuration attach to the index.
VectorSearch = new() { /* HNSW algorithm + profile named 'vector-profile' */ },
SemanticSearch = new() { /* semantic configuration naming title + content */ }
};
var indexClient = new SearchIndexClient(endpoint, credential);
await indexClient.CreateOrUpdateIndexAsync(index);
Before indexing you must chunk your documents — split them into passage-sized pieces (a few hundred tokens, often with slight overlap) — and embed each chunk. Chunking matters because retrieval returns whole documents' worth of noise if chunks are too big, and loses context if too small; passage-sized chunks give focused, citable context that fits the prompt budget. Each chunk becomes one index document: its text in content, its embedding in contentVector, and its origin in title/sourcePath so the answer can cite it.
8 Deep Dive 4: Keyword vs Semantic Search — and Hybrid
Retrieval has two complementary strategies, and understanding when each wins is central to good RAG. Keyword search (lexical) matches the actual terms of the query against the indexed text, ranked by algorithms such as BM25. It is unbeatable for exact strings — a product code 'RX-4400', an error like 'ORA-00942', a person's name, an acronym — because those must match literally, and it needs no embedding. Its weakness is vocabulary mismatch: 'get my money back' and 'refund' share no words, so keyword search misses the connection.
Semantic search retrieves by meaning. In Azure AI Search this means vector search over embeddings, optionally sharpened by the semantic ranker, which re-scores the top candidates with a language model and can return concise captions. Semantic search handles paraphrase and synonym effortlessly — the refund case just works — but can underperform on exact tokens, sometimes returning a passage that is topically close yet misses the specific code the user typed. The strengths are mirror images, which points straight at the answer: use both.
| Query type | Keyword wins | Semantic wins |
|---|---|---|
| Exact code / ID / acronym | Yes — literal match | May miss the exact token |
| Paraphrase / synonym | Misses (no shared words) | Yes — matches meaning |
| Natural-language question | Partial | Yes |
| Rare proper noun | Yes | Sometimes |
Hybrid search — issuing keyword and vector search together and fusing the results, then optionally applying the semantic ranker — is the recommended default for RAG because real user questions mix exact terms and natural language. Azure AI Search performs the fusion for you; your job is to supply both the query text and the query embedding and enable the semantic configuration. This is the retrieval quality that sets your RAG system's ceiling, so it is worth tuning.
9 Ecosystem and Tools
| Technology | Role in the RAG pipeline |
|---|---|
| Azure AI Search | The retrieval backend: index, keyword + vector + hybrid search, semantic ranker |
| Azure.Search.Documents (NuGet) | The .NET client for creating indexes, uploading documents, and querying |
| Azure OpenAI embeddings (text-embedding-3-small) | Turns document chunks and questions into vectors for vector search |
| Azure OpenAI chat deployment | Generates the grounded answer from the augmented prompt |
| IChatService (tutorials 13–14) | Where the RAG pipeline lives — retrieval then generation, behind the same interface |
| Integrated vectorization / indexers (Azure AI Search) | Optional: let the service chunk and embed during indexing instead of doing it in code |
| Semantic Kernel / other orchestrators | Higher-level frameworks (later tutorials) that provide RAG 'memory' connectors over the same search service |
You can build the pipeline at two levels. Hand-rolled, you chunk and embed documents in your own code, upload them to the index, and at query time embed the question, run a hybrid query, and construct the prompt — full control, and the version this tutorial teaches so the mechanics are visible. Higher up, Azure AI Search's integrated vectorization and indexers can chunk and embed for you during ingestion, and orchestration frameworks wrap retrieval as reusable 'memory'. Understand the hand-rolled pipeline first; the conveniences then read as shortcuts over parts you already know.
10 Use Cases
- Internal knowledge assistant: employees ask natural-language questions and get answers grounded in policies, wikis, and runbooks, each with a citation to the source page.
- Customer support deflection: a help widget answers from the product documentation and knowledge base, citing articles so users can read more.
- Contract and document Q&A: upload a set of contracts and ask 'what is the termination notice period?', getting the exact clause with a citation.
- Technical support with exact codes: hybrid search shines when a user pastes an error code and describes the symptom in words — keyword catches the code, vector catches the description.
- Onboarding helper: new staff query scattered documentation through one assistant instead of hunting across systems.
- Research assistant over a report library: ask across many documents and get a synthesized, cited answer rather than a list of links.
- Compliance-aware search: retrieval filtered by the user's permissions so answers only ever draw on documents they are allowed to see.
The common thread: a body of private or specialized text, natural-language questions over it, and a hard requirement that answers be correct and verifiable. Wherever those three meet, RAG is the fitting pattern — and the citation requirement is usually what rules out an ungrounded model.
11 Code Examples
These examples build the query-time RAG pipeline in .NET: embed the question, run a hybrid search against Azure AI Search, construct a grounded prompt, and generate a cited answer — all inside the IChatService from earlier tutorials. Indexing (schema in deep dive 3, plus chunk-embed-upload) is assumed done.
using Azure.Search.Documents;
using Azure.Search.Documents.Models;
public sealed record Passage(string Content, string Title, string SourcePath);
// Embed the question, then run keyword + vector search in one hybrid query.
async Task<IReadOnlyList<Passage>> RetrieveAsync(string question, int k, CancellationToken ct)
{
// Same embedding model used when indexing (deep dive 2's rule).
OpenAIEmbedding qEmbedding =
await _embedder.GenerateEmbeddingAsync(question, cancellationToken: ct);
var options = new SearchOptions
{
Size = k,
VectorSearch = new()
{
Queries = { new VectorizedQuery(qEmbedding.ToFloats())
{ KNearestNeighborsCount = k, Fields = { "contentVector" } } }
},
// Enable semantic ranking over the fused hybrid results.
QueryType = SearchQueryType.Semantic,
SemanticSearch = new() { SemanticConfigurationName = "default-semantic" }
};
options.Select.Add("content");
options.Select.Add("title");
options.Select.Add("sourcePath");
// Passing both the text (question) and the vector query makes it hybrid.
SearchResults<SearchDocument> results =
await _search.SearchAsync<SearchDocument>(question, options, ct);
var passages = new List<Passage>();
await foreach (SearchResult<SearchDocument> r in results.GetResultsAsync())
{
passages.Add(new Passage(
(string)r.Document["content"],
(string)r.Document["title"],
(string)r.Document["sourcePath"]));
}
return passages;
}
// Number each passage so the model can cite it as [1], [2], ...
static (string context, IReadOnlyList<Passage> sources) BuildContext(IReadOnlyList<Passage> passages)
{
var sb = new System.Text.StringBuilder();
for (int i = 0; i < passages.Count; i++)
{
sb.AppendLine($"[{i + 1}] {passages[i].Title}");
sb.AppendLine(passages[i].Content);
sb.AppendLine();
}
return (sb.ToString(), passages);
}
const string GroundingSystemPrompt =
"You are a knowledge assistant. Answer ONLY using the numbered sources below. " +
"Cite the sources you use with their bracket numbers, e.g. [1]. " +
"If the sources do not contain the answer, say you don't know — do not use outside knowledge.";
public async Task<GroundedAnswer> AskGroundedAsync(string question, CancellationToken ct = default)
{
// 1. Retrieve
IReadOnlyList<Passage> passages = await RetrieveAsync(question, k: 5, ct);
if (passages.Count == 0)
return new GroundedAnswer("I couldn't find anything relevant to answer that.", Array.Empty<Passage>());
// 2. Augment
(string context, var sources) = BuildContext(passages);
var messages = new ChatMessage[]
{
new SystemChatMessage(GroundingSystemPrompt),
new UserChatMessage($"Sources:\n{context}\nQuestion: {question}")
};
// 3. Generate (reusing tutorial 13's resilient call; low temperature for grounding)
var options = new ChatCompletionOptions { Temperature = 0.1f, MaxOutputTokenCount = 500 };
ChatCompletion completion = await CompleteResilientlyAsync(messages, options, ct);
// Return the answer AND the sources so the UI can render citations.
return new GroundedAnswer(completion.Content[0].Text, sources);
}
public sealed record GroundedAnswer(string Text, IReadOnlyList<Passage> Sources);
12 Step by Step: A Grounded, Cited Assistant
This walkthrough builds an end-to-end RAG assistant: index a small document set, then answer questions from it with citations, streamed into the tutorial-14 page.
- Provision: an Azure AI Search service plus your existing Azure OpenAI chat and embedding deployments. Add the Azure.Search.Documents package to the project.
- Create the index: define the schema from deep dive 3 (id key, searchable content, retrievable title and sourcePath, a 1536-dim contentVector, plus vector and semantic configurations) and call CreateOrUpdateIndexAsync.
- Prepare data: take a handful of documents (policies, FAQs, a manual) and chunk them into passage-sized pieces of a few hundred tokens with slight overlap.
- Embed and upload: for each chunk, call the embedding deployment, then upload a document per chunk (id, content, title, sourcePath, contentVector) with the index's upload/merge API.
- Implement retrieval (Example 1): embed the incoming question with the same model and run a hybrid query — text plus vector — with semantic ranking, selecting content, title, and sourcePath.
- Build the grounded prompt (Example 2): number the retrieved passages, and write a system prompt that forbids outside knowledge and requires bracket citations.
- Generate (Example 3): call the chat deployment at low temperature through tutorial 13's resilient wrapper, returning both the answer text and the source list as a GroundedAnswer.
- Expose it: add AskGroundedAsync to IChatService and a web endpoint that returns the answer plus a citations array; render citations under the answer in the tutorial-14 page, linking each [n] to its sourcePath.
- Test grounding: ask a question whose answer is in your documents and confirm the answer cites the right source; then ask something absent from the documents and confirm the assistant says it doesn't know rather than inventing an answer.
- Test hybrid retrieval: ask once using an exact code or name from a document and once by paraphrase, and confirm both retrieve the correct passage — keyword catching the code, vector catching the paraphrase.
- Stream it: switch generation to the streaming path from tutorial 14 so the grounded answer types into the page, then append the citations when the stream completes.
13 Limitations and Caveats
- SDK naming caveat: the Azure.Search.Documents SDK's field and query construction (SearchableField, VectorSearchField, VectorizedQuery, SemanticSearch/VectorSearch configuration objects) varies across versions — the examples are correct in shape and intent, but verify exact type and property names against the current package before relying on them.
- Retrieval sets the ceiling: if the right passage is not retrieved, the answer cannot be correct no matter the model or prompt. Most RAG quality work is retrieval and chunking work, not prompt tweaking.
- Chunking is a real design decision: chunks too large dilute relevance and waste the context window; too small lose the surrounding meaning. Passage-sized with slight overlap is a starting point, not a universal answer.
- Grounding is instructed, not guaranteed: a model told to answer only from context will usually comply, but can still leak training knowledge or miscite. Low temperature, a firm system prompt, and evaluation reduce but do not eliminate this.
- Citations can be wrong: the model may attribute a claim to the wrong bracket number. Treat citations as strong hints to verify, and consider post-checking that cited passages actually support the claim.
- Context window limits how many passages you can include; more retrieval is not always better, and stuffing the prompt raises cost and can bury the relevant passage. Tune k.
- Access control lives in retrieval: you must filter the index by the user's permissions, because the model will quote any context it is given regardless of who is asking.
- Freshness depends on your indexing pipeline: RAG is only as current as the last time you re-indexed changed documents — an ingestion schedule or change feed is part of the system, not an afterthought.
- Embedding-model consistency is mandatory: index and query must share the same embedding model, so changing it forces a full re-embed and re-index.
14 Best Practices
- Default to hybrid search with the semantic ranker; reach for pure keyword or pure vector only when you have measured a reason to.
- Invest in chunking and schema before prompt tuning — retrieval quality dominates RAG outcomes.
- Always ground explicitly: a system prompt that says 'answer only from the sources, cite them, and say you don't know otherwise' — and keep temperature low.
- Return sources with every answer and render citations in the UI; verifiability is usually the whole point of choosing RAG.
- Filter retrieval by the user's permissions so answers never draw on documents the user cannot access.
- Keep index and query on the same embedding model, and version your index so a model change is a deliberate re-index, not a silent regression.
- Log retrieved passages and scores per query; it is the fastest way to tell a retrieval failure from a generation failure.
- Tune k (number of passages) against your context window and cost — enough to cover the answer, few enough to keep the relevant passage prominent.
| Common mistake | Do this instead |
|---|---|
| Pure vector search only, missing exact codes | Hybrid search so keyword catches literal terms and vector catches meaning |
| Huge chunks (whole documents) per index entry | Passage-sized chunks with slight overlap, focused and citable |
| No grounding instruction, so the model free-associates | A firm system prompt: answer only from sources, cite, or say you don't know |
| Answer with no sources returned | Return and render citations so users can verify every claim |
| Different embedding models for index and query | One embedding model everywhere; re-index on any change |
| Blaming the model for wrong answers | Log retrieved passages first — most 'model' errors are retrieval errors |
20 Summary
- RAG retrieves relevant passages from your data, augments the prompt with them, and generates a grounded, cited answer — supplying private, current, verifiable knowledge without retraining. Fine-tune for behavior; use RAG for knowledge.
- Embeddings map text to vectors so meaning becomes distance; a vector database indexes those vectors and returns nearest neighbors fast, enabling retrieval by meaning at scale — with index and query bound to the same embedding model.
- Azure AI Search provides retrieval as a managed service; its index is defined by a field schema (key, searchable content, a vector field, retrievable citation fields, filterable access-control fields), and documents are passage-sized chunks.
- Keyword search nails exact terms, semantic search nails meaning, and hybrid search fuses both with a semantic ranker — the recommended default because real questions mix codes and natural language.
- The .NET pipeline lives behind IChatService: embed the question, run hybrid search, build a grounded prompt with numbered sources, and generate at low temperature — returning the answer plus its sources.
- Grounding (answer only from sources) is enforced by a firm system prompt and low temperature but not guaranteed; citations (references back to passages) make answers verifiable, and retrieval quality — not the model — sets the system's ceiling.
RAG is the workhorse pattern of enterprise GenAI, and you have now built it end to end: retrieval by meaning over an Azure AI Search index, hybrid search for the best of keyword and semantic, and a grounded, cited answer streamed into the web app from earlier tutorials — all behind the same clean interface. The disciplines that make it production-grade are the retrieval ones: chunk well, search hybrid, ground firmly, cite honestly, filter by permission, and keep the index fresh. With grounded answers in hand, the course now turns to the platform that unifies these building blocks, as the next tutorial introduces Azure AI Foundry.
21 Next Steps
Next tutorial: Azure AI Foundry (azure-ai-foundry). You have assembled AI capabilities piece by piece — deployments, embeddings, function calling, and now retrieval. Azure AI Foundry is the unified platform for building, evaluating, and managing these AI applications: model catalog and deployments, playgrounds, evaluation, and the tooling that ties the building blocks of this course into a managed workflow.
- Practice: build the full pipeline — create the index, chunk and embed a small document set, and answer questions with citations, confirming an out-of-scope question yields an honest 'I don't know'.
- Practice: run the same question as an exact code and as a paraphrase, and log the retrieved passages to see keyword and vector each earn their keep in hybrid search.
- Practice: deliberately vary chunk size (very large vs very small) and observe the effect on retrieval relevance and answer quality.
- Practice: add a permission filter to retrieval and verify that a restricted document never appears in answers for an unauthorized user.
- Read: the official documentation for 'Azure AI Search', 'Vector search in Azure AI Search', 'Semantic ranking', 'Retrieval-Augmented Generation (RAG) in Azure AI Search', and the Azure.Search.Documents .NET client library.
15 Quiz: RAG with Azure AI Search
Pick an answer for each question, then press Check answer. (Notes are disabled in this tab.)
1. What does RAG stand for and do?
2. Why do enterprises typically choose RAG over fine-tuning to give a model company knowledge?
3. How do embeddings enable retrieval by meaning?
4. What is a vector database's core job?
5. In Azure AI Search, what is an index?
6. Which field attribute must a chunk's content and source id have so they can appear in citations?
7. When does keyword search outperform semantic search?
8. What is hybrid search?
9. What does the semantic ranker in Azure AI Search do?
10. In the RAG pipeline, what does the 'augment' step do?
11. What is a grounding system prompt responsible for?
12. Why should retrieved passages be numbered when building the prompt?
13. The primary quality ceiling of a RAG system is set by which step?
14. Why must index and query use the same embedding model?
15. A user asks about a document they are not permitted to see. What must the RAG system do?
16 Exam: Written Questions
Try answering each question yourself before expanding the model answer.
1. Explain the three steps of RAG and what each contributes to a trustworthy answer.
2. Make the case for RAG over fine-tuning when the goal is to give a model access to company knowledge.
3. Describe how embeddings and a vector database enable retrieval by meaning, and why brute-force similarity is insufficient at scale.
4. You are designing an Azure AI Search index for RAG. Walk through the fields you would define and the attributes each needs.
5. Contrast keyword and semantic search with concrete examples, and explain why hybrid search is the RAG default.
6. Explain the role of chunking in RAG and the consequences of chunks that are too large or too small.
7. Trace the query-time RAG pipeline in .NET from question to grounded answer, naming what happens at each stage.
8. What does a grounding system prompt contain, and why is grounding instructed rather than guaranteed?
9. Why is retrieval, not generation, usually the limiting factor in RAG quality, and how does that shape where you spend effort?
10. Describe how access control and data freshness are handled in a RAG system, and why each is part of the architecture rather than an add-on.
11. How does this tutorial's RAG pipeline fit the IChatService and web architecture from tutorials 13 and 14?
12. A stakeholder wants to include the top 50 retrieved passages 'to be safe'. Explain the trade-offs and give your recommendation.
13. What is the difference between keyword, vector, and hybrid search in terms of what they match, and how would you decide to deviate from hybrid as the default?
14. Explain grounding and citations as distinct concepts and how each is implemented in the pipeline.
15. Outline how you would evaluate and debug a RAG assistant that sometimes gives wrong answers.
17 Flashcards
Click a card to reveal the back.
RAG (Retrieval-Augmented Generation)
RAG vs fine-tuning
Why enterprises need RAG
Embedding + cosine similarity
Vector database
Azure AI Search
Index field attributes
Keyword search
Semantic search
Hybrid search
Semantic ranker
Chunking
Grounding system prompt
Citations
Retrieval is the quality ceiling
18 Interview Questions and Answers
1. What is RAG and why has it become the dominant enterprise GenAI pattern?
2. When would you fine-tune instead of, or in addition to, using RAG?
3. Walk me through how retrieval by meaning actually works.
4. How do you set up an index for RAG in Azure AI Search?
5. Explain keyword vs semantic search and why you'd combine them.
6. What's the biggest lever on RAG answer quality, and how does that change how you work?
7. How do you make a RAG answer trustworthy — cover grounding and citations.
8. Where do access control and freshness fit in a RAG system?
9. Someone reports the assistant gave a confidently wrong answer. How do you investigate?
10. How do you decide how many passages (k) to retrieve?
11. What's the significance of index and query using the same embedding model?
12. How does RAG integrate with the service and web architecture you'd already have?
13. What are the failure modes and limits of RAG you'd flag to a team adopting it?
14. Would you build the RAG pipeline by hand or use higher-level tooling like integrated vectorization or an orchestration framework?
15. How would you evaluate a RAG system before and after shipping?
19 Glossary
- RAG
- Retrieval-Augmented Generation: retrieve relevant passages from your data, augment the prompt with them, and generate a grounded, cited answer — without retraining the model.
- Retrieval
- The step that finds the most relevant passages for a question from an index, before any generation happens. Sets the quality ceiling of a RAG system.
- Grounding
- Basing the model's answer on supplied source passages rather than training memory, so claims trace to real documents. Instructed via the system prompt, not guaranteed.
- Citation
- A reference in the answer (e.g. [1]) pointing back to the source passage a claim came from, enabling users to verify it.
- Hallucination
- Fluent but false model output; RAG reduces it for knowledge questions by supplying real passages and instructing the model to answer only from them.
- Vector database
- A store that indexes embedding vectors and returns the nearest ones to a query vector efficiently, making vector search practical at scale.
- Embedding
- A numeric vector capturing the meaning of text, so semantically similar texts sit close together in vector space.
- Vector search
- Finding the nearest embedding vectors to a query vector by similarity — retrieval by meaning rather than by matching words.
- Cosine similarity
- A measure of how closely two vectors point in the same direction; near 1 means very similar meaning. The usual vector-search metric.
- Azure AI Search
- Azure's managed search service supporting keyword, vector, and hybrid retrieval with a semantic ranker; a common RAG retrieval backend.
- Index
- The searchable collection of documents in Azure AI Search, defined by a field schema; you query it to retrieve passages.
- Field
- A named, typed property of an index document (content, title, vector) with attributes like searchable, filterable, retrievable, or key.
- Schema
- The index definition — its fields, their types, and attributes — describing the shape and searchability of each document.
- Keyword search
- Lexical retrieval matching the query's literal terms against the text (BM25-style), ideal for exact codes, IDs, and names.
- Semantic search
- Retrieval by meaning using embeddings and/or a semantic reranker, matching paraphrases and synonyms without shared keywords.
- Hybrid search
- Combining keyword and vector search in one query and fusing the results, capturing both exact-term and meaning matches. The RAG default.
- Semantic ranker
- An Azure AI Search feature that re-scores the top results with a language model for relevance and can return concise captions.
- Chunking
- Splitting documents into passage-sized pieces before embedding and indexing, so retrieval returns focused, citable context that fits the prompt.
- Context window
- The maximum tokens a model can consider at once; retrieved passages plus the question and answer must fit within it.
- System prompt
- The instruction message that, in RAG, tells the model to answer only from the provided sources and to cite them — the grounding rule.