Azure AI Search vector store. To use this, you should have:

  • the @azure/search-documents NPM package installed
  • an endpoint and key to the Azure AI Search instance

If you directly provide a SearchClient instance, you need to ensure that an index has been created. When using and endpoint and key, the index will be created automatically if it does not exist.

Hierarchy

  • VectorStore
    • AzureAISearchVectorStore

Constructors

Properties

embeddings: EmbeddingsInterface

Embeddings interface for generating vector embeddings from text queries, enabling vector-based similarity searches.

Methods

  • Adds vectors to the AzureAISearchVectorStore.

    Parameters

    • vectors: number[][]

      Vectors to be added.

    • documents: Document<Record<string, any>>[]

      Corresponding documents to be added.

    • Optionaloptions: AzureAISearchAddDocumentsOptions

      Options for adding documents.

    Returns Promise<string[]>

    A promise that resolves to the ids of the added documents.

  • Creates a VectorStoreRetriever instance with flexible configuration options.

    Parameters

    • OptionalkOrFields: number | Partial<VectorStoreRetrieverInput<AzureAISearchVectorStore>>

      If a number is provided, it sets the k parameter (number of items to retrieve).

      • If an object is provided, it should contain various configuration options.
    • Optionalfilter: AzureAISearchFilterType

      Optional filter criteria to limit the items retrieved based on the specified filter type.

    • Optionalcallbacks: Callbacks

      Optional callbacks that may be triggered at specific stages of the retrieval process.

    • Optionaltags: string[]

      Tags to categorize or label the VectorStoreRetriever. Defaults to an empty array if not provided.

    • Optionalmetadata: Record<string, unknown>

      Additional metadata as key-value pairs to add contextual information for the retrieval process.

    • Optionalverbose: boolean

      If true, enables detailed logging for the retrieval process. Defaults to false.

    Returns VectorStoreRetriever<AzureAISearchVectorStore>

    • A configured VectorStoreRetriever instance based on the provided parameters.

    Basic usage with a k value:

    const retriever = myVectorStore.asRetriever(5);
    

    Usage with a configuration object:

    const retriever = myVectorStore.asRetriever({
    k: 10,
    filter: myFilter,
    tags: ['example', 'test'],
    verbose: true,
    searchType: 'mmr',
    searchKwargs: { alpha: 0.5 },
    });
  • Removes specified documents from the AzureAISearchVectorStore using IDs or a filter.

    Parameters

    • params: {
          filter?: AzureAISearchFilterType;
          ids?: string | string[];
      }

      Object that includes either an array of IDs or a filter for the data to be deleted.

    Returns Promise<void>

    A promise that resolves when the documents have been removed.

  • Protected

    Ensures that an index exists on the AzureAISearchVectorStore.

    Parameters

    • indexClient: SearchIndexClient

      The Azure AI Search index client.

    Returns Promise<void>

    A promise that resolves when the AzureAISearchVectorStore index has been initialized.

  • Performs a hybrid search using query text.

    Parameters

    • query: string

      Query text for the similarity search.

    • OptionalqueryVector: number[]

      Query vector for the similarity search. If not provided, the query text will be embedded.

    • k: number = 4
    • filter: undefined | AzureAISearchFilterType = undefined

      Optional filter options for the documents.

    Returns Promise<[Document<Record<string, any>>, number][]>

    Promise that resolves to a list of documents and their corresponding similarity scores.

  • Return documents selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to the query AND diversity among selected documents.

    Parameters

    • query: string

      Text to look up documents similar to.

    • options: MaxMarginalRelevanceSearchOptions<AzureAISearchFilterType>

    Returns Promise<Document<Record<string, any>>[]>

    List of documents selected by maximal marginal relevance.

  • Performs a hybrid search with semantic reranker using query text.

    Parameters

    • query: string

      Query text for the similarity search.

    • OptionalqueryVector: number[]

      Query vector for the similarity search. If not provided, the query text will be embedded.

    • k: number = 4
    • filter: undefined | AzureAISearchFilterType = undefined

      Optional filter options for the documents.

    Returns Promise<[Document<Record<string, any>>, number][]>

    Promise that resolves to a list of documents and their corresponding similarity scores.

  • Performs a similarity search using query type specified in configuration. If the query type is not specified, it defaults to similarity search.

    Parameters

    • query: string

      Query text for the similarity search.

    • k: number = 4
    • filter: undefined | AzureAISearchFilterType = undefined

      Optional filter options for the documents.

    Returns Promise<Document<Record<string, any>>[]>

    Promise that resolves to a list of documents and their corresponding similarity scores.

  • Performs a similarity search on the vectors stored in the collection.

    Parameters

    Returns Promise<[Document<Record<string, any>>, number][]>

    Promise that resolves to a list of documents and their corresponding similarity scores.

  • Performs a similarity search using query type specified in configuration. If the query type is not specified, it defaults to similarity hybrid search.

    Parameters

    • query: string

      Query text for the similarity search.

    • k: number = 4
    • filter: undefined | AzureAISearchFilterType = undefined

      Optional filter options for the documents.

    Returns Promise<[Document<Record<string, any>>, number][]>

    Promise that resolves to a list of documents and their corresponding similarity scores.

  • Returns Serialized

  • Static method to create an instance of AzureAISearchVectorStore from a list of texts. It first converts the texts to vectors and then adds them to the collection.

    Parameters

    • texts: string[]

      List of texts to be converted to vectors.

    • metadatas: object | object[]

      Metadata for the texts.

    • embeddings: EmbeddingsInterface

      Embeddings to be used for conversion.

    • config: AzureAISearchConfig

      Database configuration for Azure AI Search.

    Returns Promise<AzureAISearchVectorStore>

    Promise that resolves to a new instance of AzureAISearchVectorStore.