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
+49-19Lines changed: 49 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,48 +9,53 @@ ms.service: azure-ai-search
9
9
ms.custom:
10
10
- ignite-2024
11
11
ms.topic: how-to
12
-
ms.date: 01/09/2025
12
+
ms.date: 02/14/2025
13
13
---
14
14
15
15
# Create a vector index
16
16
17
-
In Azure AI Search, a *vector store* has an index schema that defines vector and nonvector fields, a vector configuration for algorithms that create and compress the embedding space, and settings on vector field definitions that are used in query requests.
17
+
In Azure AI Search, you can store vectors in a search index. Your vector store has an index schema that defines both vector and nonvector fields, a vector configuration for algorithms used to create and compress the embedding space, and settings on vector field definitions used in query requests.
18
18
19
-
The [Create or Update Index](/rest/api/searchservice/indexes/create-or-update)API creates the vector store. Follow these steps to index vector data:
19
+
The [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
-
> + Define a schema with vector algorithms and optional compression
22
+
> + Start with a basic schema definition
23
+
> + Add vector algorithms and optional compression
23
24
> + Add vector field definitions
24
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
26
26
27
This article explains the workflow and uses REST 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 these features in test and production code.
27
28
28
29
> [!TIP]
29
-
> Use the Azure portal to [create a vector index](search-get-started-portal-import-vectors.md) and try integrated data chunking and vectorization.
30
+
> You can also use the Azure portal to [create a vector index](search-get-started-portal-import-vectors.md) and try out integrated data chunking and vectorization.
30
31
31
32
## Prerequisites
32
33
33
-
+ Azure AI Search, in any region and on any tier. On 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. For indexing workloads that include integrated vectorization (skillsets that call Azure AI), Azure AI Search must be in the same region as Azure OpenAI or Azure AI services.
34
+
+ Azure AI Search, in any region and on any tier. If you plan to use [integrated vectorization](vector-search-integrated-vectorization.md), Azure AI Search must be in the same region as the embedding models hosted on Azure OpenAI or in Azure AI Vision.
34
35
35
-
+You must have [pre-existing vector embeddings](vector-search-how-to-generate-embeddings.md) to upload to the index, or you can use [integrated vectorization](vector-search-integrated-vectorization.md), where embedding models are called from a skillset in an indexer pipeline.
36
+
+If you aren't using integrated vectorization, your source documents must have [vector embeddings](vector-search-how-to-generate-embeddings.md) to upload to the index.
36
37
37
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. Integrated vectorization supports a finite number of embedding models. For **text-embedding-ada-002**, dimensions are fixed at 1536. For **text-embedding-3-small** or **text-embedding-3-large**, the vector length ranges from 1 to 1536 and 3072, respectively.
38
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
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
43
44
+
## Limitations
45
+
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
+
43
48
## Prepare documents for indexing
44
49
45
-
Prior to 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 index schema.
46
51
47
52
Make sure your documents:
48
53
49
-
1. Provide 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 that can uniquely identify it in the index. This source field must be mapped to an index field of type `Edm.String` and `key=true` in the search index.
54
+
1. Provide 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. This source field must be mapped to an index field of type `Edm.String` and `key=true` in the search index.
50
55
51
56
1. Provide vector data (an array of single-precision floating point numbers) in source fields.
52
57
53
-
Vector fields contain an array generated by embedding models, 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/2023-02-01-preview/image-retrieval/vectorize-image) for images.
58
+
Vector fields contain 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 an**text-embedding-3** model for text documents or the [Image Retrieval REST API](/rest/api/computervision/image-retrieval/vectorize-image) for images.
54
59
55
60
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.
56
61
@@ -60,12 +65,35 @@ Your search index should include fields and content for all of the query scenari
60
65
61
66
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.
62
67
68
+
## Create a basic index
69
+
70
+
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).
71
+
72
+
Notice that it has a required name, a required document key, and human readable content. 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 content, coupled with a vector field equivalent that you add in a later step.
73
+
74
+
```http
75
+
POST https://[servicename].search.windows.net/indexes?api-version=[api-version]
In this step, add a vector search configuration to your schema. In the schema, you might add it after "suggesters", "scoringProfiles", or "analyzers".
92
+
65
93
A vector configuration specifies the parameters used during indexing to create "nearest neighbor" information among the vector nodes:
66
94
67
95
+ Hierarchical Navigable Small World (HNSW)
68
-
+ Exhaustive KNN
96
+
+ Exhaustive k-Nearest Neighbor (KNN)
69
97
70
98
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, you can’t later request HNSW search because the extra data structures that enable approximate search don’t exist.
71
99
@@ -284,7 +312,7 @@ Vector fields are characterized by [their data type](/rest/api/searchservice/sup
284
312
+`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.
285
313
+`vectorSearchProfile` is the name of a profile defined elsewhere in the index.
286
314
+`searchable` must be true.
287
-
+`retrievable` can be true or false. True returns the raw vectors (1536 of them) as plain text and consumes storage space. Set to true if you're passing a vector result to a downstream app.
315
+
+`retrievable` can be true or false. True returns the raw vectors (1,536 of them) as plain text and consumes storage space. Set to true if you're passing a vector result to a downstream app.
288
316
+`stored` can be true or false. It determines whether an extra copy of vectors is stored for retrieval. For more information, see [Reduce vector size](vector-search-how-to-storage-options.md).
289
317
+`filterable`, `facetable`, `sortable` must be false.
290
318
@@ -367,8 +395,10 @@ 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.
399
+
370
400
+ Supports all [vector data types](/rest/api/searchservice/supported-data-types#edm-data-types-for-vector-fields).
371
-
+ Inclusive of `2024-03-01-preview`, with new support [indexing binary data for vector search](vector-search-how-to-index-binary-data.md).
401
+
+ Inclusive of `2024-03-01-preview`.
372
402
373
403
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.
374
404
@@ -378,7 +408,7 @@ Vector fields are characterized by [their data type](/rest/api/searchservice/sup
378
408
+ `dimensions` is the number of dimensions generated by the embedding model. For text-embedding-ada-002, it's 1536.
379
409
+ `vectorSearchProfile` is the name of a profile defined elsewhere in the index.
380
410
+ `searchable` must be true.
381
-
+ `retrievable` can be true or false. True returns the raw vectors (1536 of them) as plain text and consumes storage space. Set to true if you're passing a vector result to a downstream app. False is required if `stored` is false.
411
+
+ `retrievable` can be true or false. True returns the raw vectors (1,536 of them) as plain text and consumes storage space. Set to true if you're passing a vector result to a downstream app. False is required if `stored` is false.
382
412
+ `stored` is a new boolean property that applies to vector fields only. True stores a copy of vectors returned in search results. False discards that copy during indexing. You can search on vectors, but can't return vectors in results.
383
413
+ `filterable`, `facetable`, `sortable` must be false.
384
414
@@ -547,7 +577,7 @@ If you're familiar with indexers and skillsets:
547
577
548
578
---
549
579
550
-
## Check your index for vector content
580
+
## Query your index for vector content
551
581
552
582
For validation purposes, you can query the index using Search Explorer in the Azure portal or a REST API call. Because Azure AI Search can't convert a vector to human-readable text, try to return fields from the same document that provide evidence of the match. For example, if the vector query targets the "titleVector" field, you could select "title" for the search results.
553
583
@@ -565,7 +595,7 @@ Fields must be attributed as "retrievable" to be included in the results.
565
595
566
596
+ Use the default Query view for a quick confirmation that the index contains vectors. The query view is for full text search. Although you can't use it for vector queries, you can send an empty search (`search=*`) to check for content. The content of all fields, including vector fields, is returned as plain text.
567
597
568
-
+ See[Create a vector query](vector-search-how-to-query.md) for more details.
598
+
For more information, see[Create a vector query](vector-search-how-to-query.md).
569
599
570
600
### [**REST API**](#tab/rest-check-index)
571
601
@@ -595,15 +625,15 @@ api-key: {{admin-api-key}}
595
625
596
626
## Update a vector store
597
627
598
-
To update a vector store, modify the schema and if necessary, reload documents to populate new fields. APIs for schema updates include [Create or Update Index (REST)](/rest/api/searchservice/indexes/create-or-update), [CreateOrUpdateIndex](/dotnet/api/azure.search.documents.indexes.searchindexclient.createorupdateindexasync) in the Azure SDK for .NET, [create_or_update_index](/python/api/azure-search-documents/azure.search.documents.indexes.searchindexclient?view=azure-python#azure-search-documents-indexes-searchindexclient-create-or-update-index&preserve-view=true) in the Azure SDK for Python, and similar methods in other Azure SDKs.
628
+
To update a vector store, modify the schema and reload documents to populate new fields. APIs for schema updates include [Create or Update Index (REST)](/rest/api/searchservice/indexes/create-or-update), [CreateOrUpdateIndex](/dotnet/api/azure.search.documents.indexes.searchindexclient.createorupdateindexasync) in the Azure SDK for .NET, [create_or_update_index](/python/api/azure-search-documents/azure.search.documents.indexes.searchindexclient?view=azure-python#azure-search-documents-indexes-searchindexclient-create-or-update-index&preserve-view=true) in the Azure SDK for Python, and similar methods in other Azure SDKs.
599
629
600
630
The standard guidance for updating an index is covered in [Update or rebuild an index](search-howto-reindex.md).
601
631
602
632
Key points include:
603
633
604
-
+ Drop and rebuild is often required for updates to and deletion of existing fields.
634
+
+ Drop and full index rebuild is often required for updates to and deletion of existing fields.
605
635
606
-
+However, you can update an existing schema with the following modifications, with no rebuild required:
636
+
+A few modifications can be made with no rebuild requirement:
607
637
608
638
+ Add new fields to a fields collection.
609
639
+ Add new vector configurations, assigned to new fields but not existing fields that have already been vectorized.
0 commit comments