# AzureDocumentDBVectorSearch

> **Class** in `langchain_azure_cosmosdb`

📖 [View in docs](https://reference.langchain.com/python/langchain-azure-cosmosdb/_vectorstore_documentdb/AzureDocumentDBVectorSearch)

`Azure DocumentDB (with MongoDB compatibility)` vector store.

To use, you should have both:
- the ``pymongo`` python package installed
- an authenticated ``pymongo.collection.Collection`` for an Azure
  DocumentDB cluster

## Signature

```python
AzureDocumentDBVectorSearch(
    self,
    collection: Collection,
    embedding: Embeddings,
    *,
    index_name: str = 'vectorSearchIndex',
    text_key: str = 'textContent',
    embedding_key: str = 'vectorContent',
    application_name: str = 'langchainpy',
)
```

## Description

**Example:**

.. code-block:: python

    from langchain_azure_cosmosdb import AzureDocumentDBVectorSearch
    from langchain_openai import OpenAIEmbeddings
    from pymongo import MongoClient

    mongo_client = MongoClient("<YOUR-CONNECTION-STRING>")
    collection = mongo_client["<db_name>"]["<collection_name>"]
    embeddings = OpenAIEmbeddings()
    vectorstore = AzureDocumentDBVectorSearch(collection, embeddings)

Microsoft Entra ID can be used through PyMongo's ``MONGODB-OIDC``
authentication mechanism:

.. code-block:: python

    from azure.identity import DefaultAzureCredential
    from pymongo import MongoClient
    from pymongo.auth_oidc import (
        OIDCCallback,
        OIDCCallbackContext,
        OIDCCallbackResult,
    )

    class AzureIdentityTokenCallback(OIDCCallback):
        def __init__(self, credential):
            self.credential = credential

        def fetch(self, context: OIDCCallbackContext):
            token = self.credential.get_token(
                "https://ossrdbms-aad.database.windows.net/.default"
            )
            return OIDCCallbackResult(access_token=token.token)

    credential = DefaultAzureCredential()
    mongo_client = MongoClient(
        "mongodb+srv://<cluster-name>.global.mongocluster.cosmos.azure.com/",
        authMechanism="MONGODB-OIDC",
        authMechanismProperties={
            "OIDC_CALLBACK": AzureIdentityTokenCallback(credential),
        },
        retryWrites=False,
        tls=True,
    )

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `collection` | `Collection` | Yes | MongoDB collection to add the texts to. |
| `embedding` | `Embeddings` | Yes | Text embedding model to use. |
| `index_name` | `str` | No | Name of the Atlas Search index. (default: `'vectorSearchIndex'`) |
| `text_key` | `str` | No | MongoDB field that will contain the text for each document. (default: `'textContent'`) |
| `embedding_key` | `str` | No | MongoDB field that will contain the embedding for each document. (default: `'vectorContent'`) |
| `application_name` | `str` | No | The user agent for telemetry (default: `'langchainpy'`) |

## Extends

- `VectorStore`

## Constructors

```python
__init__(
    self,
    collection: Collection,
    embedding: Embeddings,
    *,
    index_name: str = 'vectorSearchIndex',
    text_key: str = 'textContent',
    embedding_key: str = 'vectorContent',
    application_name: str = 'langchainpy',
)
```

| Name | Type |
|------|------|
| `collection` | `Collection` |
| `embedding` | `Embeddings` |
| `index_name` | `str` |
| `text_key` | `str` |
| `embedding_key` | `str` |
| `application_name` | `str` |


## Properties

- `embeddings`

## Methods

- [`get_index_name()`](https://reference.langchain.com/python/langchain-azure-cosmosdb/_vectorstore_documentdb/AzureDocumentDBVectorSearch/get_index_name)
- [`from_connection_string()`](https://reference.langchain.com/python/langchain-azure-cosmosdb/_vectorstore_documentdb/AzureDocumentDBVectorSearch/from_connection_string)
- [`index_exists()`](https://reference.langchain.com/python/langchain-azure-cosmosdb/_vectorstore_documentdb/AzureDocumentDBVectorSearch/index_exists)
- [`delete_index()`](https://reference.langchain.com/python/langchain-azure-cosmosdb/_vectorstore_documentdb/AzureDocumentDBVectorSearch/delete_index)
- [`create_index()`](https://reference.langchain.com/python/langchain-azure-cosmosdb/_vectorstore_documentdb/AzureDocumentDBVectorSearch/create_index)
- [`create_filter_index()`](https://reference.langchain.com/python/langchain-azure-cosmosdb/_vectorstore_documentdb/AzureDocumentDBVectorSearch/create_filter_index)
- [`add_texts()`](https://reference.langchain.com/python/langchain-azure-cosmosdb/_vectorstore_documentdb/AzureDocumentDBVectorSearch/add_texts)
- [`from_texts()`](https://reference.langchain.com/python/langchain-azure-cosmosdb/_vectorstore_documentdb/AzureDocumentDBVectorSearch/from_texts)
- [`delete()`](https://reference.langchain.com/python/langchain-azure-cosmosdb/_vectorstore_documentdb/AzureDocumentDBVectorSearch/delete)
- [`delete_document_by_id()`](https://reference.langchain.com/python/langchain-azure-cosmosdb/_vectorstore_documentdb/AzureDocumentDBVectorSearch/delete_document_by_id)
- [`similarity_search_with_score()`](https://reference.langchain.com/python/langchain-azure-cosmosdb/_vectorstore_documentdb/AzureDocumentDBVectorSearch/similarity_search_with_score)
- [`similarity_search()`](https://reference.langchain.com/python/langchain-azure-cosmosdb/_vectorstore_documentdb/AzureDocumentDBVectorSearch/similarity_search)
- [`max_marginal_relevance_search_by_vector()`](https://reference.langchain.com/python/langchain-azure-cosmosdb/_vectorstore_documentdb/AzureDocumentDBVectorSearch/max_marginal_relevance_search_by_vector)
- [`max_marginal_relevance_search()`](https://reference.langchain.com/python/langchain-azure-cosmosdb/_vectorstore_documentdb/AzureDocumentDBVectorSearch/max_marginal_relevance_search)
- [`get_collection()`](https://reference.langchain.com/python/langchain-azure-cosmosdb/_vectorstore_documentdb/AzureDocumentDBVectorSearch/get_collection)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-azure/blob/e62c2a55aaa0942fdac739b4066011953b80018e/libs/azure-cosmosdb/src/langchain_azure_cosmosdb/_vectorstore_documentdb.py#L65)