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

new: prohibit setting more than one param from host, url, location, path #386

Merged
merged 1 commit into from
Nov 30, 2023
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
4 changes: 4 additions & 0 deletions qdrant_client/async_qdrant_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def __init__(
):
super().__init__(**kwargs)
self._client: AsyncQdrantBase
if sum([param is not None for param in (location, url, host, path)]) > 1:
raise ValueError(
"Only one of <location>, <url>, <host> or <path> should be specified."
)
if location == ":memory:":
self._client = AsyncQdrantLocal(
location=location, force_disable_check_same_thread=force_disable_check_same_thread
Expand Down
44 changes: 24 additions & 20 deletions qdrant_client/qdrant_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,32 +86,36 @@ def __init__(

self._client: QdrantBase

if sum([param is not None for param in (location, url, host, path)]) > 1:
raise ValueError(
"Only one of <location>, <url>, <host> or <path> should be specified."
)

if location == ":memory:":
self._client = QdrantLocal(
location=location,
force_disable_check_same_thread=force_disable_check_same_thread,
)
elif path is not None:
self._client = QdrantLocal(
location=path,
force_disable_check_same_thread=force_disable_check_same_thread,
)
else:
if path is not None:
self._client = QdrantLocal(
location=path,
force_disable_check_same_thread=force_disable_check_same_thread,
)
else:
if location is not None and url is None:
url = location
self._client = QdrantRemote(
url=url,
port=port,
grpc_port=grpc_port,
prefer_grpc=prefer_grpc,
https=https,
api_key=api_key,
prefix=prefix,
timeout=timeout,
host=host,
**kwargs,
)
if location is not None and url is None:
url = location
self._client = QdrantRemote(
url=url,
port=port,
grpc_port=grpc_port,
prefer_grpc=prefer_grpc,
https=https,
api_key=api_key,
prefix=prefix,
timeout=timeout,
host=host,
**kwargs,
)
self._is_fastembed_installed: Optional[bool] = None
# if fastembed is installed, set to true else False
if self._is_fastembed_installed is None:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_qdrant_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,21 @@ def test_client_init():
client = QdrantClient(":memory:", not_exist_param="test")
assert isinstance(client._client, QdrantLocal)

grid_params = [
{"location": ":memory:", "url": "http://localhost:6333"},
{"location": ":memory:", "host": "localhost"},
{"location": ":memory:", "path": "/tmp/test.db"},
{"url": "http://localhost:6333", "host": "localhost"},
{"url": "http://localhost:6333", "path": "/tmp/test.db"},
{"host": "localhost", "path": "/tmp/test.db"},
]
for params in grid_params:
with pytest.raises(
ValueError,
match="Only one of <location>, <url>, <host> or <path> should be specified.",
):
QdrantClient(**params)


@pytest.mark.parametrize("prefer_grpc", [False, True])
def test_record_upload(prefer_grpc):
Expand Down