Skip to content

Commit 5e92b4f

Browse files
authored
feat: add zvec support (#692)
* feat: support zvec * update default m
1 parent 2b28d2f commit 5e92b4f

9 files changed

Lines changed: 370 additions & 0 deletions

File tree

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ All the database client supported
6363
| tencent_es | `pip install vectordb-bench[tencent_es]` |
6464
| alisql | `pip install 'vectordb-bench[alisql]'` |
6565
| doris | `pip install vectordb-bench[doris]` |
66+
| zvec | `pip install vectordb-bench[zvec]` |
6667

6768
### Run
6869

@@ -413,6 +414,27 @@ Options:
413414
--help Show this message and exit.
414415
```
415416

417+
### Run Zvec from command line
418+
419+
```bash
420+
vectordbbench zvec --path Performance768D10M --db-label 16c64g-v0.1 \
421+
--case-type Performance768D10M --num-concurrency 12,14,16,18,20 \
422+
--quantize-type int8 --ef-search 118 --is-using-refiner
423+
```
424+
To list the options for zvec, execute vectordbbench zvec --help
425+
```
426+
--path TEXT collection path [required]
427+
--m INTEGER HNSW index parameter m.
428+
--ef-construction INTEGER HNSW index parameter ef_construction
429+
--ef-search INTEGER HNSW index parameter ef for search
430+
--quantize-type TEXT HNSW index quantize type, fp16/int8
431+
supported
432+
--is-using-refiner is using refiner, suitable for quantized
433+
index, recall `ef-search` results then
434+
refine with unquantized vector to `topk`
435+
results
436+
```
437+
416438
### Run Doris from command line
417439

418440
Doris supports ann index with type hnsw from version 4.0.x

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ all = [
7878
"lancedb",
7979
"mysql-connector-python",
8080
"turbopuffer[fast]",
81+
'zvec',
8182
]
8283

8384
qdrant = [ "qdrant-client" ]
@@ -106,6 +107,7 @@ oceanbase = [ "mysql-connector-python" ]
106107
alisql = [ "mysql-connector-python" ]
107108
doris = [ "doris-vector-search" ]
108109
turbopuffer = [ "turbopuffer" ]
110+
zvec = [ "zvec" ]
109111

110112
[project.urls]
111113
Repository = "https://github.com/zilliztech/VectorDBBench"

vectordb_bench/backend/clients/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class DB(Enum):
5656
AliSQL = "AlibabaCloudRDSMySQL"
5757
Doris = "Doris"
5858
TurboPuffer = "TurboPuffer"
59+
Zvec = "Zvec"
5960

6061
@property
6162
def init_cls(self) -> type[VectorDB]: # noqa: PLR0911, PLR0912, C901, PLR0915
@@ -228,6 +229,11 @@ def init_cls(self) -> type[VectorDB]: # noqa: PLR0911, PLR0912, C901, PLR0915
228229

229230
return AliSQL
230231

232+
if self == DB.Zvec:
233+
from .zvec.zvec import Zvec
234+
235+
return Zvec
236+
231237
msg = f"Unknown DB: {self.name}"
232238
raise ValueError(msg)
233239

@@ -402,6 +408,11 @@ def config_cls(self) -> type[DBConfig]: # noqa: PLR0911, PLR0912, C901, PLR0915
402408

403409
return AliSQLConfig
404410

411+
if self == DB.Zvec:
412+
from .zvec.config import ZvecConfig
413+
414+
return ZvecConfig
415+
405416
msg = f"Unknown DB: {self.name}"
406417
raise ValueError(msg)
407418

@@ -533,6 +544,11 @@ def case_config_cls( # noqa: C901, PLR0911, PLR0912, PLR0915
533544

534545
return HologresIndexConfig
535546

547+
if self == DB.Zvec:
548+
from .zvec.config import ZvecHNSWIndexConfig
549+
550+
return ZvecHNSWIndexConfig
551+
536552
if self == DB.TencentElasticsearch:
537553
from .tencent_elasticsearch.config import TencentElasticsearchIndexConfig
538554

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from typing import Annotated, Unpack
2+
3+
import click
4+
5+
from ....cli.cli import (
6+
CommonTypedDict,
7+
cli,
8+
click_parameter_decorators_from_typed_dict,
9+
run,
10+
)
11+
from .. import DB
12+
13+
14+
class ZvecTypedDict(CommonTypedDict):
15+
path: Annotated[
16+
str,
17+
click.option("--path", type=str, help="collection path", required=True),
18+
]
19+
20+
21+
class ZvecHNSWTypedDict(CommonTypedDict, ZvecTypedDict):
22+
m: Annotated[
23+
int,
24+
click.option("--m", type=int, default=50, help="HNSW index parameter m."),
25+
]
26+
ef_construct: Annotated[
27+
int,
28+
click.option("--ef-construction", type=int, default=500, help="HNSW index parameter ef_construction"),
29+
]
30+
ef_search: Annotated[
31+
int,
32+
click.option("--ef-search", type=int, default=300, help="HNSW index parameter ef for search"),
33+
]
34+
quantize_type: Annotated[
35+
int,
36+
click.option("--quantize-type", type=str, default="", help="HNSW index quantize type, fp16/int8 supported"),
37+
]
38+
is_using_refiner: Annotated[
39+
bool,
40+
click.option(
41+
"--is-using-refiner",
42+
is_flag=True,
43+
default=False,
44+
help="is using refiner, suitable for quantized index, "
45+
"recall `ef-search` results then refine with unquantized vector to `topk` results",
46+
),
47+
]
48+
49+
50+
# default to hnsw
51+
@cli.command()
52+
@click_parameter_decorators_from_typed_dict(ZvecHNSWTypedDict)
53+
def Zvec(**parameters: Unpack[ZvecHNSWTypedDict]):
54+
from .config import ZvecConfig, ZvecHNSWIndexConfig
55+
56+
run(
57+
db=DB.Zvec,
58+
db_config=ZvecConfig(
59+
db_label=parameters["db_label"],
60+
path=parameters["path"],
61+
),
62+
db_case_config=ZvecHNSWIndexConfig(
63+
M=parameters["m"],
64+
ef_construction=parameters["ef_construction"],
65+
ef_search=parameters["ef_search"],
66+
quantize_type=parameters["quantize_type"],
67+
is_using_refiner=parameters["is_using_refiner"],
68+
),
69+
**parameters,
70+
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from pydantic import BaseModel
2+
3+
from ..api import DBCaseConfig, DBConfig, MetricType
4+
5+
6+
class ZvecConfig(DBConfig):
7+
"""Zvec connection configuration."""
8+
9+
db_label: str
10+
path: str
11+
12+
def to_dict(self) -> dict:
13+
return {
14+
"path": self.path,
15+
}
16+
17+
18+
class ZvecIndexConfig(BaseModel, DBCaseConfig):
19+
metric_type: MetricType | None = None
20+
21+
def index_param(self) -> dict:
22+
return {}
23+
24+
def search_param(self) -> dict:
25+
return {}
26+
27+
28+
class ZvecHNSWIndexConfig(ZvecIndexConfig):
29+
M: int | None = 50
30+
ef_construction: int | None = 500
31+
32+
ef_search: int | None = 300
33+
34+
quantize_type: str = ""
35+
36+
is_using_refiner: bool = False

0 commit comments

Comments
 (0)