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
43 changes: 8 additions & 35 deletions vectordb_bench/backend/clients/elastic_cloud/elastic_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
7 changes: 4 additions & 3 deletions vectordb_bench/frontend/config/dbCaseConfigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ class CaseConfigInput(BaseModel):
)

CaseConfigParamInput_IndexType_ES = CaseConfigInput(
label=CaseConfigParamType.IndexType,
label=CaseConfigParamType.index,
inputType=InputType.Option,
inputConfig={
"options": [
Expand Down Expand Up @@ -881,15 +881,16 @@ 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(
label=CaseConfigParamType.oversample_ratio,
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(
Expand Down
1 change: 1 addition & 0 deletions vectordb_bench/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CaseConfigParamType(Enum):
"""

IndexType = "IndexType"
index = "index"
M = "M"
EFConstruction = "efConstruction"
ef_construction = "ef_construction"
Expand Down