You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/search/tutorial-rag-build-solution-index-schema.md
+81-33Lines changed: 81 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ ms.date: 09/12/2024
12
12
13
13
---
14
14
15
-
# Tutorial: Design an index (RAG in Azure AI Search)
15
+
# Tutorial: Design an index for RAG in Azure AI Search
16
16
17
17
An index contains searchable text and vector content, plus configurations. In a RAG pattern that uses a chat model for responses, you want an index that contains chunks of content that can be passed to an LLM at query time.
18
18
@@ -35,29 +35,29 @@ The output of this exercise is an index definition in JSON. At this point, it's
35
35
36
36
In conversational search, LLMs compose the response that the user sees, not the search engine, so you don't need to think about what fields to show in your search results, and whether the representations of individual search documents are coherent to the user. Depending on the question, the LLM might return verbatim content from your index, or more likely, repackage the content for a better answer.
37
37
38
-
### Focus on chunks
38
+
### Organized around chunks
39
39
40
40
When LLMs generate a response, they operate on chunks of content for message inputs, and while they need to know where the chunk came from for citation purposes, what matters most is the quality of message inputs and its relevance to the user's question. Whether the chunks come from one document or a thousand, the LLM ingests the information or *grounding data*, and formulates the response using instructions provided in a system prompt.
41
41
42
42
Chunks are the focus of the schema, and each chunk is the defining element of a search document in a RAG pattern. You can think of your index as a large collection of chunks, as opposed to traditional search documents that probably have more structure, such as fields containing uniform content for a name, descriptions, categories, and addresses.
43
43
44
-
### Focus on content
44
+
### Content-aware
45
45
46
46
In addition to structural considerations, like chunked content, you also want to consider the substance of your content because it also informs what fields are indexed.
47
47
48
-
In this tutorial, we use PDFs and content from the NASA Earth Book. This content is descriptive and informative, with numerous references to geographies, countries, and areas across the world. To capture this information in our index and potentially use it in queries, we can include skills in our indexing pipeline that recognize and extract this information, loading it into a searchable and filterable `locations` field.
48
+
In this tutorial, sample data consists of PDFs and content from the NASA Earth Book. This content is descriptive and informative, with numerous references to geographies, countries, and areas across the world. To capture this information in our index and potentially use it in queries, we include skills in our indexing pipeline that recognize and extract this information, loading it into a searchable and filterable `locations` field.
49
49
50
50
The original ebook is large, over 100 pages and 35 MB in size. We broke it up into smaller PDFs, one per page of text, to stay under the REST API payload limit of 16 MB per API call.
51
51
52
52
For simplicity, we omit image vectorization for this exercise.
53
53
54
-
### Focus on parent-child indexes
54
+
### Parent-child fields in one or two indexes
55
55
56
-
Chunked content typically derives from a larger document. And although the schema is organized around chunks, you also want to capture properties and content at the parent level. Examples of these properties might include the parent file path, title, authors, publication date, summary.
56
+
Chunked content typically derives from a larger document. And although the schema is organized around chunks, you also want to capture properties and content at the parent level. Examples of these properties might include the parent file path, title, authors, publication date, or a summary.
57
57
58
58
An inflection point in schema design is whether to have two indexes for parent and child/chunked content, or a single index that repeats parent elements for each chunk.
59
59
60
-
In this tutorial, because all of the chunks of text originate from a single parent (NASA Earth Book), you don't need a separate index dedicated to up level parent fields. If you index from multiple parent PDFs, you might want a parent-child index pair to capture level-specific fields and then send lookup queries to the parent index to retrieve those fields relevant to each chunk. We include an example of that parent-child index template in this exercise for comparison.
60
+
In this tutorial, because all of the chunks of text originate from a single parent (NASA Earth Book), you don't need a separate index dedicated to up level parent fields. However, if you index from multiple parent PDFs, you might want a parent-child index pair to capture level-specific fields and then send lookup queries to the parent index to retrieve those fields relevant to each chunk.
61
61
62
62
### Checklist of schema considerations
63
63
@@ -76,13 +76,13 @@ Although Azure AI Search can't join indexes, you can create indexes that preserv
76
76
> [!NOTE]
77
77
> Schema design affects storage and costs. This exercise is focused on schema fundamentals. In the [Minimize storage and costs](tutorial-rag-build-solution-minimize-storage.md) tutorial, you revisit schema design to consider narrow data types, attribution, and vector configurations that offer more efficient.
78
78
79
-
## Create a basic index
79
+
## Create an index for RAG workloads
80
80
81
-
A minimal index for LLM is designed to store chunks of content. It includes vector fields if you want similarity search for highly relevant results, and nonvector fields for human-readable inputs to the LLM for conversational search. Nonvector chunked content in the search results becomes the grounding data sent to the LLM.
81
+
A minimal index for LLM is designed to store chunks of content. It typically includes vector fields if you want similarity search for highly relevant results. It also includes nonvector fields for human-readable inputs to the LLM for conversational search. Nonvector chunked content in the search results becomes the grounding data sent to the LLM.
82
82
83
83
1. Open Visual Studio Code and create a new file. It doesn't have to be a Python file type for this exercise.
84
84
85
-
1. Here's a minimal index definition for RAG solutions that support vector and hybrid search. Review it for an introduction to required elements: name, fields, and a `vectorSearch`configuration for the vector fields.
85
+
1. Here's a minimal index definition for RAG solutions that support vector and hybrid search. Review it for an introduction to required elements: index name, fields, and a configuration section for vector fields.
86
86
87
87
```json
88
88
{
@@ -91,7 +91,7 @@ A minimal index for LLM is designed to store chunks of content. It includes vect
@@ -104,13 +104,62 @@ A minimal index for LLM is designed to store chunks of content. It includes vect
104
104
}
105
105
```
106
106
107
-
Fields must include key field (`"id"`) and should include vector chunks for similarity search, and nonvector chunks for the LLM. Metadata about the source file might be file path, creation date, or content type.
108
-
109
-
Vector fields have [specific types](/rest/api/searchservice/supported-data-types#edm-data-types-for-vector-fields) and extra attributes for embedding model dimensions and configuration. `Edm.Single` is a data type that works for the more commonly used LLMs. For more information about vector fields, see [Create a vector index](vector-search-how-to-create-index.md).
110
-
111
-
1. Here's the index schema for the tutorial and the Earth Book content. It's similar to the basic schema, but adds a parent ID, metadata (`title`), strings (`chunks`), and vectors for similarity search (`text_vectors`). It also includes a `locations` field for storing generated content that's created in the [indexing pipeline](tutorial-rag-build-solution-pipeline.md).
107
+
Fields must include key field (`"id"`) and should include vector chunks for similarity search, and nonvector chunks for inputs to the LLM.
108
+
109
+
Vector fields have [specific types](/rest/api/searchservice/supported-data-types#edm-data-types-for-vector-fields) and extra attributes for embedding model dimensions and configuration. `Edm.Single` is a data type that works for commonly used LLMs. For more information about vector fields, see [Create a vector index](vector-search-how-to-create-index.md).
110
+
111
+
Metadata fields might be file path, creation date, or content type and are useful for [filters](vector-search-filters.md).
112
+
113
+
1. Here's the index schema for the [tutorial source code](https://github.com/Azure-Samples/azure-search-python-samples/blob/main/Tutorial-RAG/Tutorial-rag.ipynb) and the [Earth Book content](https://github.com/Azure-Samples/azure-search-sample-data/tree/main/nasa-e-book/earth_book_2019_text_pages).
114
+
115
+
Like the basic schema, it's organized around chunks. The `chunk_id` uniquely identifies each chunk. The `text_vector` field is an embedding of the chunk. The nonvector `chunk` field is a readable string. The `title` maps to a unique metadata storage path for the blobs. The `parent_id` is the only parent-level field, and it's a base64-encoded version of the parent file URI.
116
+
117
+
The schema also includes a `locations` field for storing generated content that's created by the [indexing pipeline](tutorial-rag-build-solution-pipeline.md).
index = SearchIndex(name=index_name, fields=fields, vector_search=vector_search)
158
+
result = index_client.create_or_update_index(index)
159
+
print(f"{result.name} created")
160
+
```
112
161
113
-
```json
162
+
<!-- ```json
114
163
{
115
164
"name": "rag-tutorial-earth-book",
116
165
"defaultScoringProfile": null,
@@ -223,7 +272,21 @@ A minimal index for LLM is designed to store chunks of content. It includes vect
223
272
"compressions": []
224
273
}
225
274
}
275
+
``` -->
276
+
277
+
1. For an index schema that more closely mimics structured content, you would have separate indexes for parent and child (chunked) fields. You would need index projections to coordinate the indexing of the two indexes simultaneously. Queries execute against the child index. Query logic includes a lookup query, using the parent_idto retrieve content from the parent index.
278
+
279
+
Fields in the child index:
280
+
281
+
- id
282
+
- chunk
283
+
- chunkVectcor
284
+
- parent_id
226
285
286
+
Fields in the parent index (everything that you want "one of"):
287
+
288
+
- parent_id
289
+
- parent-level fields (name, title, category)
227
290
228
291
<!-- Objective:
229
292
@@ -251,22 +314,7 @@ Tasks:
251
314
<!--
252
315
253
316
ps 2: A richer index has more fields and configurations, and is often better because extra fields support richer queries and more opportunities for relevance tuning. Filters and scoring profiles for boosting apply to nonvector fields. If you have content that should be matched precisely and not similarly, such as a name or employee number, then create fields to contain that information.*
254
-
255
-
## BLOCKED: Index for hybrid queries and relevance tuning
256
-
257
-
Per Carey, you would want a couple indexes for this scenario - parent index, chunked/child index linked to parent - with queries that include lookup to access fields at the parent level. You would need index projections to "project" to coordiate the indexing of the two indexes simultaneously.
258
-
259
-
child index:
260
-
- id
261
-
- chunk
262
-
- chunkVectcor
263
-
- parentId
264
-
265
-
parent index (everything that you want "one of"):
266
-
- fields for verbatim matching (name, title, category)
267
-
- fields for filters or boosting (dates, geo coordates)
268
-
269
-
This is probably out of scope for this tutorial, but could be an extension. -->
Copy file name to clipboardExpand all lines: articles/search/tutorial-rag-build-solution-models.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ ms.date: 09/12/2024
13
13
14
14
---
15
15
16
-
# Tutorial: Choose embedding and chat models (RAG in Azure AI Search)
16
+
# Tutorial: Choose embedding and chat models for RAG in Azure AI Search
17
17
18
18
A RAG solution built on Azure AI Search takes a dependency on embedding models for vectorization, and on chat models for conversational search over your data.
0 commit comments