Skip to content

feat(Hgraph): support tunning alpha in MRNG#1104

Merged
ShawnShawnYou merged 2 commits intoantgroup:mainfrom
HeHuMing:main
Sep 23, 2025
Merged

feat(Hgraph): support tunning alpha in MRNG#1104
ShawnShawnYou merged 2 commits intoantgroup:mainfrom
HeHuMing:main

Conversation

@HeHuMing
Copy link
Copy Markdown
Contributor

@HeHuMing HeHuMing commented Sep 1, 2025

close #1060

alpha=1 0 alpha=1 2

After alpha is exposed, with Recallavg aligned on the gist-960 dataset, QPS increases by 14.3%.

@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
Copy link
Copy Markdown

sourcery-ai bot commented Sep 1, 2025

Reviewer's Guide

Add support for a tunable “alpha” parameter in MRNG-based HGraph and Pyramid indices by propagating the new parameter through configuration parsing, class initialization, neighbor‐connection routines, constants, and examples.

Sequence diagram for neighbor connection with alpha parameter in MRNG

sequenceDiagram
    participant HGraph
    participant PruningStrategy
    participant Graph
    HGraph->>PruningStrategy: mutually_connect_new_element(..., alpha)
    PruningStrategy->>Graph: select_edges_by_heuristic(..., alpha)
    Note right of PruningStrategy: Alpha influences edge selection
Loading

Entity relationship diagram for new alpha field in index configuration

erDiagram
    HGRAPH_PARAMETER {
        float alpha
    }
    PYRAMID_PARAMETERS {
        float alpha
    }
    HGRAPH_PARAMETER ||--o| HGRAPH : configures
    PYRAMID_PARAMETERS ||--o| PYRAMID : configures
Loading

Class diagram for updated HGraph and Pyramid with tunable alpha parameter

classDiagram
    class HGraphParameter {
        +float alpha
        +FromJson(json)
        +ToJson()
    }
    class PyramidParameters {
        +float alpha
        +FromJson(json)
        +ToJson()
    }
    class HGraph {
        +float alpha_
        +HGraphParameter hgraph_params_
        +HGraph(hgraph_param, common_param)
    }
    class Pyramid {
        +float alpha_
        +Pyramid(pyramid_param, common_param)
    }
    HGraphParameter <|-- HGraph
    PyramidParameters <|-- Pyramid
    HGraphParameter : FromJson(json)
    HGraphParameter : ToJson()
    PyramidParameters : FromJson(json)
    PyramidParameters : ToJson()
Loading

File-Level Changes

Change Details Files
Parameter parsing and serialization for alpha
  • Define BUILD_ALPHA_KEY and HGRAPH_BUILD_ALPHA constants
  • Extend HGraphParameter::FromJson/ToJson to read/write alpha
  • Extend PyramidParameters::FromJson/ToJson to read/write alpha
  • Update HGraph::CheckAndMappingExternalParam to map build_params.alpha
src/algorithm/hgraph_parameter.cpp
src/algorithm/hgraph_parameter.h
src/algorithm/pyramid_zparameters.cpp
src/algorithm/pyramid_zparameters.h
src/inner_string_params.h
include/vsag/constants.h
src/constants.cpp
src/algorithm/hgraph.cpp
Introduce alpha member in index classes
  • Add alpha_ field and initialize it from parameters in HGraph constructor
  • Add alpha_ field and initialize it in Pyramid constructor
src/algorithm/hgraph.cpp
src/algorithm/hgraph.h
src/algorithm/pyramid.h
Propagate alpha into neighbor connection logic
  • Pass alpha to mutually_connect_new_element in HGraph::graph_add_one and Pyramid::Add
  • Extend pruning_strategy to accept alpha and forward it to select_edges_by_heuristic
  • Update pruning_strategy.cpp and pruning_strategy.h function signatures
src/algorithm/hgraph.cpp
src/algorithm/pyramid.cpp
src/impl/pruning_strategy.cpp
src/impl/pruning_strategy.h
Update examples and benchmarks
  • Include alpha in example code index parameters
  • Adjust ef_search and add alpha in bench YAML for hgraph-90
examples/cpp/103_index_hgraph.cpp
benchs/indexes/hgraph-90.yml

