Skip to content
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
28 changes: 13 additions & 15 deletions vectordb_bench/backend/clients/alisql/alisql.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def __init__(
self.name = "AliSQL"
self.db_config = db_config
self.case_config = db_case_config
self.db_name = "vectordbbench"
self.table_name = collection_name
self.dim = dim

Expand Down Expand Up @@ -57,11 +56,11 @@ def _create_connection(self):
def _drop_db(self):
assert self.conn is not None, "Connection is not initialized"
assert self.cursor is not None, "Cursor is not initialized"
log.info(f"{self.name} client drop db : {self.db_name}")
log.info(f'{self.name} client drop db : {self.db_config["database"]}')

# flush tables before dropping database to avoid some locking issue
self.cursor.execute("FLUSH TABLES")
self.cursor.execute(f"DROP DATABASE IF EXISTS {self.db_name}")
self.cursor.execute(f'DROP DATABASE IF EXISTS {self.db_config["database"]}')
self.cursor.execute("COMMIT")
self.cursor.execute("FLUSH TABLES")

Expand All @@ -70,11 +69,11 @@ def _create_db_table(self, dim: int):
assert self.cursor is not None, "Cursor is not initialized"

try:
log.info(f"{self.name} client create database : {self.db_name}")
self.cursor.execute(f"CREATE DATABASE {self.db_name}")
log.info(f'{self.name} client create database : {self.db_config["database"]}')
self.cursor.execute(f'CREATE DATABASE {self.db_config["database"]}')

log.info(f"{self.name} client create table : {self.table_name}")
self.cursor.execute(f"USE {self.db_name}")
self.cursor.execute(f'USE {self.db_config["database"]}')

self.cursor.execute(
f"""
Expand Down Expand Up @@ -103,23 +102,22 @@ def init(self):
index_param = self.case_config.index_param()
search_param = self.case_config.search_param()

# maximize allowed package size
self.cursor.execute("SET GLOBAL max_allowed_packet = 1073741824")
self.cursor.execute("SET sql_mode = ''")

if index_param["index_type"] == "HNSW":
if index_param["cache_size"] is not None:
self.cursor.execute(f"SET GLOBAL vidx_hnsw_cache_size = {index_param['cache_size']}")
if search_param["ef_search"] is not None:
self.cursor.execute(f"SET GLOBAL vidx_hnsw_ef_search = {search_param['ef_search']}")
self.cursor.execute(f"SET SESSION vidx_hnsw_ef_search = {search_param['ef_search']}")
self.cursor.execute("COMMIT")

self.insert_sql = f"INSERT INTO {self.db_name}.{self.table_name} (id, v) VALUES (%s, %s)" # noqa: S608
self.insert_sql = (
f'INSERT INTO {self.db_config["database"]}.{self.table_name} (id, v) VALUES (%s, %s)' # noqa: S608
)
self.select_sql = (
f"SELECT id FROM {self.db_name}.{self.table_name} " # noqa: S608
f'SELECT id FROM {self.db_config["database"]}.{self.table_name} ' # noqa: S608
f"ORDER by vec_distance_{search_param['metric_type']}(v, %s) LIMIT %s"
)
self.select_sql_with_filter = (
f"SELECT id FROM {self.db_name}.{self.table_name} WHERE id >= %s " # noqa: S608
f'SELECT id FROM {self.db_config["database"]}.{self.table_name} WHERE id >= %s ' # noqa: S608
f"ORDER by vec_distance_{search_param['metric_type']}(v, %s) LIMIT %s"
)

Expand Down Expand Up @@ -147,7 +145,7 @@ def optimize(self, data_size: int) -> None:

self.cursor.execute(
f"""
ALTER TABLE {self.db_name}.{self.table_name}
ALTER TABLE {self.db_config["database"]}.{self.table_name}
ADD VECTOR KEY v(v) {index_options}
"""
)
Expand Down
24 changes: 12 additions & 12 deletions vectordb_bench/backend/clients/alisql/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@ class AliSQLTypedDict(CommonTypedDict):
"--port",
type=int,
default=3306,
help="DB Port",
help="Db Port",
),
]

database: Annotated[
str,
click.option(
"--database",
type=str,
help="Database name",
default="vectordbbench",
),
]

Expand All @@ -75,16 +85,6 @@ class AliSQLHNSWTypedDict(AliSQLTypedDict):
),
]

cache_size: Annotated[
int | None,
click.option(
"--cache-size",
type=int,
help="AliSQL system variable vidx_hnsw_cache_size",
required=False,
),
]


@cli.command()
@click_parameter_decorators_from_typed_dict(AliSQLHNSWTypedDict)
Expand All @@ -101,11 +101,11 @@ def AliSQLHNSW(
password=SecretStr(parameters["password"]),
host=parameters["host"],
port=parameters["port"],
database=parameters["database"],
),
db_case_config=AliSQLHNSWConfig(
M=parameters["m"],
ef_search=parameters["ef_search"],
cache_size=parameters["cache_size"],
),
**parameters,
)
5 changes: 3 additions & 2 deletions vectordb_bench/backend/clients/alisql/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ class AliSQLConfigDict(TypedDict):
password: str
host: str
port: int
database: str


class AliSQLConfig(DBConfig):
user_name: str = "root"
password: SecretStr
host: str = "127.0.0.1"
port: int = 3306
database: str = "vectordbbench"

def to_dict(self) -> AliSQLConfigDict:
pwd_str = self.password.get_secret_value()
Expand All @@ -28,6 +30,7 @@ def to_dict(self) -> AliSQLConfigDict:
"port": self.port,
"user": self.user_name,
"password": pwd_str,
"database": self.database,
}


Expand All @@ -49,14 +52,12 @@ class AliSQLHNSWConfig(AliSQLIndexConfig, DBCaseConfig):
M: int | None
ef_search: int | None
index: IndexType = IndexType.HNSW
cache_size: int | None

def index_param(self) -> dict:
return {
"metric_type": self.parse_metric(),
"index_type": self.index.value,
"M": self.M,
"cache_size": self.cache_size,
}

def search_param(self) -> dict:
Expand Down
14 changes: 0 additions & 14 deletions vectordb_bench/frontend/config/dbCaseConfigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1575,18 +1575,6 @@ class CaseConfigInput(BaseModel):
isDisplayed=lambda config: config.get(CaseConfigParamType.IndexType, None) == IndexType.HNSW.value,
)

CaseConfigParamInput_CacheSize_AliSQL = CaseConfigInput(
label=CaseConfigParamType.cache_size,
inputHelp="vidx_hnsw_cache_size",
inputType=InputType.Number,
inputConfig={
"min": 1048576,
"max": (1 << 53) - 1,
"value": 16 * 1024**3,
},
isDisplayed=lambda config: config.get(CaseConfigParamType.IndexType, None) == IndexType.HNSW.value,
)

CaseConfigParamInput_IndexType_AliSQL = CaseConfigInput(
label=CaseConfigParamType.IndexType,
inputHelp="Select Index Type",
Expand Down Expand Up @@ -2077,12 +2065,10 @@ class CaseConfigInput(BaseModel):
AliSQLLoadingConfig = [
CaseConfigParamInput_IndexType_AliSQL,
CaseConfigParamInput_M_AliSQL,
CaseConfigParamInput_CacheSize_AliSQL,
]
AliSQLPerformanceConfig = [
CaseConfigParamInput_IndexType_AliSQL,
CaseConfigParamInput_M_AliSQL,
CaseConfigParamInput_CacheSize_AliSQL,
CaseConfigParamInput_EFSearch_AliSQL,
]

Expand Down
1 change: 0 additions & 1 deletion vectordb_bench/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ class CaseConfigParamType(Enum):
oversample_ratio = "oversample_ratio"
use_routing = "use_routing"
replication_type = "replication_type"
cache_size = "cache_size"

dataset_with_size_type = "dataset_with_size_type"
filter_rate = "filter_rate"
Expand Down