Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Added init_options property #541

Merged
merged 6 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading