diff --git a/qdrant_client/async_qdrant_remote.py b/qdrant_client/async_qdrant_remote.py index b67c3ccd..c9fc7933 100644 --- a/qdrant_client/async_qdrant_remote.py +++ b/qdrant_client/async_qdrant_remote.py @@ -9,8 +9,10 @@ # # ****** WARNING: THIS FILE IS AUTOGENERATED ****** +import importlib.metadata import logging import math +import platform import warnings from multiprocessing import get_all_start_methods from typing import ( @@ -71,7 +73,7 @@ def __init__( super().__init__(**kwargs) self._prefer_grpc = prefer_grpc self._grpc_port = grpc_port - self._grpc_options = grpc_options + self._grpc_options = grpc_options or {} self._https = https if https is not None else api_key is not None self._scheme = "https" if self._https else "http" self._prefix = prefix or "" @@ -116,6 +118,11 @@ def __init__( warnings.warn("Api key is used with an insecure connection.") self._rest_headers["api-key"] = api_key self._grpc_headers.append(("api-key", api_key)) + client_version = importlib.metadata.version("qdrant-client") + python_version = platform.python_version() + user_agent = f"qdrant-client/{client_version} python/{python_version}" + self._rest_headers["User-Agent"] = user_agent + self._grpc_options["grpc.primary_user_agent"] = user_agent grpc_compression: Optional[Compression] = kwargs.pop("grpc_compression", None) if grpc_compression is not None and (not isinstance(grpc_compression, Compression)): raise TypeError( diff --git a/qdrant_client/qdrant_remote.py b/qdrant_client/qdrant_remote.py index e716ef7d..b237a7c3 100644 --- a/qdrant_client/qdrant_remote.py +++ b/qdrant_client/qdrant_remote.py @@ -1,6 +1,8 @@ import asyncio +import importlib.metadata import logging import math +import platform import warnings from multiprocessing import get_all_start_methods from typing import ( @@ -63,7 +65,7 @@ def __init__( super().__init__(**kwargs) self._prefer_grpc = prefer_grpc self._grpc_port = grpc_port - self._grpc_options = grpc_options + self._grpc_options = grpc_options or {} self._https = https if https is not None else api_key is not None self._scheme = "https" if self._https else "http" @@ -133,6 +135,12 @@ def __init__( self._rest_headers["api-key"] = api_key self._grpc_headers.append(("api-key", api_key)) + client_version = importlib.metadata.version("qdrant-client") + python_version = platform.python_version() + user_agent = f"qdrant-client/{client_version} python/{python_version}" + self._rest_headers["User-Agent"] = user_agent + self._grpc_options["grpc.primary_user_agent"] = user_agent + # GRPC Channel-Level Compression grpc_compression: Optional[Compression] = kwargs.pop("grpc_compression", None) if grpc_compression is not None and not isinstance(grpc_compression, Compression): diff --git a/tests/test_qdrant_client.py b/tests/test_qdrant_client.py index 0afaa31f..4cc6292d 100644 --- a/tests/test_qdrant_client.py +++ b/tests/test_qdrant_client.py @@ -1,5 +1,7 @@ import asyncio +import importlib.metadata import os +import platform import uuid from pprint import pprint from tempfile import mkdtemp @@ -1964,11 +1966,20 @@ def test_timeout_propagation(): def test_grpc_options(): + client_version = importlib.metadata.version("qdrant-client") + user_agent = f"qdrant-client/{client_version}" + python_version = f"python/{platform.python_version()}" + client = QdrantClient(prefer_grpc=True) - assert client._client._grpc_options is None + assert client._client._grpc_options == { + "grpc.primary_user_agent": f"{user_agent} {python_version}" + } client = QdrantClient(prefer_grpc=True, grpc_options={"grpc.max_send_message_length": 3}) - assert client._client._grpc_options == {"grpc.max_send_message_length": 3} + assert client._client._grpc_options == { + "grpc.max_send_message_length": 3, + "grpc.primary_user_agent": f"{user_agent} {python_version}", + } with pytest.raises(RpcError): if not client.collection_exists("grpc_collection"):