Muokkaa

Share via


Choose an Azure service for vector search

Vector search is a method of finding information stored in a database in the shape of vectors. Vectors are groups of numbers that represent features or characteristics of media, such as text or images. Vectors are a significant advancement over traditional keyword-based search methods. They offer faster, more accurate results by understanding the semantic relationships within the information.

Azure offers multiple ways to store and search vectorized data. This article helps architects and developers who need to understand and choose the right Azure service for vector search for their application.

This article compares the following services based on their vector search capabilities:

Architects and developers should compare the available services from the perspective of system requirements in Choose a candidate service and in Capability matrix.

Choose a candidate service

This section helps you select the most likely services for your needs. To narrow the choices, start by considering the system requirements.

Key requirements

A flow chart that helps you choose the right Azure service for vector search.

When deciding whether to use a traditional database solution or Azure AI Search service, consider your requirements and whether you can perform live or real-time vector searching on your data. A traditional relational or NoSQL database is the best fit for your scenario if you change values in vectorized fields frequently and the changes need to be searchable in real time or near real time. Likewise, using your existing database might be the best solution for you to meet your performance targets. On the other hand, if your workload doesn't require real-time or near real-time vector searchability, and you accept managing an index of vectors, AI Search can be a compelling choice.

If you choose a traditional database solution, the specific type of database service you decide to use mostly depends on your team's skill set and the databases that you currently operate. If you already use a specific type of database, like MongoDB for example, then using that same type of database might be the easiest solution for your scenario. As shown in the Capability matrix section, each database service has some unique capabilities and limitations for vector search. Review that information to ensure that your preferred database type supports the functionality you require.

If cost concerns are a driving factor, maintaining your existing design is likely the best fit for your scenario because introducing new services or other instances of a database service can add new net costs and complexity. Using your current databases for vector search likely affects your costs less than using a dedicated service.

If you choose to use a traditional database instead of AI Search, some advanced search features aren't available by default. For example, if you want to do reranking or hybrid search, enable that functionality through Transact-SQL (T-SQL) or other coding.

Capability matrix

The tables in this section summarize the key differences in capabilities.

Basic features

Native support for vector data types, artificial neural network (ANN) vector indexes, vector dimension limits, multiple vector fields, and multiple vector indexes are sometimes different between the services. Your workload requirements might require some of these specific features. Understand the basic vector features of each Azure service, as shown in the following table.

Capability Azure Cosmos DB for PostgreSQL Azure Cosmos DB for MongoDB (vCore) Azure Database for PostgreSQL (Flex) Azure AI Search Azure SQL Database
Built-in vector search Yes 1 Yes 2 Yes 1 Yes 3 No 4
Vector data type Yes Yes Yes Yes No 5
Dimension limits 6 16,000 7 or 2,000 2,000 16,000 7 or 2,000 3,072 Unlimited
Multiple vector fields Yes No Yes Yes N/A
Multiple vector indexes Yes No Yes Yes N/A
  1. pgvector supports vector search, which is the extension of Azure Database for PostgreSQL.
  2. Use vector search on embeddings in Azure Cosmos DB for MongoDB (vCore).
  3. Vectors in Azure AI Search.
  4. Vector search isn't provided as a first-class feature, but it can be implemented by using columnstore indexes and functions for cosine similarity.
  5. Unpivot dimension (array) to table row. Vectors are stored with columnstore index.
  6. Embedding models from OpenAI, 1536 for both text-embedding-ada-002 and text-embedding-3-small, and 3072 for text-embedding-3-large. For Azure AI Vision multimodal embedding models, 1024 for both image and text.
  7. Vectors can have up to 16,000 dimensions. But indexing by using Inverted File with Flat Compression (IVFFlat) and Hierarchical Navigable Small World (HNSW) supports vectors with up to 2,000 dimensions.

Search methods

Workloads often need to combine vector search with full text search or even a hybrid search (full text search or semantic search plus vector search). The combination of hybrid search and reranking achieves high accuracy for workloads. You can manually implement hybrid search and reranking with your own code, or you can consider how your vector store supports this workload requirement.

Search method Azure Cosmos DB for PostgreSQL Azure Cosmos DB for MongoDB (vCore) Azure Database for PostgreSQL (Flex) Azure AI Search Azure SQL Database
Full text search Yes 1 Yes 2 Yes 1 Yes 3 Yes 4
Hybrid search Yes 5 No Yes 5 Yes 6 Yes 7
Built-in reranking No No No Yes 8 No
  1. PostgreSQL full text search.
  2. Search and query with text indexes in Azure Cosmos DB for MongoDB (vCore).
  3. Get started with full text search.
  4. Vector data on SQL Server.
  5. Not provided as a first-class feature, but sample codes are provided.
  6. Hybrid search (combination of full text search, vector search, and semantic ranking) is provided as a first-class feature.
  7. Hybrid search example for Azure SQL database and SQL Server.
  8. Reranking called semantic ranking is a first-class feature for reranking the result of full text search and vector search.

