AzureDocumentDBVectorSearch(
self,
collection: Collection,
embedding: Embeddings,
*,
index_name: str = | Name | Type | Description |
|---|---|---|
collection* | Collection | MongoDB collection to add the texts to. |
embedding* | Embeddings | Text embedding model to use. |
index_name | str | Default: 'vectorSearchIndex'Name of the Atlas Search index. |
text_key | str | Default: 'textContent' |
embedding_key | str | Default: 'vectorContent' |
application_name | str | Default: 'langchainpy' |
| Name | Type |
|---|---|
| collection | Collection |
| embedding | Embeddings |
| index_name | str |
| text_key | str |
| embedding_key | str |
| application_name | str |
Azure DocumentDB (with MongoDB compatibility) vector store.
To use, you should have both:
pymongo python package installedpymongo.collection.Collection for an Azure
DocumentDB clusterExample:
.. 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,
)
MongoDB field that will contain the text for each document.
MongoDB field that will contain the embedding for each document.
The user agent for telemetry