Choosing Retrieval Query Types, Indexing and Chunking
This lesson explains the planning decisions for retrieval, which decides which content the model sees and so the upper limit of answer quality: query type, indexing approach, chunking and metadata.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish keyword, vector, hybrid and semantic queries.
- Choose an indexing approach from the content and its update pattern.
- Explain how metadata and security trimming filter results.
Query types
In a retrieval-augmented generation (RAG) solution, the application does not send the user's question straight to the model. It first sends a query to a search index: a request that describes the content to find, usually built from the user's question. The search service compares the query with the indexed content, scores each match and returns the highest-ranked passages, which the application then adds to the prompt as grounding data. The query type decides how that comparison and ranking are done: by matching words, by comparing meaning, or by a combination. Because different questions need different kinds of matching, the query type is the first retrieval decision. Azure AI Search supports the following query types.
Keyword search, also called full-text search, matches the words in the query against the words in the indexed text and ranks documents with the BM25 algorithm, which scores a document higher when the query terms appear often in it and are rare across the index. It finds exact identifiers, product codes, error numbers and names reliably. Its weakness is that it matches words, not meaning, so it misses passages that use different words for the same idea, such as "annual leave" when the user asks about "holiday entitlement".
Vector search matches meaning rather than words. An embedding model converts each passage into a vector, a list of numbers that represents its meaning, when the content is indexed, and converts the query into a vector in the same way at query time. The search service then returns the passages whose vectors are closest to the query vector, using an approximate nearest neighbour algorithm such as HNSW (Hierarchical Navigable Small World) or an exhaustive k-nearest neighbours (KNN) search. Vector search finds paraphrases and works across languages, but it can miss exact identifiers and rare terms, because a code such as E-4471 carries little meaning that an embedding can capture.
Hybrid search runs a keyword query and a vector query in the same request and merges the two ranked lists with Reciprocal Rank Fusion (RRF). RRF gives each result a score based on its position in each list, so a passage that ranks well in both lists rises to the top. Hybrid search therefore finds both exact terms and paraphrases, and it is the usual default for RAG.
The semantic ranker is not a separate way of matching content; it is a second ranking stage applied to the results of a keyword or hybrid query. It takes the top 50 results and reranks them with a language model that reads the query and each passage together, which judges relevance more accurately than BM25 or vector distance alone. It can also return extractive captions, the most relevant sentences in each passage, and extractive answers. The semantic ranker is billed separately.
Agentic retrieval goes further for complex questions. A large language model (LLM) reads the question and the conversation history, plans several focused subqueries, runs them in parallel with semantic reranking and merges the results into one response. It handles multi-part questions and follow-up questions such as "and what about the other model?", at the cost of higher latency and token usage.
The following table summarises the strengths, weaknesses and typical uses of each option.
| Method | Strength | Weakness | Typical use |
|---|---|---|---|
| Keyword | Exact terms and identifiers | No synonyms or paraphrase | Codes, names, legal citations |
| Vector | Meaning and paraphrase | Can miss exact identifiers | Natural-language questions |
| Hybrid | Both of the above | Slightly more cost | Default for RAG |
| Hybrid + semantic ranker | Best single-query relevance | Reranks top 50 only; extra charge | Production RAG |
| Agentic retrieval | Multi-part and conversational questions | Higher latency and token cost | Chat assistants and agents |
Choose the query type
Indexing approach
A query can only find content that has been indexed. In Azure AI Search, an index is the searchable store that queries run against. It is similar to a database table: it holds search documents, and its schema defines their fields, such as the text, its vector and metadata, together with which fields are searchable, filterable or retrievable. Indexing is the process that fills the index: it reads the source content, extracts the text, splits it into chunks, generates embeddings and writes the results as search documents. The indexing approach is the plan for how that process runs, and it follows the content and its update pattern.
There are two ways to load content. In the pull model, an indexer connects to a supported data source, such as Blob Storage, Data Lake Storage, Azure SQL, Cosmos DB, OneLake or SharePoint, and runs on a schedule with change detection, so only new and changed documents are processed on each run. In the push model, the application sends documents to the index through the API or SDK, which suits sources that indexers do not support and content that must appear in the index immediately. An indexer can also run a skillset, a sequence of processing steps. With integrated vectorization, the skillset performs the chunking and embedding, so no separate pipeline is needed.
Chunking is the step that splits each source document into smaller passages, called chunks, before they are embedded and indexed. It is needed because embedding models have input limits, and because a short, focused passage matches a question more precisely and uses fewer prompt tokens than a whole manual. Each chunk becomes its own search document in the index. Fixed-size chunks with an overlap between neighbouring chunks are simple to produce, but they can cut a section or table in half. Layout-aware chunks follow the document's structure, keeping headings, paragraphs and tables together, which matters for manuals and policies.
Some content needs preparation before it can be chunked. Scanned documents contain images of text, so they need optical character recognition (OCR) or layout analysis to extract the text first. Images are made searchable either by verbalization, generating a text description of the image and indexing it, or by multimodal embeddings that place images and text in the same vector space.
Plan the indexing
Metadata and security trimming
Metadata is descriptive information stored alongside the content, such as where a passage came from and who may read it. Because each chunk created during indexing is stored as a separate search document, it loses the context of the source document unless that context is copied into fields on the chunk. Each chunk should therefore carry metadata fields: the source document, title, section, page, date, category and, where access differs between users, the groups that may see it. When these fields are marked filterable in the index schema, a query can include a filter that restricts results by product, region or date.
Security trimming is the use of such a filter to remove content the current user is not allowed to see. A filter on group identifiers ensures that users only retrieve content they are permitted to read. Trimming must happen in the query, not by asking the model to ignore documents.
Security trimming works as follows. During indexing, each chunk receives a collection field, such as group_ids, holding the Microsoft Entra group IDs that may read the source document. At query time, the application looks up the signed-in user's groups and adds a filter such as group_ids/any(g: search.in(g, 'hr-all, hr-managers')). Azure AI Search applies the filter before ranking, so chunks the user may not see never reach the prompt. If the application instead retrieved everything and told the model "do not reveal documents the user cannot access", the restricted text would already be in the model's context, and a carefully worded question could extract it.
Metadata also improves relevance, not only security. A question about the current travel policy is better answered when a date or version filter excludes superseded policies, and a filter on product model stops a question about one device from retrieving another device's manual. Planning these fields before indexing matters: a new field can be added to an existing index, but every existing document must then be re-indexed to populate it, and changing an existing field to filterable requires rebuilding the index.
Security trimming
Choosing the method
An electronics manufacturer's support assistant answers technicians' questions such as "What does error E-4471 mean on the X200, and how is it different from the X300?" Manuals are PDFs with many tables, some scanned.
The error code needs keyword matching, the explanation needs semantic matching, and the comparison has two parts. Hybrid search with semantic ranking covers the first two; agentic retrieval splits the comparison into subqueries for each model. Indexing should use layout analysis with OCR so that the tables survive, and each chunk should carry a filterable model field. Pure vector search would be the weakest choice because it may miss the exact error code.
Users search for exact product codes. Why is vector search alone not enough?
Show answer
Embeddings capture meaning, not exact strings, so similar but different codes can rank highly. Keyword matching, usually in a hybrid query, finds exact identifiers.
Exam Tips
Remember for the exam
- Default for RAG: hybrid search plus semantic ranker.
- Exact codes and identifiers need keyword matching; do not rely on vectors alone.
- Multi-part or follow-up questions: agentic retrieval.
- Security trimming uses filters in the query, never prompt instructions.