Skip to content

Commit 28e2fa6

Browse files
authored
INTPYTHON-724 - Add DriverInfo metadata to MongoDB connector (#13379)
### Motivation and Context This PR updates the MongoDB connector to use best practices for DriverInfo while connecting to the database. ### Description ### Contribution Checklist Passing MongoDB connector tests: https://spruce.mongodb.com/task/ai_ml_pipeline_testing_test_semantic_kernel_python_rhel_test_semantic_kernel_python_local_patch_888cccaf0dc36ca794fde4fd82cb1f997e5a4211_69209c01107dec0007300089_25_11_21_17_06_20/logs?execution=0 <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄
1 parent 42716d5 commit 28e2fa6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

python/semantic_kernel/connectors/mongodb.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
DistanceFunction.DOT_PROD: "dotProduct",
6565
DistanceFunction.DEFAULT: "euclidean",
6666
}
67+
DRIVER_METADATA = DriverInfo(SEMANTIC_KERNEL_USER_AGENT, metadata.version("semantic-kernel"))
6768

6869
logger = logging.getLogger(__name__)
6970

@@ -210,6 +211,8 @@ def __init__(
210211
managed_client=managed_client,
211212
embedding_generator=embedding_generator,
212213
)
214+
if callable(mongo_client.append_metadata):
215+
mongo_client.append_metadata(DRIVER_METADATA)
213216
return
214217

215218
try:
@@ -225,7 +228,7 @@ def __init__(
225228

226229
mongo_client = AsyncMongoClient(
227230
mongodb_atlas_settings.connection_string.get_secret_value(),
228-
driver=DriverInfo(SEMANTIC_KERNEL_USER_AGENT, metadata.version("semantic-kernel")),
231+
driver=DRIVER_METADATA,
229232
)
230233

231234
super().__init__(
@@ -565,6 +568,8 @@ def __init__(
565568
database_name=database_name or DEFAULT_DB_NAME,
566569
embedding_generator=embedding_generator,
567570
)
571+
if callable(mongo_client.append_metadata):
572+
mongo_client.append_metadata(DRIVER_METADATA)
568573
return
569574

570575
try:
@@ -581,7 +586,7 @@ def __init__(
581586

582587
mongo_client = AsyncMongoClient(
583588
mongodb_atlas_settings.connection_string.get_secret_value(),
584-
driver=DriverInfo(SEMANTIC_KERNEL_USER_AGENT, metadata.version("semantic-kernel")),
589+
driver=DRIVER_METADATA,
585590
)
586591

587592
super().__init__(

0 commit comments

Comments
 (0)