Skip to content

Support Export All ID from index#1069

Merged
LHT129 merged 1 commit into
antgroup:mainfrom
LHT129:label
Aug 20, 2025
Merged

Support Export All ID from index#1069
LHT129 merged 1 commit into
antgroup:mainfrom
LHT129:label

Conversation

@LHT129

@LHT129 LHT129 commented Aug 19, 2025

Copy link
Copy Markdown
Collaborator

closed: #1068

Summary by Sourcery

Add support for exporting all IDs from an index through a new ExportIDs API, enable it via a feature flag, implement it in index internals, and validate it with unit tests.

New Features:

  • Add ExportIDs method in the Index interface and its implementation to export all stored IDs as a Dataset

Enhancements:

  • Introduce SUPPORT_EXPORT_IDS feature flag and expose it in the InnerIndexInterface
  • Add GetAllLabels in LabelTable for bulk label retrieval

Documentation:

  • Document the ExportIDs API in index.h

Tests:

  • Add TestExportIDs in TestIndex and invoke it in HGraph and IVF test suites to verify ExportIDs functionality

@LHT129 LHT129 self-assigned this Aug 19, 2025
@LHT129
LHT129 requested a review from inabao as a code owner August 19, 2025 08:31
@LHT129 LHT129 added the kind/feature Brand-new functionality or capabilities 引入全新的功能、新特性或新能力 label Aug 19, 2025
@LHT129 LHT129 added the version/0.17 1. HGraph enhancements 2. Quantization and ISA enhancements 1. HGraph 继续增强 2. 量化与指令集增强 label Aug 19, 2025
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Important

Installation incomplete: to start using Gemini Code Assist, please ask the organization owner(s) to visit the Gemini Code Assist Admin Console and sign the Terms of Services.

@sourcery-ai

sourcery-ai Bot commented Aug 19, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR adds comprehensive support for exporting all index IDs by introducing a new feature flag, defining the ExportIDs API across interfaces and implementations, exposing label table data, and validating the functionality with new unit tests.

Entity relationship diagram for LabelTable and Dataset in ExportIDs

erDiagram
    LABEL_TABLE {
        int64_t id
        LabelType label_table[]
    }
    DATASET {
        int64_t num_elements
        LabelType ids[]
        int dim
        bool owner
    }
    LABEL_TABLE ||--o| DATASET : exports IDs
Loading

Class diagram for ExportIDs API integration

classDiagram
    class Index {
        +ExportIDs() : tl::expected<DatasetPtr, Error>
    }
    class IndexImpl {
        +ExportIDs() : tl::expected<DatasetPtr, Error>
    }
    class InnerIndexInterface {
        +ExportIDs() : DatasetPtr
    }
    Index <|-- IndexImpl
    IndexImpl o-- InnerIndexInterface

    class LabelTable {
        +GetAllLabels() : const LabelType*
    }
    InnerIndexInterface o-- LabelTable

    class Dataset {
        +Make()
        +NumElements()
        +Ids()
        +Dim()
        +Owner()
    }
    InnerIndexInterface o-- Dataset
Loading

Class diagram for new IndexFeature SUPPORT_EXPORT_IDS

classDiagram
    class IndexFeature {
        <<enum>>
        SUPPORT_EXPORT_IDS
    }
Loading

File-Level Changes

Change Details Files
Introduce SUPPORT_EXPORT_IDS feature flag
  • Enable SUPPORT_EXPORT_IDS in InnerIndexInterface constructor
  • Add SUPPORT_EXPORT_IDS to the index_features enum
src/algorithm/inner_index_interface.cpp
include/vsag/index_features.h
Define and implement ExportIDs API
  • Declare virtual ExportIDs in the public Index interface
  • Define ExportIDs in InnerIndexInterface header and implementation
  • Override ExportIDs in IndexImpl using SAFE_CALL
include/vsag/index.h
src/algorithm/inner_index_interface.h
src/algorithm/inner_index_interface.cpp
src/index/index_impl.h
Expose full label table data for export
  • Add GetAllLabels() accessor to LabelTable to retrieve raw label array
src/label_table.h
Add and integrate TestExportIDs unit tests
  • Implement TestExportIDs in test_index.cpp and declare in test_index.h
  • Invoke TestExportIDs in hgraph and IVF test suites
