From c1b041c188fdac469920078fde66d55f016df101 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Thu, 16 Nov 2023 22:20:04 -0800 Subject: [PATCH] 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. --- libs/langchain/langchain/vectorstores/mongodb_atlas.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/langchain/langchain/vectorstores/mongodb_atlas.py b/libs/langchain/langchain/vectorstores/mongodb_atlas.py index b9dcfbfc05..b7caec575f 100644 --- a/libs/langchain/langchain/vectorstores/mongodb_atlas.py +++ b/libs/langchain/langchain/vectorstores/mongodb_atlas.py @@ -102,13 +102,18 @@ class MongoDBAtlasVectorSearch(VectorStore): """ try: - from pymongo import MongoClient + from importlib.metadata import version + + from pymongo import DriverInfo, MongoClient except ImportError: raise ImportError( "Could not import pymongo, please install it with " "`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(".") collection = client[db_name][collection_name] return cls(collection, embedding, **kwargs)