|
| 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 | + ) |
0 commit comments