feat: unify distance-by-ID API naming with legacy compatibility#2532
feat: unify distance-by-ID API naming with legacy compatibility#2532wxyucs wants to merge 1 commit into
Conversation
|
/label S-waiting-on-review |
|
Automated pull request review completed. Review effort: Submitted 2 inline comments. |
Merge Protections🟢 All 2 merge protections satisfied — ready to merge. Show 2 satisfied protections🟢 Require kind label
🟢 Require version label
|
LHT129
left a comment
There was a problem hiding this comment.
Review Summary
Reviewed 33 changed files across the CalcDistancesById batch API addition and CalDistanceById deprecation.
Design: The backward-compatibility strategy is well-designed. The base Index class CalcDistancesById defaults to forwarding to the deprecated CalDistanceById virtual, so third-party implementations that only override the legacy API continue to work. Concrete implementations (HGraph, IVF, Pyramid, SINDI, DiskANN, HNSW) override CalcDistancesById with real logic and make CalDistanceById forward to it, avoiding recursion. IndexImpl bridges the two correctly.
Correctness: No critical issues found. The virtual dispatch chains are correct — no infinite recursion, no missed overrides. The [[deprecated]] attribute on CalDistanceById in the public Index API properly warns callers while the internal forwarding uses pragma guards.
Test coverage: Good — new LegacyBatchIndex test in test_simple_index.cpp verifies dispatch to a legacy-only override; test_index_calc.cpp adds corrected/legacy equivalence checks with pragma guards; Python tests verify calc_distances_by_id vs cal_distance_by_id equivalence.
Bindings: Python (calc_distances_by_id + cal_distance_by_id alias), Node (calcDistancesById + calDistanceById alias), and C API all updated correctly.
Documentation: English and Chinese docs updated consistently with clear migration notes.
Issues found: 1 note-level (see inline comment on include/vsag/index.h).
24bc16c to
574c6e9
Compare
574c6e9 to
81dc2a2
Compare
vsag-bot
left a comment
There was a problem hiding this comment.
Automated inline review completed.
Review effort: high (442 changed lines across 34 files).
Submitted 1 inline comment.
Reviewed commit 81dc2a2.
| * third-party Index implementations remain source-compatible. | ||
| */ | ||
| [[nodiscard]] virtual tl::expected<DatasetPtr, Error> | ||
| CalcDistancesById(const DatasetPtr& query, |
There was a problem hiding this comment.
[P1] Append the new virtual methods after existing vtable slots
These two virtual overloads are inserted before GetMinAndMaxId, shifting that method and every subsequent Index vtable slot. An existing application or plugin compiled against the previous v1.x header can therefore call a later virtual method on an object built by this version and dispatch to a CalcDistancesById slot with an incompatible signature, causing undefined behavior or a crash. Place both new virtual declarations after all pre-existing virtual methods (including the destructor), leaving every legacy slot at its original offset, or explicitly introduce a new ABI version.
There was a problem hiding this comment.
Judged independently: this ABI concern remains valid in the final diff. The new public virtual overloads are still declared before existing virtual slots, so I’m leaving the thread unresolved rather than claiming the ABI layout issue is fixed.
There was a problem hiding this comment.
Correction to my previous reply: this ABI concern remains valid because the new public virtual overloads are still declared before existing Index virtual slots. I am leaving the thread unresolved rather than claiming the ABI layout issue is fixed.
LHT129
left a comment
There was a problem hiding this comment.
Code review for PR #2532: feat: add CalcDistancesById batch API
Overall this is a well-structured rename with good backward-compatibility design. The new CalcDistancesById virtual methods are added alongside deprecated CalDistanceById wrappers, and the default implementations cross-dispatch so existing third-party overrides remain compatible.
Two issues noted below.
| tl::expected<DatasetPtr, vsag::Error> legacy_result; | ||
| #if defined(__GNUC__) | ||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
There was a problem hiding this comment.
[note] The deprecation warning suppression in this test file only covers GCC/Clang. On MSVC, calling the deprecated CalDistanceById will emit C4996. Consider adding the MSVC counterpart for consistency with the pattern used in include/vsag/index.h.
There was a problem hiding this comment.
This remains a valid portability note: the current test fixture still only suppresses GCC/Clang deprecation diagnostics. I have not changed that fixture in this follow-up, so I’m leaving this thread unresolved rather than claiming it is handled.
There was a problem hiding this comment.
Correction to my previous reply: this remains a valid portability note because the current test fixture still only suppresses GCC and Clang deprecation diagnostics. I have not changed that fixture, so I am leaving this thread unresolved.
Unify the canonical batch distance-by-ID API spelling while preserving the historical source-compatible entry point during the migration window. Signed-off-by: Xiangyu Wang <wxy407827@antgroup.com> Assisted-by: OpenAI Codex:GPT-5
81dc2a2 to
3ec15a1
Compare
vsag-bot
left a comment
There was a problem hiding this comment.
Automated inline review completed.
Review effort: high (442 changed lines across 34 files).
Submitted 2 inline comments.
Reviewed commit 3ec15a1.
| * third-party Index implementations remain source-compatible. | ||
| */ | ||
| [[nodiscard]] virtual tl::expected<DatasetPtr, Error> | ||
| CalcDistancesById(const DatasetPtr& query, |
There was a problem hiding this comment.
[P1] Preserve the existing Index vtable layout
These new virtual overloads are inserted before GetMinAndMaxId and all subsequent virtual methods. An application or plugin compiled against the existing v1 header but loading this library will therefore dispatch later calls to slots with incompatible signatures, causing undefined behavior or crashes. Append new slots only after every pre-existing virtual entry, including the destructor, or use a nonvirtual forwarding API/bump the ABI version.
There was a problem hiding this comment.
Judged independently: this is valid and duplicates the existing unresolved ABI concern. The new public virtual overloads still precede existing Index virtual entries, so I am leaving this thread unresolved.
| InstanceMethod("getMemoryUsage", &VsagIndex::GetMemoryUsage), | ||
| InstanceMethod("checkIdExist", &VsagIndex::CheckIdExist), | ||
| InstanceMethod("getMinMaxId", &VsagIndex::GetMinMaxId), | ||
| InstanceMethod("calcDistancesById", &VsagIndex::CalcDistancesById), |
There was a problem hiding this comment.
[P2] Expose the corrected API through the TypeScript package
The npm package exports the wrapper generated from typescript/src/index.ts, but that Index class still exposes only calDistanceById; it has no calcDistancesById forwarding method or declaration. Consequently normal TypeScript consumers cannot call the newly registered native method. Add the corrected wrapper method while retaining the legacy alias.
There was a problem hiding this comment.
Judged independently: this is valid. The native Node binding exposes calcDistancesById, but typescript/src/index.ts still declares only calDistanceById, so the corrected API is not available to normal TypeScript consumers. I am leaving this thread unresolved.
Summary
CalcDistancesByIdfor raw-pointer andDatasetPtrqueries.CalDistanceByIdspelling as a deprecated, source-compatible alias through the 1.1 migration window.Compatibility
The public canonical
Index::CalcDistancesByIdoverloads default-forward to the legacy virtualIndex::CalDistanceByIdoverloads. This preserves existing third-party implementations that override only the historical spelling: calls through the new API reach their legacy overrides.Built-in concrete indexes use
CalcDistancesByIdas the canonical implementation entry point, while theirCalDistanceByIdwrappers forward toCalcDistancesById. The public/index and internal bridges therefore route old and new entry points through the appropriate shared implementation without recursive dispatch: legacy-only third-party overrides use the new-to-old bridge, and built-in implementations use the old-to-new wrapper.Verification
Build with TSANandRun TSAN Testson the prior commit.3ec15a1bis live: PR CI run30087602121and TSAN run30087602050are still in progress; Detect Changes and Format Check have passed.30087622023, DCO, Mergify protections, and CircleCI path filtering have passed. Compatibility workflow run30087601337concluded failure without a job log exposed by GitHub at verification time.python3.10-venv; Node binding build was unavailable becausenode-addon-apiis not installed.Fixes: #2068