Optimizer (Tune)
For graph-based indexes (HGraph), VSAG exposes the Tune interface, which automatically
adjusts runtime parameters based on a representative query set to get a better trade-off between
recall and latency. Internally this is the historical “ELP Optimizer”.
Basic Usage
#include <vsag/vsag.h>
auto index = vsag::Factory::CreateIndex("hgraph", build_params).value();
index->Build(base_dataset);
std::string tune_params = R"(
{
"queries_dataset": "path/or/inline/queries",
"target_recall": 0.95,
"top_k": 10
}
)";
auto ret = index->Tune(tune_params);
The second argument disable_future_tuning defaults to false, allowing repeated calls to keep
refining. Set it to true to freeze the parameters.
Relationship with the ELP Optimizer
Older literature (see Research Papers) refers to the “ELP
Optimizer”. Its implementation key is use_elp_optimizer, which now lives behind the unified
Tune API — users no longer need to flip it directly.
Supported Indexes
| Index type | Supports Tune |
|---|---|
| hgraph | yes |
| ivf / sindi / brute_force | no |
Example
examples/cpp/318_feature_tune.cpp walks through an end-to-end tuning flow:
- Create the index and
Build. - Call
Tunewith a representative query set. - Serialize the tuned index for production use.
Notes
- When rebuilding HGraph vector codes,
Tuneneeds a raw or FP32 source covering the full internal ID range. If a failedAddleaves that source incomplete and no complete fallback exists,Tunereturnsfalsewithout changing the index. Later successful Adds do not fill earlier unwritten IDs. Deduplicated storage must have a published mapping for every ID; ordinary storage retains unfinished-write information and reserved IDs across serialization, so an Add after restore cannot reuse a missing vector’s ID. This uses existing count metadata without changing the binary format; older snapshots without unfinished-write metadata cannot recover that information.Mergerejects a destination or any input with unfinished code writes withINVALID_ARGUMENT, before copying any input; rebuild incomplete indexes from original data before merging. Restores reject reservation counts above the serialized capacity or internal ID limit withINVALID_BINARY; legacy metadata without a reservation count still falls back to the written-code count. It does not recover vectors from the failedAdd; rebuild the index from the original data before tuning again. - Tuning is sensitive to the query distribution — use samples that reflect real traffic.
- Tuned parameters are persisted together with the index metadata via
Serialize/Deserializeand remain in effect after deployment.