Skip to content

Commit

Permalink
chore: Added init_options property (#541)
Browse files Browse the repository at this point in the history
* chore: Added init_options property

* refactor: @Property

* test: init_opts

* chore: regen async client again with Py 3.10

* chore: deepcopy kwargs
  • Loading branch information
Anush008 authored Jul 17, 2024
1 parent a5023f6 commit a0d263e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
16 changes: 16 additions & 0 deletions qdrant_client/async_qdrant_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# ****** WARNING: THIS FILE IS AUTOGENERATED ******

import warnings
from copy import deepcopy
from typing import (
Any,
Awaitable,
Expand Down Expand Up @@ -105,6 +106,12 @@ def __init__(
**kwargs: Any,
):
super().__init__(**kwargs)
self._init_options = {
key: value
for (key, value) in locals().items()
if key not in ("self", "__class__", "kwargs")
}
self._init_options.update(deepcopy(kwargs))
self._client: AsyncQdrantBase
if sum([param is not None for param in (location, url, host, path)]) > 1:
raise ValueError(
Expand Down Expand Up @@ -189,6 +196,15 @@ def http(self) -> AsyncApis[AsyncApiClient]:
return self._client.http
raise NotImplementedError(f"REST client is not supported for {type(self._client)}")

@property
def init_options(self) -> Dict[str, Any]:
"""`__init__` Options
Returns:
A dictionary of options the client class was instantiated with
"""
return self._init_options

async def search_batch(
self,
collection_name: str,
Expand Down
19 changes: 19 additions & 0 deletions qdrant_client/qdrant_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import warnings
from copy import deepcopy
from typing import (
Any,
Awaitable,
Expand Down Expand Up @@ -101,6 +102,15 @@ def __init__(
# we will need to pop them from **kwargs. Otherwise, they might be passed to QdrantRemote as httpx kwargs.
# Httpx has specific set of params, which it accepts and will raise an error if it receives any other params.

# Saving the init options to facilitate building AsyncQdrantClient from QdrantClient and vice versa.
# Eg. AsyncQdrantClient(**sync_client.init_options) or QdrantClient(**async_client.init_options)
self._init_options = {
key: value
for key, value in locals().items()
if key not in ("self", "__class__", "kwargs")
}
self._init_options.update(deepcopy(kwargs))

self._client: QdrantBase

if sum([param is not None for param in (location, url, host, path)]) > 1:
Expand Down Expand Up @@ -220,6 +230,15 @@ def http(self) -> SyncApis[ApiClient]:

raise NotImplementedError(f"REST client is not supported for {type(self._client)}")

@property
def init_options(self) -> Dict[str, Any]:
"""`__init__` Options
Returns:
A dictionary of options the client class was instantiated with
"""
return self._init_options

def search_batch(
self,
collection_name: str,
Expand Down
7 changes: 7 additions & 0 deletions tests/test_qdrant_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ def test_client_init():
):
QdrantClient(**params)

client = QdrantClient(
url="http://localhost:6333", prefix="custom", metadata={"some-rest-meta": "some-value"}
)
assert client.init_options["url"] == "http://localhost:6333"
assert client.init_options["prefix"] == "custom"
assert client.init_options["metadata"] == {"some-rest-meta": "some-value"}


@pytest.mark.parametrize("prefer_grpc", [False, True])
@pytest.mark.parametrize("parallel", [1, 2])
Expand Down

0 comments on commit a0d263e

Please sign in to comment.