use std::time::Instant;
use clap::Parser;
use diskann_providers::storage::FileStorageProvider;
use diskann_tools::utils::{
compute_multivec_ground_truth_from_datafiles, init_subscriber, CMDResult, DataType,
MultivecAggregationMethod,
};
use diskann_vector::distance::Metric;
use diskann_vector::Half;
fn main() -> CMDResult<()> {
init_subscriber();
let timer = Instant::now();
let args = ComputeMultivecGroundTruthArgs::parse();
tracing::info!("Computing ground truth file");
let storage_provider = FileStorageProvider;
let err = match args.data_type {
DataType::Float => {
compute_multivec_ground_truth_from_datafiles::<f32, FileStorageProvider>(
&storage_provider,
args.distance_function,
args.aggregation,
&args.base_file,
&args.query_file,
&args.ground_truth_file,
args.recall_at,
args.base_file_labels.as_deref(),
args.query_file_labels.as_deref(),
)
}
DataType::Fp16 => {
compute_multivec_ground_truth_from_datafiles::<Half, FileStorageProvider>(
&storage_provider,
args.distance_function,
args.aggregation,
&args.base_file,
&args.query_file,
&args.ground_truth_file,
args.recall_at,
args.base_file_labels.as_deref(),
args.query_file_labels.as_deref(),
)
}
DataType::Uint8 => compute_multivec_ground_truth_from_datafiles::<u8, FileStorageProvider>(
&storage_provider,
args.distance_function,
args.aggregation,
&args.base_file,
&args.query_file,
&args.ground_truth_file,
args.recall_at,
args.base_file_labels.as_deref(),
args.query_file_labels.as_deref(),
),
DataType::Int8 => compute_multivec_ground_truth_from_datafiles::<i8, FileStorageProvider>(
&storage_provider,
args.distance_function,
args.aggregation,
&args.base_file,
&args.query_file,
&args.ground_truth_file,
args.recall_at,
args.base_file_labels.as_deref(),
args.query_file_labels.as_deref(),
),
};
match err {
Ok(_) => {
tracing::info!(
"Compute ground-truth completed successfully in {:?}",
timer.elapsed()
);
Ok(())
}
Err(err) => {
tracing::error!("Error: {:?}", err);
Err(err)
}
}
}
#[derive(Debug, Parser)]
struct ComputeMultivecGroundTruthArgs {
#[arg(long = "data-type", default_value = "float")]
pub data_type: DataType,
#[arg(long = "dist-fn", default_value = "l2")]
pub distance_function: Metric,
#[arg(long = "aggregation", default_value = "average")]
pub aggregation: MultivecAggregationMethod,
#[arg(long = "base-file", short, required = true)]
pub base_file: String,
#[arg(long = "base-file-labels", default_value = None)]
pub base_file_labels: Option<String>,
#[arg(long = "query-file", short, required = true)]
pub query_file: String,
#[arg(long = "query-file-labels")]
pub query_file_labels: Option<String>,
#[arg(long = "gt-file", short, required = true)]
pub ground_truth_file: String,
#[arg(long = "recall-at", short = 'K', default_value = "10")]
pub recall_at: u32,
}