Skip to content

Commit

Permalink
new: Send client version to server in headers (#861)
Browse files Browse the repository at this point in the history
* new: Send client version in request's headers (http and gRpc)
  • Loading branch information
tellet-q authored Dec 5, 2024
1 parent baa3e26 commit ebc358c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
9 changes: 8 additions & 1 deletion qdrant_client/async_qdrant_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 ""
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 9 additions & 1 deletion qdrant_client/qdrant_remote.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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):
Expand Down
15 changes: 13 additions & 2 deletions tests/test_qdrant_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
import importlib.metadata
import os
import platform
import uuid
from pprint import pprint
from tempfile import mkdtemp
Expand Down Expand Up @@ -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"):
Expand Down

0 comments on commit ebc358c

Please sign in to comment.