From 3c91525b42ac8bc35fb72de557c3ad09dd166301 Mon Sep 17 00:00:00 2001 From: "min.tian" Date: Thu, 27 Nov 2025 17:00:26 +0800 Subject: [PATCH] fix es quant & rescore settings Signed-off-by: min.tian --- .../clients/elastic_cloud/elastic_cloud.py | 43 ++++--------------- .../frontend/config/dbCaseConfigs.py | 7 +-- vectordb_bench/models.py | 1 + 3 files changed, 13 insertions(+), 38 deletions(-) diff --git a/vectordb_bench/backend/clients/elastic_cloud/elastic_cloud.py b/vectordb_bench/backend/clients/elastic_cloud/elastic_cloud.py index e89601be2..ae3350ddf 100644 --- a/vectordb_bench/backend/clients/elastic_cloud/elastic_cloud.py +++ b/vectordb_bench/backend/clients/elastic_cloud/elastic_cloud.py @@ -180,48 +180,21 @@ def search_embedding( """ assert self.client is not None, "should self.init() first" + knn = { + "field": self.vector_col_name, + "k": k, + "num_candidates": self.case_config.num_candidates, + "filter": self.filter, + "query_vector": query, + } if self.case_config.use_rescore: - oversample_k = int(k * self.case_config.oversample_ratio) - oversample_num_candidates = int(self.case_config.num_candidates * self.case_config.oversample_ratio) - knn = { - "field": self.vector_col_name, - "k": oversample_k, - "num_candidates": oversample_num_candidates, - "filter": self.filter, - "query_vector": query, - } - rescore = { - "window_size": oversample_k, - "query": { - "rescore_query": { - "script_score": { - "query": {"match_all": {}}, - "script": { - "source": f"cosineSimilarity(params.queryVector, '{self.vector_col_name}')", - "params": {"queryVector": query}, - }, - } - }, - "query_weight": 0, - "rescore_query_weight": 1, - }, - } - else: - knn = { - "field": self.vector_col_name, - "k": k, - "num_candidates": self.case_config.num_candidates, - "filter": self.filter, - "query_vector": query, - } - rescore = None + knn["rescore_vector"] = {"oversample": self.case_config.oversample_ratio} size = k res = self.client.search( index=self.indice, knn=knn, routing=self.routing_key, - rescore=rescore, size=size, _source=False, docvalue_fields=[self.id_col_name], diff --git a/vectordb_bench/frontend/config/dbCaseConfigs.py b/vectordb_bench/frontend/config/dbCaseConfigs.py index 525e2e166..6dd8a6e19 100644 --- a/vectordb_bench/frontend/config/dbCaseConfigs.py +++ b/vectordb_bench/frontend/config/dbCaseConfigs.py @@ -839,7 +839,7 @@ class CaseConfigInput(BaseModel): ) CaseConfigParamInput_IndexType_ES = CaseConfigInput( - label=CaseConfigParamType.IndexType, + label=CaseConfigParamType.index, inputType=InputType.Option, inputConfig={ "options": [ @@ -881,7 +881,8 @@ class CaseConfigInput(BaseModel): label=CaseConfigParamType.use_rescore, inputType=InputType.Bool, inputConfig={"value": False}, - isDisplayed=lambda config: config.get(CaseConfigParamType.IndexType, None) != IndexType.ES_HNSW.value, + isDisplayed=lambda config: config.get(CaseConfigParamType.index, None) != IndexType.ES_HNSW.value, + inputHelp="Recalculating scores using the original (non-quantized) vectors.", ) CaseConfigParamInput_OversampleRatio_ES = CaseConfigInput( @@ -889,7 +890,7 @@ class CaseConfigInput(BaseModel): inputType=InputType.Float, inputConfig={"min": 1.0, "max": 100.0, "value": 2.0}, isDisplayed=lambda config: config.get(CaseConfigParamType.use_rescore, False), - inputHelp="num_oversample = oversample_ratio * top_k.", + inputHelp="Retrieving more candidates per shard for rescoring.", ) CaseConfigParamInput_UseRouting_ES = CaseConfigInput( diff --git a/vectordb_bench/models.py b/vectordb_bench/models.py index 32eabec04..5ffd0e70f 100644 --- a/vectordb_bench/models.py +++ b/vectordb_bench/models.py @@ -44,6 +44,7 @@ class CaseConfigParamType(Enum): """ IndexType = "IndexType" + index = "index" M = "M" EFConstruction = "efConstruction" ef_construction = "ef_construction"