Skip to content

Commit 4a1886d

Browse files
authored
INTPYTHON-758 - Add append_metadata helper (#6)
1 parent ab22353 commit 4a1886d

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pymongo_vectorsearch_utils/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
text_search_stage,
1414
vector_search_stage,
1515
)
16+
from .util import append_client_metadata
1617

1718
__all__ = [
1819
"__version__",
@@ -26,4 +27,5 @@
2627
"reciprocal_rank_stage",
2728
"final_hybrid_stage",
2829
"bulk_embed_and_insert_texts",
30+
"append_client_metadata",
2931
]

pymongo_vectorsearch_utils/util.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import logging
22
from typing import Any
33

4+
from pymongo import AsyncMongoClient, MongoClient
5+
from pymongo.driver_info import DriverInfo
6+
47
logger = logging.getLogger(__file__)
58

69

@@ -42,3 +45,9 @@ def oid_to_str(oid: Any) -> str:
4245
24 character hex string.
4346
"""
4447
return str(oid)
48+
49+
50+
def append_client_metadata(client: MongoClient | AsyncMongoClient, driver_info: DriverInfo) -> None:
51+
# append_metadata was added in PyMongo 4.14.0, but is a valid database name on earlier versions
52+
if callable(client.append_metadata):
53+
client.append_metadata(driver_info)

0 commit comments

Comments
 (0)