Add Wrapping Library Metadata to MongoDB vector store (#13084)

**Description**
MongoDB drivers are used in various flavors and languages. Making sure
we exercise our due diligence in identifying the "origin" of the library
calls makes it best to understand how our Atlas servers get accessed.
This commit is contained in:
Noah Stapp 2023-11-16 22:20:04 -08:00 committed by GitHub
parent 21552628c8
commit c1b041c188
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -102,13 +102,18 @@ class MongoDBAtlasVectorSearch(VectorStore):
""" """
try: try:
from pymongo import MongoClient from importlib.metadata import version
from pymongo import DriverInfo, MongoClient
except ImportError: except ImportError:
raise ImportError( raise ImportError(
"Could not import pymongo, please install it with " "Could not import pymongo, please install it with "
"`pip install pymongo`." "`pip install pymongo`."
) )
client: MongoClient = MongoClient(connection_string) client: MongoClient = MongoClient(
connection_string,
driver=DriverInfo(name="Langchain", version=version("langchain")),
)
db_name, collection_name = namespace.split(".") db_name, collection_name = namespace.split(".")
collection = client[db_name][collection_name] collection = client[db_name][collection_name]
return cls(collection, embedding, **kwargs) return cls(collection, embedding, **kwargs)