|
| 1 | +import logging |
| 2 | +import uuid |
| 3 | +from typing import Annotated |
| 4 | + |
| 5 | +import click |
| 6 | + |
| 7 | +from vectordb_bench.cli.cli import ( |
| 8 | + CommonTypedDict, |
| 9 | + benchmark_runner, |
| 10 | + click_parameter_decorators_from_typed_dict, |
| 11 | + get_custom_case_config, |
| 12 | + parse_task_stages, |
| 13 | +) |
| 14 | +from vectordb_bench.models import ( |
| 15 | + CaseConfig, |
| 16 | + CaseType, |
| 17 | + ConcurrencySearchConfig, |
| 18 | + TaskConfig, |
| 19 | +) |
| 20 | + |
| 21 | +from .. import DB |
| 22 | +from ..api import EmptyDBCaseConfig |
| 23 | +from .config import EndeeConfig |
| 24 | + |
| 25 | +log = logging.getLogger(__name__) |
| 26 | + |
| 27 | + |
| 28 | +class EndeeTypedDict(CommonTypedDict): |
| 29 | + token: Annotated[str, click.option("--token", type=str, required=True, default=None, help="Endee API token")] |
| 30 | + region: Annotated[str, click.option("--region", type=str, default=None, help="Endee region", show_default=True)] |
| 31 | + base_url: Annotated[ |
| 32 | + str, |
| 33 | + click.option( |
| 34 | + "--base-url", type=str, default="http://127.0.0.1:8080/api/v1", help="API server URL", show_default=True |
| 35 | + ), |
| 36 | + ] |
| 37 | + space_type: Annotated[ |
| 38 | + str, |
| 39 | + click.option( |
| 40 | + "--space-type", |
| 41 | + type=click.Choice(["cosine", "l2", "dot_product"]), |
| 42 | + default="cosine", |
| 43 | + help="Distance metric", |
| 44 | + show_default=True, |
| 45 | + ), |
| 46 | + ] |
| 47 | + precision: Annotated[ |
| 48 | + str, |
| 49 | + click.option( |
| 50 | + "--precision", |
| 51 | + type=click.Choice(["binary", "int8d", "int16d", "float16", "float32"]), |
| 52 | + default="int8d", |
| 53 | + help="Quant Level", |
| 54 | + show_default=True, |
| 55 | + ), |
| 56 | + ] |
| 57 | + version: Annotated[int, click.option("--version", type=int, default=None, help="Index version", show_default=True)] |
| 58 | + m: Annotated[int, click.option("--m", type=int, default=None, help="HNSW M parameter", show_default=True)] |
| 59 | + ef_con: Annotated[ |
| 60 | + int, click.option("--ef-con", type=int, default=None, help="HNSW construction parameter", show_default=True) |
| 61 | + ] |
| 62 | + ef_search: Annotated[ |
| 63 | + int, click.option("--ef-search", type=int, default=None, help="HNSW search parameter", show_default=True) |
| 64 | + ] |
| 65 | + index_name: Annotated[ |
| 66 | + str, |
| 67 | + click.option( |
| 68 | + "--index-name", |
| 69 | + type=str, |
| 70 | + required=True, |
| 71 | + help="Endee index name (will use a random name if not provided)", |
| 72 | + show_default=True, |
| 73 | + ), |
| 74 | + ] |
| 75 | + |
| 76 | + |
| 77 | +@click.command() |
| 78 | +@click_parameter_decorators_from_typed_dict(EndeeTypedDict) |
| 79 | +def Endee(**parameters): |
| 80 | + """ |
| 81 | + Run VectorDBBench against Endee VectorDB. |
| 82 | + """ |
| 83 | + stages = parse_task_stages( |
| 84 | + parameters["drop_old"], |
| 85 | + parameters["load"], |
| 86 | + parameters["search_serial"], |
| 87 | + parameters["search_concurrent"], |
| 88 | + ) |
| 89 | + |
| 90 | + # Generate a random collection name if not provided |
| 91 | + collection_name = parameters["index_name"] |
| 92 | + if not collection_name: |
| 93 | + collection_name = f"endee_bench_{uuid.uuid4().hex[:8]}" |
| 94 | + |
| 95 | + # Filter out None values before creating config |
| 96 | + params_for_nd = {k: v for k, v in parameters.items() if v is not None} |
| 97 | + db_config = EndeeConfig(**params_for_nd) |
| 98 | + |
| 99 | + custom_case_config = get_custom_case_config(parameters) |
| 100 | + |
| 101 | + db_case_config = EmptyDBCaseConfig() |
| 102 | + |
| 103 | + task = TaskConfig( |
| 104 | + db=DB.Endee, |
| 105 | + db_config=db_config, |
| 106 | + db_case_config=db_case_config, |
| 107 | + case_config=CaseConfig( |
| 108 | + case_id=CaseType[parameters["case_type"]], |
| 109 | + k=parameters["k"], |
| 110 | + concurrency_search_config=ConcurrencySearchConfig( |
| 111 | + concurrency_duration=parameters["concurrency_duration"], |
| 112 | + num_concurrency=[int(s) for s in parameters["num_concurrency"]], |
| 113 | + concurrency_timeout=parameters["concurrency_timeout"], |
| 114 | + ), |
| 115 | + custom_case=custom_case_config, |
| 116 | + ), |
| 117 | + stages=stages, |
| 118 | + ) |
| 119 | + |
| 120 | + # Use the run method of the benchmark_runner object |
| 121 | + if not parameters["dry_run"]: |
| 122 | + # Generate task label |
| 123 | + run_uuid = uuid.uuid4().hex |
| 124 | + base_name = parameters.get("task_label") |
| 125 | + if not base_name: |
| 126 | + base_name = parameters.get("index_name", "endee") |
| 127 | + |
| 128 | + final_label = f"{base_name}_{run_uuid}" |
| 129 | + |
| 130 | + # Run the benchmark |
| 131 | + benchmark_runner.run([task], final_label) |
| 132 | + |
| 133 | + # Wait for task to complete |
| 134 | + import time |
| 135 | + from concurrent.futures import wait |
| 136 | + |
| 137 | + from vectordb_bench.interface import global_result_future |
| 138 | + |
| 139 | + time.sleep(5) |
| 140 | + if global_result_future: |
| 141 | + wait([global_result_future]) |
| 142 | + |
| 143 | + # Ensure CLI doesn't close while background processes are active |
| 144 | + while benchmark_runner.has_running(): |
| 145 | + time.sleep(1) |
0 commit comments