Skip to content

Commit f0e8367

Browse files
remove redundant empty_field config check for qdrant and tidb
Signed-off-by: min.tian <min.tian.cn@gmail.com>
1 parent 1446c6e commit f0e8367

5 files changed

Lines changed: 28 additions & 33 deletions

File tree

vectordb_bench/backend/clients/clickhouse/config.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from typing import TypedDict
21
from pydantic import BaseModel, SecretStr
3-
from ..api import DBConfig, DBCaseConfig, MetricType, IndexType
2+
3+
from ..api import DBCaseConfig, DBConfig, IndexType, MetricType
4+
45

56
class ClickhouseConfig(DBConfig):
6-
user_name: str = "clickhouse"
7+
user_name: str = "clickhouse"
78
password: SecretStr
89
host: str = "localhost"
910
port: int = 8123
@@ -16,7 +17,7 @@ def to_dict(self) -> dict:
1617
"port": self.port,
1718
"dbname": self.db_name,
1819
"user": self.user_name,
19-
"password": pwd_str
20+
"password": pwd_str,
2021
}
2122

2223

@@ -32,8 +33,11 @@ def parse_metric(self) -> str:
3233
def parse_metric_str(self) -> str:
3334
if self.metric_type == MetricType.L2:
3435
return "L2Distance"
35-
elif self.metric_type == MetricType.COSINE:
36+
if self.metric_type == MetricType.COSINE:
3637
return "cosineDistance"
38+
msg = f"Not Support for {self.metric_type}"
39+
raise RuntimeError(msg)
40+
return None
3741

3842

3943
class ClickhouseHNSWConfig(ClickhouseIndexConfig, DBCaseConfig):
@@ -51,6 +55,6 @@ def index_param(self) -> dict:
5155

5256
def search_param(self) -> dict:
5357
return {
54-
"metric_type": self.parse_metric_str(),
58+
"met˝ric_type": self.parse_metric_str(),
5559
"params": {"ef": self.ef},
56-
}
60+
}

vectordb_bench/backend/clients/mariadb/cli.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
from typing import Annotated, Optional, Unpack
22

33
import click
4-
import os
54
from pydantic import SecretStr
65

6+
from vectordb_bench.backend.clients import DB
7+
78
from ....cli.cli import (
89
CommonTypedDict,
9-
HNSWFlavor1,
1010
cli,
1111
click_parameter_decorators_from_typed_dict,
1212
run,
1313
)
14-
from vectordb_bench.backend.clients import DB
1514

1615

1716
class MariaDBTypedDict(CommonTypedDict):

vectordb_bench/backend/clients/mariadb/config.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
from pydantic import SecretStr, BaseModel
21
from typing import TypedDict
3-
from ..api import DBConfig, DBCaseConfig, MetricType, IndexType
2+
3+
from pydantic import BaseModel, SecretStr
4+
5+
from ..api import DBCaseConfig, DBConfig, IndexType, MetricType
6+
47

58
class MariaDBConfigDict(TypedDict):
69
"""These keys will be directly used as kwargs in mariadb connection string,
@@ -36,10 +39,10 @@ class MariaDBIndexConfig(BaseModel):
3639
def parse_metric(self) -> str:
3740
if self.metric_type == MetricType.L2:
3841
return "euclidean"
39-
elif self.metric_type == MetricType.COSINE:
42+
if self.metric_type == MetricType.COSINE:
4043
return "cosine"
41-
else:
42-
raise ValueError(f"Metric type {self.metric_type} is not supported!")
44+
msg = f"Metric type {self.metric_type} is not supported!"
45+
raise ValueError(msg)
4346

4447
class MariaDBHNSWConfig(MariaDBIndexConfig, DBCaseConfig):
4548
M: int | None

vectordb_bench/backend/clients/qdrant_cloud/config.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pydantic import BaseModel, SecretStr, validator
1+
from pydantic import BaseModel, SecretStr
22

33
from ..api import DBCaseConfig, DBConfig, MetricType
44

@@ -20,14 +20,6 @@ def to_dict(self) -> dict:
2020
"url": self.url.get_secret_value(),
2121
}
2222

23-
@validator("*")
24-
def not_empty_field(cls, v: any, field: any):
25-
if field.name in ["api_key", "db_label"]:
26-
return v
27-
if isinstance(v, str | SecretStr) and len(v) == 0:
28-
raise ValueError("Empty string!")
29-
return v
30-
3123

3224
class QdrantIndexConfig(BaseModel, DBCaseConfig):
3325
metric_type: MetricType | None = None

vectordb_bench/backend/clients/tidb/config.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from pydantic import SecretStr, BaseModel, validator
2-
from ..api import DBConfig, DBCaseConfig, MetricType
1+
from pydantic import BaseModel, SecretStr
2+
3+
from ..api import DBCaseConfig, DBConfig, MetricType
34

45

56
class TiDBConfig(DBConfig):
@@ -10,10 +11,6 @@ class TiDBConfig(DBConfig):
1011
db_name: str = "test"
1112
ssl: bool = False
1213

13-
@validator("*")
14-
def not_empty_field(cls, v: any, field: any):
15-
return v
16-
1714
def to_dict(self) -> dict:
1815
pwd_str = self.password.get_secret_value()
1916
return {
@@ -33,10 +30,10 @@ class TiDBIndexConfig(BaseModel, DBCaseConfig):
3330
def get_metric_fn(self) -> str:
3431
if self.metric_type == MetricType.L2:
3532
return "vec_l2_distance"
36-
elif self.metric_type == MetricType.COSINE:
33+
if self.metric_type == MetricType.COSINE:
3734
return "vec_cosine_distance"
38-
else:
39-
raise ValueError(f"Unsupported metric type: {self.metric_type}")
35+
msg = f"Unsupported metric type: {self.metric_type}"
36+
raise ValueError(msg)
4037

4138
def index_param(self) -> dict:
4239
return {

0 commit comments

Comments
 (0)