Vector data indexing algorithms

Vector data indexing is the ability to efficiently store and retrieve vectors. This capability is important because indexing influences speed and accuracy of similarity searches and nearest neighbor queries on data sources.

Indexes are typically based on an exhaustive k-nearest neighbor (Ek-NN) or an ANN algorithm. Ek-NN does an exhaustive search on all data points one by one and returns the accurate K nearest neighbors. Ek-NN works in milliseconds with a small amount of data but can cause latency for large amounts of data.

HNSW and IVFFlat are ANN algorithm indexes. Selecting the appropriate indexing strategy involves a careful consideration of various factors such as the nature of the dataset, the specific requirements of the queries, and the available resources. IVFFlat is effective in environments where hardware resources are limited or query volumes aren't high. HNSW excels in systems that require fast query responses and can adapt to changes in the dataset.

Understand what kinds of vector data indexing are provided from the following table.

Indexing approach Azure Cosmos DB for PostgreSQL Azure Cosmos DB for MongoDB (vCore) Azure Database for PostgreSQL (Flex) Azure AI Search Azure SQL Database
Exhaustive k-nearest neighbor (Ek-NN) Yes Yes Yes Yes Yes
Hierarchical Navigable Small World (HNSW) Yes Yes (preview)1 Yes Yes No
IVFFlat Yes Yes Yes No No
Other - Vector field limitation 2
Vector index limitation 3
- - No native vector index support4
  1. Azure Cosmos DB for MongoDB - Vector search overview.
  2. Only one vector field is available per container.
  3. Only one vector index is available per container.
  4. Azure SQL Database doesn't have vector data type. But you can store vectors into a column. Each row holds each element of vectors. Then you can use columnstore index to efficiently store and search for vectors.

Similarity and distance calculation capabilities

There are Cosine similarity, Dot product, and Euclidean distance calculation methods for vector search. These methods are used to calculate the similarity between two vectors or the distance between two vectors.

Preliminary data analysis benefits from both metrics and Euclidean distances, which allow for the extraction of different insights on data structure, whereas text classification generally performs better under Euclidean distances. Retrieval of the most similar texts to a given text typically functions better with cosine similarity.

Azure OpenAI Service embeddings rely on cosine similarity to compute similarity between documents and a query.

Built-in vector comparison calculation Azure Cosmos DB for PostgreSQL Azure Cosmos DB for MongoDB (vCore) Azure Database for PostgreSQL (Flex) Azure AI Search Azure SQL Database
Cosine similarity Yes Yes Yes Yes Yes 1
Euclidean distance (L2 distance) Yes Yes Yes Yes Yes 1
Dot product Yes Yes Yes Yes Yes 1
  1. Distance calculation examples for Azure SQL database and SQL Server.

Integration with Azure OpenAI and other components

When implementing vector search, you can also consider linking with other Microsoft components. For example, Azure OpenAI Service helps you create vectors for your data and input queries for vector similarity search.

Capability Azure Cosmos DB for PostgreSQL Azure Cosmos DB for MongoDB (vCore) Azure Database for PostgreSQL (Flex) Azure AI Search Azure SQL Database
Azure OpenAI Service - add your own data No Yes 1 No Yes 2 No
Vector embedding with Azure OpenAI No No Yes 3 Yes 4 Yes 5
Integration with prompt flow No No No Yes 6 No
Integration with Semantic Kernel Yes 7 Yes 8 Yes 7 Yes 9 Yes 10
  1. Azure Cosmos DB for MongoDB (vCore) is supported as a data source for Azure OpenAI on your data.
  2. Azure AI Search is supported as a data source for Azure OpenAI on your data.
  3. Azure AI Extension (preview) is available.
  4. Azure AI Search provides a skill to vectorize the chunked text.
  5. You can create a stored procedure for your embedding model deployment.
  6. Supported as a vector database in Vector DB Lookup tool.
  7. Supported as a memory connector, and a vector database connector (C#).
  8. Supported as a vector database connector (Python).
  9. Supported as a memory connector, and a vector database connector (C#, Python).
  10. Supported as a memory connector.

Contributors

This article is maintained by Microsoft. It was originally written by the following contributors.

Principal authors:

Other contributors:

To see non-public LinkedIn profiles, sign in to LinkedIn.

Next step

Implement knowledge mining with Azure AI Search. This learning path explores how to use Azure AI Search.