Possibly linked issues

  • introduce simple resource_pool #123: The PR introduces the 'alpha' parameter in HGraph and Pyramid, allowing control over the MRNG process, directly addressing the issue's request.

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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

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 and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/algorithm/hgraph_parameter.cpp:132` </location>
<code_context>
         if (build_params.contains(BUILD_EF_CONSTRUCTION)) {
             this->ef_construction = build_params[BUILD_EF_CONSTRUCTION];
         }
+        if (build_params.contains(BUILD_ALPHA_KEY)) {
+            this->alpha = build_params[BUILD_ALPHA_KEY];
+        }
         if (build_params.contains(BUILD_THREAD_COUNT)) {
</code_context>

<issue_to_address>
Type safety for alpha assignment from JSON should be ensured.

Validate or convert build_params[BUILD_ALPHA_KEY] to float before assignment to prevent type-related errors.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
        if (build_params.contains(BUILD_ALPHA_KEY)) {
            this->alpha = build_params[BUILD_ALPHA_KEY];
        }
=======
        if (build_params.contains(BUILD_ALPHA_KEY)) {
            // Ensure type safety: convert to float if necessary
            if (build_params[BUILD_ALPHA_KEY].is_number_float()) {
                this->alpha = build_params[BUILD_ALPHA_KEY].get<float>();
            } else if (build_params[BUILD_ALPHA_KEY].is_number_integer()) {
                this->alpha = static_cast<float>(build_params[BUILD_ALPHA_KEY].get<int>());
            } else {
                // Handle unexpected type (optional: throw, log, or set default)
                this->alpha = 0.0f; // or handle error as appropriate
            }
        }
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `src/algorithm/pyramid_zparameters.cpp:53` </location>
<code_context>
         if (build_params.contains(BUILD_EF_CONSTRUCTION)) {
             this->ef_construction = build_params[BUILD_EF_CONSTRUCTION];
         }
+        if (build_params.contains(BUILD_ALPHA_KEY)) {
+            this->alpha = build_params[BUILD_ALPHA_KEY];
+        }
         if (build_params.contains(BUILD_THREAD_COUNT)) {
</code_context>

<issue_to_address>
Type conversion for alpha from JSON should be explicit.

Assigning directly from JSON can cause type issues if the value isn't a float. Use an explicit cast to ensure type safety.
</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/algorithm/hgraph_parameter.cpp Outdated
Comment on lines +132 to +134
if (build_params.contains(BUILD_ALPHA_KEY)) {
this->alpha = build_params[BUILD_ALPHA_KEY];
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Type safety for alpha assignment from JSON should be ensured.

Validate or convert build_params[BUILD_ALPHA_KEY] to float before assignment to prevent type-related errors.

Suggested change
if (build_params.contains(BUILD_ALPHA_KEY)) {
this->alpha = build_params[BUILD_ALPHA_KEY];
}
if (build_params.contains(BUILD_ALPHA_KEY)) {
// Ensure type safety: convert to float if necessary
if (build_params[BUILD_ALPHA_KEY].is_number_float()) {
this->alpha = build_params[BUILD_ALPHA_KEY].get<float>();
} else if (build_params[BUILD_ALPHA_KEY].is_number_integer()) {
this->alpha = static_cast<float>(build_params[BUILD_ALPHA_KEY].get<int>());
} else {
// Handle unexpected type (optional: throw, log, or set default)
this->alpha = 0.0f; // or handle error as appropriate
}
}

Comment thread src/algorithm/pyramid_zparameters.cpp Outdated
Comment on lines +53 to +54
if (build_params.contains(BUILD_ALPHA_KEY)) {
this->alpha = build_params[BUILD_ALPHA_KEY];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Type conversion for alpha from JSON should be explicit.

Assigning directly from JSON can cause type issues if the value isn't a float. Use an explicit cast to ensure type safety.

Signed-off-by: HeHuMing <hehuming434@gmail.com>
Signed-off-by: HeHuMing <hehuming434@gmail.com>
Copy link
Copy Markdown
Collaborator

@ShawnShawnYou ShawnShawnYou left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Collaborator

@inabao inabao left a comment

Choose a reason for hiding this comment

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

LGTM

@codecov
Copy link
Copy Markdown

codecov bot commented Sep 23, 2025

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.

@@            Coverage Diff             @@
##             main    #1104      +/-   ##
==========================================
- Coverage   92.14%   92.02%   -0.12%     
==========================================
  Files         310      310              
  Lines       18526    18537      +11     
==========================================
- Hits        17070    17058      -12     
- Misses       1456     1479      +23     
Flag Coverage Δ
cpp 92.02% <94.73%> (-0.12%) ⬇️

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

Components Coverage Δ
common 90.72% <ø> (ø)
datacell 91.49% <ø> (-0.21%) ⬇️
index 91.01% <94.11%> (-0.14%) ⬇️
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 463e9d5...2309048. 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 assigned inabao and unassigned HeHuMing Sep 23, 2025
@wxyucs wxyucs added kind/feature New feature kind/improvement Code improvements (variable/function renaming, refactoring, etc. ) version/0.17 and removed kind/feature New feature labels Sep 23, 2025
Copy link
Copy Markdown
Collaborator

@wxyucs wxyucs left a comment

Choose a reason for hiding this comment

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

lgtm

@ShawnShawnYou ShawnShawnYou merged commit 55f651f into antgroup:main Sep 23, 2025
36 of 40 checks passed
LHT129 pushed a commit to LHT129/vsag that referenced this pull request Apr 16, 2026
Signed-off-by: HeHuMing <hehuming434@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/improvement Code improvements (variable/function renaming, refactoring, etc. ) module/tools size/M version/0.17

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add parameter in HGraph to control the MRNG

4 participants