Azure Cosmos DB for NoSQL vCore vector store. To use this, you should have both:

  • the @azure/cosmos NPM package installed
  • a connection string associated with a NoSQL instance

You do not need to create a database or container, it will be created automatically.

Hierarchy

  • VectorStore
    • AzureCosmosDBNoSQLVectorStore

Constructors

Properties

embeddings: EmbeddingsInterface

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

initialize: (() => Promise<void>)

Initializes the AzureCosmosDBNoSQLVectorStore. Connect the client to the database and create the container, creating them if needed.

Type declaration

    • (): Promise<void>
    • Returns Promise<void>

      A promise that resolves when the AzureCosmosDBNoSQLVectorStore has been initialized.

Methods

  • Method for adding documents to the AzureCosmosDBNoSQLVectorStore. It first converts the documents to texts and then adds them as vectors.

    Parameters

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

      The documents to add.

    Returns Promise<string[]>

    A promise that resolves to the added documents IDs.

  • Method for adding vectors to the AzureCosmosDBNoSQLVectorStore.

    Parameters

    • vectors: number[][]

      Vectors to be added.

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

      Corresponding documents to be added.

    Returns Promise<string[]>

    A promise that resolves to the added documents IDs.

  • Creates a VectorStoreRetriever instance with flexible configuration options.

    Parameters

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

      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: AzureCosmosDBNoSQLFilterType

      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<AzureCosmosDBNoSQLVectorStore>

    • 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 },
    });
  • Return documents selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to the query AND diversity among selected documents.

    Parameters

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

    List of documents selected by maximal marginal relevance.

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

    Parameters

    • query: string

      Query text for the similarity search.

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

      Optional filter options for the documents.

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

    Promise that resolves to a list of documents.

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

    Parameters

    • queryVector: number[]

      Query vector for the similarity search.

    • k: number = 4
    • filter: undefined | AzureCosmosDBNoSQLFilterType = 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.

  • Searches for documents similar to a text query by embedding the query, and returns results with similarity scores.

    Parameters

    • query: string

      Text query for finding similar documents.

    • Optionalk: number

      Number of similar results to return. Defaults to 4.

    • Optionalfilter: AzureCosmosDBNoSQLFilterType

      Optional filter based on FilterType.

    • Optional_callbacks: Callbacks

      Optional callbacks for monitoring search progress

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

    A promise resolving to an array of tuples, each containing a document and its similarity score.

  • Returns Serialized

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

    Parameters

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

      List of documents to be converted to vectors.

    • embeddings: EmbeddingsInterface

      Embeddings to be used for conversion.

    • dbConfig: AzureCosmosDBNoSQLConfig

      Database configuration for Azure Cosmos DB for NoSQL.

    Returns Promise<AzureCosmosDBNoSQLVectorStore>

    Promise that resolves to a new instance of AzureCosmosDBNoSQLVectorStore.

  • Static method to create an instance of AzureCosmosDBNoSQLVectorStore 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.

    • dbConfig: AzureCosmosDBNoSQLConfig

      Database configuration for Azure Cosmos DB for NoSQL.

    Returns Promise<AzureCosmosDBNoSQLVectorStore>

    Promise that resolves to a new instance of AzureCosmosDBNoSQLVectorStore.