tests/test_index.cpp
tests/test_index.h
tests/test_hgraph.cpp
tests/test_ivf.cpp

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • You’re unconditionally setting SUPPORT_EXPORT_IDS for every InnerIndexInterface in its constructor, which can advertise export support even when no specialized implementation exists; consider moving feature registration into only those index types that truly support ExportIDs.
  • The ExportIDs implementation eagerly allocates and copies all labels, which could be expensive for large datasets; consider providing a zero-copy view or sharing the underlying label buffer when safe.
  • ExportIDs falls back to throwing std::runtime_error on unsupported indices, but other methods use tl::expected<...,Error>; consider aligning on the expected-based error handling to keep the API consistent.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- You’re unconditionally setting SUPPORT_EXPORT_IDS for every InnerIndexInterface in its constructor, which can advertise export support even when no specialized implementation exists; consider moving feature registration into only those index types that truly support ExportIDs.
- The ExportIDs implementation eagerly allocates and copies all labels, which could be expensive for large datasets; consider providing a zero-copy view or sharing the underlying label buffer when safe.
- ExportIDs falls back to throwing std::runtime_error on unsupported indices, but other methods use tl::expected<...,Error>; consider aligning on the expected-based error handling to keep the API consistent.

## Individual Comments

### Comment 1
<location> `src/label_table.h:115` </location>
<code_context>
         return this->label_table_[inner_id];
     }

+    inline const LabelType*
+    GetAllLabels() const {
+        return label_table_.data();
+    }
+
</code_context>

<issue_to_address>
Returning raw pointer exposes internal storage.

This approach risks dangling pointers if the vector is modified. Please document this behavior or restrict usage to prevent misuse.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    inline const LabelType*
    GetAllLabels() const {
        return label_table_.data();
    }
=======
    // WARNING: Returns a pointer to the internal storage of label_table_.
    // The returned pointer may become invalid if label_table_ is modified (e.g., resized).
    // Use only when you can guarantee that label_table_ will not be changed while the pointer is in use.
    // This function is intended for advanced usage only.
    inline const LabelType*
    GetAllLabels() const {
        return label_table_.data();
    }
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `include/vsag/index.h:541` </location>
<code_context>
+     * @return DatasetPtr A pointer to the exported IDs dataset.
+     * @throws std::runtime_error If the index does not support exporting the IDs.
+     */
+    virtual tl::expected<DatasetPtr, Error>
+    ExportIDs() const {
+        throw std::runtime_error("Index doesn't support ExportIDs");
+    }
+
</code_context>

<issue_to_address>
Throwing runtime_error may not match expected error handling.

Consider returning tl::unexpected(Error(...)) instead of throwing, to align with the method's error handling approach.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/label_table.h
Comment thread include/vsag/index.h
Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
@codecov

codecov Bot commented Aug 19, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.23529% with 2 lines in your changes missing coverage. Please review.

@@            Coverage Diff             @@
##             main    #1069      +/-   ##
==========================================
+ Coverage   91.67%   91.74%   +0.07%     
==========================================
  Files         303      303              
  Lines       17278    17295      +17     
==========================================
+ Hits        15839    15867      +28     
+ Misses       1439     1428      -11     
Flag Coverage Δ
cpp 91.74% <88.23%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
common 92.75% <100.00%> (+0.12%) ⬆️
datacell 90.63% <ø> (+0.16%) ⬆️
index 91.05% <100.00%> (+0.05%) ⬆️
simd 100.00% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f863d6...cca44b5. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wxyucs wxyucs left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@inabao inabao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@LHT129
LHT129 merged commit 2b0e3f7 into antgroup:main Aug 20, 2025
28 of 30 checks passed
LHT129 added a commit to LHT129/vsag that referenced this pull request Apr 16, 2026
Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
LHT129 added a commit that referenced this pull request May 11, 2026
Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
@LHT129
LHT129 deleted the label branch May 29, 2026 07:20
Sia-Sheerland pushed a commit to Sia-Sheerland/vsag that referenced this pull request Jun 26, 2026
Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
Signed-off-by: Sia Sheerland <x1075956441x@163.com>

Signed-off-by: Sia Sheerland <x1075956441x@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Brand-new functionality or capabilities 引入全新的功能、新特性或新能力 module/testing size/M version/0.17 1. HGraph enhancements 2. Quantization and ISA enhancements 1. HGraph 继续增强 2. 量化与指令集增强

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support all ID export from an exists index

3 participants