Skip to content

Conversation

@shubhamvishu
Copy link
Contributor

Description

We don't need to call getGraph twice (which then calls new OffHeapHnswGraph to initialize graph) where we are only interested to the graph size.

int unfilteredVisit = HnswGraphSearcher.expectedVisitedNodes(knnCollector.k(), graph.size());
if (unfilteredVisit >= filteredDocCount || graph.size() == 0) {
int unfilteredVisit = HnswGraphSearcher.expectedVisitedNodes(knnCollector.k(), graphSize);
if (unfilteredVisit >= filteredDocCount || graphSize == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

What about when the building the graph is delayed? We likely need to validate entry.vectorIndexLength == 0 . right now we use the side-effect of an empty graph as a way to skip hnsw graph search.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are already checking that on L338. So in case of delayed graph building graphSize will be 0 because fieldEntry.vectorIndexLength == 0 (same as current) or else the size of graph (when fieldEntry.vectorIndexLength != 0) .

This tries to replicate the getGraph logic but without having to initialize the graph unnecessarily.

Copy link
Member

Choose a reason for hiding this comment

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

I initially misread that logic. You are correct, shipit!

But, even for smaller things like this, its nice to have a CHANGES entry under "optimizations" that way we have a nice trail even outside of github commits :)

Copy link
Member

@benwtrent benwtrent left a comment

Choose a reason for hiding this comment

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

It would be nice to have a CHANGES entry under optimizations. But this is good!

@github-actions github-actions bot added this to the 10.4.0 milestone Jan 12, 2026
@shubhamvishu
Copy link
Contributor Author

Thanks @benwtrent ! I added a changes entry. I'll ship it once all checks complete.

@shubhamvishu shubhamvishu merged commit 00b9533 into apache:main Jan 12, 2026
12 checks passed
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