Class AzureVectorStore

java.lang.Object
org.springframework.ai.vectorstore.azure.AzureVectorStore
All Implemented Interfaces:
Consumer<List<Document>>, DocumentWriter, VectorStore, org.springframework.beans.factory.InitializingBean

public class AzureVectorStore extends Object implements VectorStore, org.springframework.beans.factory.InitializingBean
Uses Azure Cognitive Search as a backing vector store. Documents can be preloaded into a Cognitive Search index and managed via Azure tools or added and managed through this VectorStore. The underlying index is configured in the provided Azure SearchIndexClient.
Author:
Greg Meyer, Xiangyang Yu, Christian Tzolov
  • Field Details

  • Constructor Details

    • AzureVectorStore

      public AzureVectorStore(com.azure.search.documents.indexes.SearchIndexClient searchIndexClient, EmbeddingClient embeddingClient)
      Constructs a new AzureCognitiveSearchVectorStore.
      Parameters:
      searchIndexClient - A pre-configured Azure SearchIndexClient that CRUD for Azure search indexes and factory for SearchClient.
      embeddingClient - The client for embedding operations.
    • AzureVectorStore

      public AzureVectorStore(com.azure.search.documents.indexes.SearchIndexClient searchIndexClient, EmbeddingClient embeddingClient, List<AzureVectorStore.MetadataField> filterMetadataFields)
      Constructs a new AzureCognitiveSearchVectorStore.
      Parameters:
      searchIndexClient - A pre-configured Azure SearchIndexClient that CRUD for Azure search indexes and factory for SearchClient.
      embeddingClient - The client for embedding operations.
      filterMetadataFields - List of metadata fields (as field name and type) that can be used in similarity search query filter expressions.
  • Method Details

    • setIndexName

      public void setIndexName(String indexName)
      Change the Index Name.
      Parameters:
      indexName - The Azure VectorStore index name to use.
    • setDefaultTopK

      public void setDefaultTopK(int topK)
      Sets the a default maximum number of similar documents returned.
      Parameters:
      topK - The default maximum number of similar documents returned.
    • setDefaultSimilarityThreshold

      public void setDefaultSimilarityThreshold(Double similarityThreshold)
      Sets the a default similarity threshold for returned documents.
      Parameters:
      similarityThreshold - The a default similarity threshold for returned documents.
    • add

      public void add(List<Document> documents)
      Description copied from interface: VectorStore
      Adds list of Documents to the vector store.
      Specified by:
      add in interface VectorStore
      Parameters:
      documents - the list of documents to store. Throws an exception if the underlying provider checks for duplicate IDs.
    • delete

      public Optional<Boolean> delete(List<String> documentIds)
      Description copied from interface: VectorStore
      Deletes documents from the vector store.
      Specified by:
      delete in interface VectorStore
      Parameters:
      documentIds - list of document ids for which documents will be removed.
      Returns:
    • similaritySearch

      public List<Document> similaritySearch(String query)
      Description copied from interface: VectorStore
      Retrieves documents by query embedding similarity using the default SearchRequest's' search criteria.
      Specified by:
      similaritySearch in interface VectorStore
      Parameters:
      query - Text to use for embedding similarity comparison.
      Returns:
      Returns a list of documents that have embeddings similar to the query text embedding.
    • similaritySearch

      public List<Document> similaritySearch(SearchRequest request)
      Description copied from interface: VectorStore
      Retrieves documents by query embedding similarity and metadata filters to retrieve exactly the number of nearest-neighbor results that match the request criteria.
      Specified by:
      similaritySearch in interface VectorStore
      Parameters:
      request - Search request for set search parameters, such as the query text, topK, similarity threshold and metadata filter expressions.
      Returns:
      Returns documents th match the query request conditions.
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception