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/vector-search-how-to-create-index.md
+52-53Lines changed: 52 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,20 +9,20 @@ ms.service: azure-ai-search
9
9
ms.custom:
10
10
- ignite-2024
11
11
ms.topic: how-to
12
-
ms.date: 02/14/2025
12
+
ms.date: 04/17/2025
13
13
---
14
14
15
15
# Create a vector index
16
16
17
-
In Azure AI Search, you can store vectors in a search index and send vector queries to match on semantic similarity. A vector store in Azure AI Search is defined by an index schema that has both vector and nonvector fields. The schema also has a vector configuration for specifying the algorithms used to create and compress the embedding space.
17
+
In Azure AI Search, you can store vectors in a search index and send vector queries for matching based on semantic similarity. A vector index is defined by an index schema that has: vector fields, nonvector fields, and a vector configuration section.
18
18
19
19
[Create or Update Index API](/rest/api/searchservice/indexes/create-or-update) creates the vector store. Follow these steps to index vectors in Azure AI Search:
20
20
21
21
> [!div class="checklist"]
22
22
> + Start with a basic schema definition
23
23
> + Add vector algorithms and optional compression
24
24
> + Add vector field definitions
25
-
> + Load prevectorized data [as a separate step](#load-vector-data-for-indexing), or use [integrated vectorization](vector-search-integrated-vectorization.md) for data chunking and encoding during indexing
25
+
> + Load prevectorized data [as a separate step](#load-vector-data-for-indexing), or use [integrated vectorization](vector-search-integrated-vectorization.md) for data chunking and embedding during indexing
26
26
27
27
This article explains the workflow using the REST API for illustration. Once you understand the basic workflow, continue with the Azure SDK code samples in the [azure-search-vector-samples](https://github.com/Azure/azure-search-vector-samples) repository for guidance on using vectors in test and production code.
28
28
@@ -37,35 +37,37 @@ This article explains the workflow using the REST API for illustration. Once you
37
37
38
38
+ You should know the dimensions limit of the model used to create the embeddings so that you can assign that limit to the vector field. For **text-embedding-ada-002**, dimensions are fixed at 1536. For **text-embedding-3-small** or **text-embedding-3-large**, dimensions range from 1 to 1536 and 3072, respectively.
39
39
40
-
+ You should also know what similarity metric to use. For embedding models on Azure OpenAI, similarity is [computed using `cosine`](/azure/ai-services/openai/concepts/understand-embeddings#cosine-similarity).
40
+
+ You should also know what similarity metric to use. For embedding models on Azure OpenAI, similarity is computed using [`cosine`](/azure/ai-services/openai/concepts/understand-embeddings#cosine-similarity).
41
41
42
-
+ You should be familiar with [creating an index](search-how-to-create-search-index.md). The schema must include a field for the document key, other fields you want to search or filter, and other configurations for behaviors needed during indexing and queries.
42
+
+ You should be familiar with [creating an index](search-how-to-create-search-index.md). A schema always includes a field for the document key, fields used for search or filters, and other configurations for behaviors needed during indexing and queries.
43
43
44
44
## Limitations
45
45
46
46
For search services created before January 2019, there's a small subset that can't create a vector index. If this applies to you, create a new service to use vectors.
47
47
48
48
## Prepare documents for indexing
49
49
50
-
Before indexing, assemble a document payload that includes fields of vector and nonvector data. The document structure must conform to the index schema.
50
+
Before indexing, assemble a document payload that includes fields of vector and nonvector data. The document structure must conform to the fields collection of index schema.
51
51
52
52
Make sure your source documents provide the following content:
53
53
54
54
| Content | Description |
55
55
|---------|-------------|
56
56
| Unique identifier | A field or a metadata property that uniquely identifies each document. All search indexes require a document key. To satisfy document key requirements, a source document must have one field or property uniquely identifies it in the index. If you're indexing blobs, it might be the metadata_storage_path that uniquely identifies each blob. If you're indexing from a database, it might be primary key. This source field must be mapped to an index field of type `Edm.String` and `key=true` in the search index.|
57
-
| Non-vector content | Provide other fields with human-readable content. Human readable content is useful for the query response, and for hybrid query scenarios that include full text search or semantic ranking in the same request. If you're using a chat completion model, most models like ChatGPT don't accept raw vectors as input. |
58
-
| Vector content| A vectorized version of your non-vector content. A vector is an array of single-precision floating point numbers generated by an embedding model. Each vector field contains an array generated by an embedding model, one embedding per field, where the field is a top-level field (not part of a nested or complex type). For the simplest integration, we recommend the embedding models in [Azure OpenAI](https://aka.ms/oai/access), such as a **text-embedding-3** model for text documents or the [Image Retrieval REST API](/rest/api/computervision/image-retrieval) for images and multimodal embeddings. <br><br>If you can take a dependency on indexers and skillsets, consider using [integrated vectorization](vector-search-integrated-vectorization.md) that encodes images and textual content during indexing. Your field definitions are for vector fields, but incoming source data can be text or images, which are converted to vector arrays during indexing. |
57
+
| Non-vector content | Provide other fields with human-readable content. Human readable content is useful for the query response, and for hybrid query scenarios that include full text search or semantic ranking in the same request. If you're using a chat completion model, most models like ChatGPT expect human-readable text and don't accept raw vectors as input. |
58
+
| Vector content| A vectorized version of your non-vector content. Vectors are used at query time. A vector is an array of single-precision floating point numbers generated by an embedding model. Each vector field contains an array generated by an embedding model, one embedding per field, where the field is a top-level field (not part of a nested or complex type). For the simplest integration, we recommend the embedding models in [Azure OpenAI](https://aka.ms/oai/access), such as a **text-embedding-3** model for text documents or the [Image Retrieval REST API](/rest/api/computervision/image-retrieval) for images and multimodal embeddings. <br><br>If you can take a dependency on indexers and skillsets, consider using [integrated vectorization](vector-search-integrated-vectorization.md) that encodes images and textual content during indexing. Your field definitions are for vector fields, but incoming source data can be text or images, which are converted to vector arrays during indexing. |
59
59
60
-
Your search index should include fields and content for all of the query scenarios you want to support. Suppose you want to search or filter over product names, versions, metadata, or addresses. In this case, vector similarity search isn't especially helpful. Keyword search, geo-search, or filters would be a better choice. A search index that includes a comprehensive collection of both vector and nonvector fields provides maximum flexibility for query construction and response composition.
60
+
Your search index should include fields and content for all of the query scenarios you want to support. Suppose you want to search or filter over product names, versions, metadata, or addresses. In this case, vector similarity search isn't especially helpful. Keyword search, geo-search, or filters that iterate over verbatim content would be a better choice. A search index that's inclusive of both vector and nonvector fields provides maximum flexibility for query construction and response composition.
61
61
62
62
A short example of a documents payload that includes vector and nonvector fields is in the [load vector data](#load-vector-data-for-indexing) section of this article.
63
63
64
64
## Start with a basic index
65
65
66
66
Start with a minimum schema so that you have a definition to work with before adding a vector configuration and vector fields. A simple index might look the following example. You can learn more about an index schema in [Create a search index](search-how-to-create-search-index.md).
67
67
68
-
Notice that it has a required name, a required document key (`"key": true`), and fields for human readable content in plain text. It's common to have a human-readable version of whatever content you intend to vectorize. For example, if you have a chunk of text from a PDF file, your index schema should have the plain text equivalent of the vectorized text.
68
+
Notice that it has a required name, a required document key (`"key": true`), and fields for human readable content in plain text. It's common to have a human-readable version of whatever content you intend to vectorize. For example, if you have a chunk of text from a PDF file, your index schema should have a field for plain text chunks and a second field for vectorized chunks.
69
+
70
+
Here's a basic index with a "name", a "fields" collection, and a few other constructs for extra configuration.
69
71
70
72
```http
71
73
POST https://[servicename].search.windows.net/indexes?api-version=[api-version]
@@ -76,35 +78,35 @@ POST https://[servicename].search.windows.net/indexes?api-version=[api-version]
Next, add a vector search configuration (profile) to your schema. Configuration occurs before field definitions because you specify a profile on each field as part of its definition. In the schema, vector configuration is typically added after the fields collection, perhaps after `"suggesters"`, `"scoringProfiles"`, or `"analyzers"`.
88
-
89
-
A vector configuration specifies the parameters used during indexing to create "nearest neighbor" information among the vector nodes. Algorithms include:
90
-
91
-
+ Hierarchical Navigable Small World (HNSW)
92
-
+ Exhaustive k-Nearest Neighbor (KNN)
93
-
94
-
If you choose HNSW on a field, you can opt in for exhaustive KNN at query time. But the other direction doesn’t work: if you choose exhaustive for indexing, you can’t later request HNSW search because the extra data structures that enable approximate search don’t exist.
90
+
Next, add a "vectorSearch" configuration to your schema. It's useful to specify a configuration first, before field definitions, because the profiles you define here become part of the vector field's definition. In the schema, vector configuration is typically inserted after the fields collection, perhaps after `"analyzers"`, `"scoringProfiles"`, and `"suggesters"` (although order doesn't matter).
95
91
96
-
Optionally, a vector configuration also specifies quantization methods for reducing vector size:
92
+
A vector configuration includes:
97
93
98
-
+ Scalar
99
-
+ Binary (available in 2024-07-01 only and in newer Azure SDK packages)
94
+
+`vectorSearch.algorithms` used during indexing to create "nearest neighbor" information among the vector nodes.
95
+
+`vectorSearch.compressions` for scalar or binary quantization, oversampling, and for reranking with original vectors.
96
+
+`vectorSearch.profiles` for specifying multiple combinations of algorithm and compression configurations.
100
97
101
98
### [**2024-07-01**](#tab/config-2024-07-01)
102
99
103
100
[**2024-07-01**](/rest/api/searchservice/search-service-api-versions#2024-07-01) is generally available. It supports a vector configuration having:
104
101
105
-
+`vectorSearch.algorithms` support HNSW and exhaustive KNN.
106
-
+`vectorSearch.compressions` support scalar and binary quantization, oversampling, and reranking with original vectors.
107
-
+`vectorSearch.profiles` for specifying multiple combinations of algorithm and compression configurations.
102
+
+ Hierarchical Navigable Small World (HNSW) algorithm
103
+
+ Exhaustive k-Nearest Neighbor (KNN) algorithm
104
+
+ Scalar compression
105
+
+ Binary compression (available in 2024-07-01 only and in newer Azure SDK packages)
106
+
+ Oversampling
107
+
+ Reranking with original vectors
108
+
109
+
If you choose HNSW on a field, you can opt in for exhaustive KNN at query time. But the other direction doesn’t work: if you choose exhaustive for indexing, you can’t later request HNSW search because the extra data structures that enable approximate search don’t exist.
108
110
109
111
Be sure to have a strategy for [vectorizing your content](vector-search-how-to-generate-embeddings.md). We recommend [integrated vectorization](vector-search-integrated-vectorization.md) and [query-time vectorizers](vector-search-how-to-configure-vectorizer.md) for built-in encoding.
110
112
@@ -175,7 +177,7 @@ Be sure to have a strategy for [vectorizing your content](vector-search-how-to-g
175
177
176
178
+ Names for each configuration of compression, algorithm, and profile must be unique for its type within the index.
177
179
178
-
+`vectorSearch.compressions` can be `scalarQuantization` or `binaryQuantization`. Scalar quantization compresses float values into narrower data types. Binary quantization converts floats into binary 1bit values.
180
+
+`vectorSearch.compressions` can be `scalarQuantization` or `binaryQuantization`. Scalar quantization compresses float values into narrower data types. Binary quantization converts floats into binary 1-bit values.
179
181
180
182
+`vectorSearch.compressions.rerankWithOriginalVectors` uses the original, uncompressed vectors to recalculate similarity and rerank the top results returned by the initial search query. The uncompressed vectors exist in the search index even if `stored` is false. This property is optional. Default is true.
181
183
@@ -197,14 +199,9 @@ Be sure to have a strategy for [vectorizing your content](vector-search-how-to-g
[**2024-05-01-preview**](/rest/api/searchservice/search-service-api-versions#2024-05-01-preview) is the most recent preview version.
202
+
[**2024-05-01-preview**](/rest/api/searchservice/search-service-api-versions#2024-05-01-preview) is the most recent preview version. It's inclusive of previous preview versions.
201
203
202
-
+`vectorSearch.algorithms` with support for HNSW and exhaustive KNN.
203
-
+`vectorSearch.compressions` with properties for scalar (but not binary) quantization, oversampling, and reranking with original vectors.
204
-
+`vectorSearch.profiles` for multiple combinations of algorithm and compression configurations.
205
-
+ Inclusive of 2024-03-01-preview.
206
-
+ Inclusive of 2023-10-01-preview.
207
-
+ Inclusive of 2023-11-01 `vectorSearch.algorithms` and `vectorSearch.profiles`.
204
+
Preview and stable API versions support the same `"vectorSearch"` configurations. You would choose the preview over the stable version for other reasons, such as newer [vectorizers](vector-search-how-to-configure-vectorizer.md) invoked at query time.
208
205
209
206
1. Use the [Create or Update Index Preview REST API](/rest/api/searchservice/indexes/create-or-update?view=rest-searchservice-2024-05-01-preview&preserve-view=true) to create the index.
210
207
@@ -278,7 +275,7 @@ Be sure to have a strategy for [vectorizing your content](vector-search-how-to-g
278
275
279
276
+`vectorSearch.algorithms.efConstruction` is the number of nearest neighbors used during indexing. Default is 400. The range is 100 to 1,000.
280
277
281
-
+`"vectorSearch.algorithms.fSearch` is the number of nearest neighbors used during search. Default is 500. The range is 100 to 1,000.
278
+
+`"vectorSearch.algorithms.efSearch` is the number of nearest neighbors used during search. Default is 500. The range is 100 to 1,000.
282
279
283
280
+`vectorSearch.algorithms.metric` should be "cosine" if you're using Azure OpenAI, otherwise use the similarity metric associated with the embedding model you're using. Supported values are `cosine`, `dotProduct`, `euclidean`, `hamming` (used for [indexing binary data](vector-search-how-to-index-binary-data.md)).
284
281
@@ -294,25 +291,30 @@ Once you have a vector configuration, you can add a vector field to the fields c
294
291
295
292
Vector fields are characterized by [their data type](/rest/api/searchservice/supported-data-types#edm-data-types-for-vector-fields), a `dimensions` property based on the embedding model used to output the vectors, and a vector profile that you created in a previous step.
296
293
297
-
```json
298
-
{
299
-
"name": "contentVector",
300
-
"type": "Collection(Edm.Single)",
301
-
"searchable": true,
302
-
"retrievable": false,
303
-
"stored": false,
304
-
"dimensions": 1536,
305
-
"vectorSearchProfile": "vector-profile-1"
306
-
}
307
-
```
308
-
309
294
### [**2024-07-01**](#tab/rest-2024-07-01)
310
295
311
296
[**2024-07-01**](/rest/api/searchservice/search-service-api-versions#2024-07-01) is generally available.
312
297
313
-
1. Use the [Create or Update Index](/rest/api/searchservice/indexes/create-or-update) to create the index.
298
+
1. Use the [Create or Update Index](/rest/api/searchservice/indexes/create-or-update) to create the index and add a vector field to the fields collection.
314
299
315
-
1. Define a vector field with the following attributes. You can store one generated embedding per field. For each vector field:
300
+
```json
301
+
{
302
+
"name": "example-index",
303
+
"fields": [
304
+
{
305
+
"name": "contentVector",
306
+
"type": "Collection(Edm.Single)",
307
+
"searchable": true,
308
+
"retrievable": false,
309
+
"stored": false,
310
+
"dimensions": 1536,
311
+
"vectorSearchProfile": "vector-profile-1"
312
+
}
313
+
]
314
+
}
315
+
```
316
+
317
+
1. Specify a vector field with the following attributes. You can store one generated embedding per field. For each vector field:
316
318
317
319
+ `type` must be a [vector data types](/rest/api/searchservice/supported-data-types#edm-data-types-for-vector-fields). `Collection(Edm.Single)` is the most common for embedding models.
318
320
+ `dimensions` is the number of dimensions generated by the embedding model. For text-embedding-ada-002, it's fixed at 1536. For the text-embedding-3 model series, there's a range of values. If you're using integrated vectorization and an embedding skill to generate vectors, make sure this property is set to the [same dimensions value](cognitive-search-skill-azure-openai-embedding.md#supported-dimensions-by-modelname) used by the embedding skill.
@@ -401,10 +403,7 @@ Vector fields are characterized by [their data type](/rest/api/searchservice/sup
[**2024-05-01-preview**](/rest/api/searchservice/search-service-api-versions#2024-05-01-preview) is the most recent preview version.
405
-
406
-
+ Supports all [vector data types](/rest/api/searchservice/supported-data-types#edm-data-types-for-vector-fields).
407
-
+ Inclusive of `2024-03-01-preview`.
406
+
[**2024-05-01-preview**](/rest/api/searchservice/search-service-api-versions#2024-05-01-preview) is the most recent preview version. It supports the same vector field definitions as the stable version, including support for all [vector data types](/rest/api/searchservice/supported-data-types#edm-data-types-for-vector-fields).
408
407
409
408
1. Use the [Create or Update Index Preview REST API](/rest/api/searchservice/indexes/create-or-update?view=rest-searchservice-2024-05-01-preview&preserve-view=true) to define the fields collection of an index.
0 commit comments