Skip to content

Commit 67f0f2e

Browse files
s-h-a-d-o-walwayslove2013
authored andcommitted
Add qdrant cli
1 parent 75bbdfb commit 67f0f2e

4 files changed

Lines changed: 59 additions & 8 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from typing import Annotated, Unpack
2+
3+
import click
4+
from pydantic import SecretStr
5+
6+
from ....cli.cli import (
7+
CommonTypedDict,
8+
cli,
9+
click_parameter_decorators_from_typed_dict,
10+
run,
11+
)
12+
from .. import DB
13+
14+
15+
class QdrantTypedDict(CommonTypedDict):
16+
url: Annotated[
17+
str,
18+
click.option("--url", type=str, help="URL connection string", required=True),
19+
]
20+
api_key: Annotated[
21+
str | None,
22+
click.option("--api-key", type=str, help="API key for authentication", required=False),
23+
]
24+
25+
26+
@cli.command()
27+
@click_parameter_decorators_from_typed_dict(QdrantTypedDict)
28+
def QdrantCloud(**parameters: Unpack[QdrantTypedDict]):
29+
from .config import QdrantConfig, QdrantIndexConfig
30+
31+
config_params = {
32+
"db_label": parameters["db_label"],
33+
"url": SecretStr(parameters["url"]),
34+
}
35+
36+
config_params["api_key"] = SecretStr(parameters["api_key"]) if parameters["api_key"] else None
37+
38+
run(
39+
db=DB.QdrantCloud,
40+
db_config=QdrantConfig(**config_params),
41+
db_case_config=QdrantIndexConfig(),
42+
**parameters,
43+
)

vectordb_bench/backend/clients/qdrant_cloud/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
# Allowing `api_key` to be left empty, to ensure compatibility with the open-source Qdrant.
77
class QdrantConfig(DBConfig):
88
url: SecretStr
9-
api_key: SecretStr
9+
api_key: SecretStr | None = None
1010

1111
def to_dict(self) -> dict:
12-
api_key = self.api_key.get_secret_value()
13-
if len(api_key) > 0:
12+
api_key_value = self.api_key.get_secret_value() if self.api_key else None
13+
if api_key_value:
1414
return {
1515
"url": self.url.get_secret_value(),
16-
"api_key": self.api_key.get_secret_value(),
16+
"api_key": api_key_value,
1717
"prefer_grpc": True,
1818
}
1919
return {

vectordb_bench/cli/vectordbbench.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from ..backend.clients.pgvecto_rs.cli import PgVectoRSHNSW, PgVectoRSIVFFlat
1010
from ..backend.clients.pgvector.cli import PgVectorHNSW
1111
from ..backend.clients.pgvectorscale.cli import PgVectorScaleDiskAnn
12+
from ..backend.clients.qdrant_cloud.cli import QdrantCloud
1213
from ..backend.clients.redis.cli import Redis
1314
from ..backend.clients.test.cli import Test
1415
from ..backend.clients.tidb.cli import TiDB
@@ -35,6 +36,7 @@
3536
cli.add_command(Clickhouse)
3637
cli.add_command(Vespa)
3738
cli.add_command(LanceDB)
39+
cli.add_command(QdrantCloud)
3840

3941

4042
if __name__ == "__main__":

vectordb_bench/frontend/components/run_test/dbConfigSetting.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,27 @@ def dbConfigSettingItem(st, activeDb: DB):
3636
columns = st.columns(DB_CONFIG_SETTING_COLUMNS)
3737

3838
dbConfigClass = activeDb.config_cls
39-
properties = dbConfigClass.schema().get("properties")
39+
schema = dbConfigClass.schema()
40+
property_items = schema.get("properties").items()
41+
required_fields = set(schema.get("required", []))
4042
dbConfig = {}
4143
idx = 0
4244

4345
# db config (unique)
44-
for key, property in properties.items():
46+
for key, property in property_items:
4547
if key not in dbConfigClass.common_short_configs() and key not in dbConfigClass.common_long_configs():
4648
column = columns[idx % DB_CONFIG_SETTING_COLUMNS]
4749
idx += 1
48-
dbConfig[key] = column.text_input(
50+
input_value = column.text_input(
4951
key,
50-
key="%s-%s" % (activeDb.name, key),
52+
key=f"{activeDb.name}-{key}",
5153
value=property.get("default", ""),
5254
type="password" if inputIsPassword(key) else "default",
55+
placeholder="optional" if key not in required_fields else None,
5356
)
57+
if key in required_fields or input_value:
58+
dbConfig[key] = input_value
59+
5460
# db config (common short labels)
5561
for key in dbConfigClass.common_short_configs():
5662
column = columns[idx % DB_CONFIG_SETTING_COLUMNS]

0 commit comments

Comments
 (0)