Skip to content

Reject maxConn=1 in HNSW vector formats - #17054

Open
qidaye wants to merge 2 commits into
apache:mainfrom
qidaye:fix-rebalance-maxconn-1
Open

qidaye wants to merge 2 commits into
apache:mainfrom
qidaye:fix-rebalance-maxconn-1

Conversation

@qidaye

@qidaye qidaye commented Nov 20, 2026 •

Copy link
Copy Markdown

Description

When maxConn=1, a merge that reuses the HNSW graph of a segment with deletions never terminates.
InitializedHnswGraphBuilder#rebalanceGraph computes the target number of nodes per level as
size * (1/M)^level. When M=1, this is always equal to size and never drops to 0. The loop only
exits when this value reaches 0, so it never exits.

maxConn=1 is a degenerate setting anyway, so instead of supporting it, this change rejects
maxConn < 2 in all writable HNSW vector formats

@msokolov

msokolov commented Nov 21, 2026 via email

Copy link
Copy Markdown
Contributor

@qidaye

qidaye commented Nov 23, 2026

Copy link
Copy Markdown
Author

Instead we should disallow Max Conn one. It's nonsensical.

Agreed, I'll disallow Max Conn one instead.

@qidaye

qidaye commented Nov 23, 2026

Copy link
Copy Markdown
Author

I plan to reject maxConn < 2 in all writable HNSW format constructors.
But there is a problem. maxConn=1 has always been allowed, so existing indexes may contain graphs with M=1. After an upgrade, such indexes will reuse the old graph during merge and carry over its M=1, regardless of the M configured in the new writer.

I'm considering two options:

  1. reject new writes and keep the 1/e handling in the rebalance for the old graphs.
  2. also forbid using M<2 in builder, and rebuild graphs instead of reusing the old ones.

I prefer the 1.
Can you give me some advice? @msokolov

And should this CHANGES be treated as bug fix or API change?

@msokolov

Copy link
Copy Markdown
Contributor

I don't think you need to concern yourself with existing usage of maxconn=1 given the problem you found

@qidaye
qidaye force-pushed the fix-rebalance-maxconn-1 branch from d349c76 to f4b12fd Compare November 24, 2026 01:35
@qidaye qidaye changed the title Fix HNSW rebalanceGraph never terminating when maxConn is 1 Reject maxConn=1 in HNSW vector formats Nov 24, 2026
maxConn=1 produces a degenerate graph, and merging such a graph after
deletions never terminates: rebalanceGraph() expects (1/M)^level nodes
on each level, which never drops to zero when M == 1. Require maxConn
to be at least 2 in the writable HNSW formats instead of supporting it.
@qidaye
qidaye force-pushed the fix-rebalance-maxconn-1 branch from f4b12fd to 2d3a751 Compare November 24, 2026 02:50
@qidaye

qidaye commented Nov 24, 2026

Copy link
Copy Markdown
Author

I don't think you need to concern yourself with existing usage of maxconn=1 given the problem you found

Thanks for your advice.
I have changed the fix to reject maxConn < 2 in the HNSW formats. Please take a look, thanks.

@msokolov msokolov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks, looks good except I would reclassify the comment in CHANGES

Comment thread lucene/CHANGES.txt Outdated

Bug Fixes
---------------------
* GITHUB#17054: HNSW vector formats now reject maxConn=1, since merging an HNSW graph with

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this belongs under API Changes rather than Bug Fixes

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have moved this to API Changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants