Skip to content

Commit aff487b

Browse files
author
Wenxin Li
committed
Support per-percentage ground truth datasets via filter_percentage param
Adds optional key_suffix to HDF5 dataset reads. When filter_percentage is set (e.g. "10pct"), the neighbors and radial threshold datasets are read from suffixed keys (neighbors_10pct, faiss_max_distance_10pct), allowing one dataset file to hold precomputed answer sets for multiple filter percentages. Signed-off-by: Wenxin Li <liwenxin@amazon.com>
1 parent a588056 commit aff487b

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

osbenchmark/utils/dataset.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,20 @@ def reset(self):
7272
"""
7373

7474

75-
def get_data_set(data_set_format: str, path: str, context: Context):
75+
def get_data_set(data_set_format: str, path: str, context: Context, key_suffix: str = None):
7676
"""
7777
Factory method to get instance of Dataset for given format.
7878
Args:
7979
data_set_format: File format like hdf5, bigann
8080
path: Data set file path
8181
context: Dataset Context Enum
82+
key_suffix: Optional suffix appended to the HDF5 key name, e.g.
83+
Context.NEIGHBORS with key_suffix "10pct" reads "neighbors_10pct".
84+
Used by filtered benchmarks storing per-percentage ground truth.
8285
Returns: DataSet instance
8386
"""
8487
if data_set_format == HDF5DataSet.FORMAT_NAME:
85-
return HDF5DataSet(path, context)
88+
return HDF5DataSet(path, context, key_suffix)
8689
if data_set_format == BigANNVectorDataSet.FORMAT_NAME:
8790
return create_big_ann_dataset(path)
8891
raise ConfigurationError("Invalid data set format")
@@ -95,9 +98,11 @@ class HDF5DataSet(DataSet):
9598

9699
FORMAT_NAME = "hdf5"
97100

98-
def __init__(self, dataset_path: str, context: Context):
101+
def __init__(self, dataset_path: str, context: Context, key_suffix: str = None):
99102
self.dataset_path = dataset_path
100103
self.context = self.parse_context(context)
104+
if key_suffix:
105+
self.context = f"{self.context}_{key_suffix}"
101106
self.current = self.BEGINNING
102107
self.data = None
103108

osbenchmark/workload/params.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,10 @@ def __init__(self, workloads, params, query_params, **kwargs):
11621162
self.filter_type = self.query_params.get(self.PARAMS_NAME_FILTER_TYPE)
11631163
self.filter_body = self.query_params.get(self.PARAMS_NAME_FILTER_BODY)
11641164
self.space_type = params.get(self.PARAMS_NAME_SPACE_TYPE, "l2")
1165+
# Suffix selecting per-percentage ground truth datasets, e.g. "10pct"
1166+
# reads neighbors_10pct and faiss_max_distance_10pct instead of the
1167+
# unsuffixed keys. Used by filtered benchmarks.
1168+
self.filter_percentage = params.get("filter_percentage")
11651169

11661170
if self.radial_search_type:
11671171
self.radial_engine = params.get("radial_engine", "faiss")
@@ -1234,14 +1238,16 @@ def partition(self, partition_index, total_partitions):
12341238
neighbors_context = Context.NEIGHBORS
12351239

12361240
partition.neighbors_data_set = get_data_set(
1237-
self.neighbors_data_set_format, self.neighbors_data_set_path, neighbors_context)
1241+
self.neighbors_data_set_format, self.neighbors_data_set_path, neighbors_context,
1242+
self.filter_percentage)
12381243
partition.neighbors_data_set.seek(partition.offset)
12391244

12401245
if self.radial_search_type:
12411246
threshold_context = self.RADIAL_THRESHOLD_CONTEXTS[
12421247
(self.radial_engine, self.radial_search_type)]
12431248
partition.threshold_data_set = get_data_set(
1244-
self.neighbors_data_set_format, self.neighbors_data_set_path, threshold_context)
1249+
self.neighbors_data_set_format, self.neighbors_data_set_path, threshold_context,
1250+
self.filter_percentage)
12451251
partition.threshold_data_set.seek(partition.offset)
12461252

12471253
return partition

0 commit comments

Comments
 (0)