Skip to content

Commit

Permalink
new: prohibit setting more than one param from host, url, location, p…
Browse files Browse the repository at this point in the history
…ath (#386)
  • Loading branch information
joein authored Nov 30, 2023
1 parent 6743f28 commit cced4f5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
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

0 comments on commit cced4f5

Please sign in to comment.