You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ka...@apache.org on 2026/03/09 18:59:10 UTC
(lucene) branch main updated: Improve prefix sum in Lucene99HnswVectorsReader (#15024) (#15790)
This is an automated email from the ASF dual-hosted git repository.
kaivalnp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/main by this push:
new fb2b916b1b2 Improve prefix sum in Lucene99HnswVectorsReader (#15024) (#15790)
fb2b916b1b2 is described below
commit fb2b916b1b22800e959f0dfb43c241fdc58cb209
Author: Luis Negrin <51...@users.noreply.github.com>
AuthorDate: Mon Mar 9 14:59:05 2026 -0400
Improve prefix sum in Lucene99HnswVectorsReader (#15024) (#15790)
---
lucene/CHANGES.txt | 2 ++
.../lucene/codecs/lucene99/Lucene99HnswVectorsReader.java | 12 +++++++-----
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 52a6801ad7a..3cfc437107a 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -239,6 +239,8 @@ Optimizations
* GITHUB#15742: Optimize int4 dotProduct and squareDistance computations by replacing vector conversions with reinterpret casting + bit manipulation. (Trevor McCulloch, Kaival Parikh)
+* GITHUB#15024: Improve prefix sum computation in Lucene99HnswVectorsReader for faster neighbor decoding. (Luis Negrin)
+
Bug Fixes
---------------------
* GITHUB#15754: Fix HTMLStripCharFilter to prevent tags from incorrectly consuming subsequent
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99HnswVectorsReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99HnswVectorsReader.java
index 0931048d7ac..fbe4e2da2cb 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99HnswVectorsReader.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99HnswVectorsReader.java
@@ -561,15 +561,17 @@ public final class Lucene99HnswVectorsReader extends KnnVectorsReader
arcCount = dataIn.readVInt();
assert arcCount <= currentNeighborsBuffer.length : "too many neighbors: " + arcCount;
if (arcCount > 0) {
+ int sum = 0;
if (version >= VERSION_GROUPVARINT) {
GroupVIntUtil.readGroupVInts(dataIn, currentNeighborsBuffer, arcCount);
- for (int i = 1; i < arcCount; i++) {
- currentNeighborsBuffer[i] = currentNeighborsBuffer[i - 1] + currentNeighborsBuffer[i];
+ for (int i = 0; i < arcCount; i++) {
+ sum += currentNeighborsBuffer[i];
+ currentNeighborsBuffer[i] = sum;
}
} else {
- currentNeighborsBuffer[0] = dataIn.readVInt();
- for (int i = 1; i < arcCount; i++) {
- currentNeighborsBuffer[i] = currentNeighborsBuffer[i - 1] + dataIn.readVInt();
+ for (int i = 0; i < arcCount; i++) {
+ sum += dataIn.readVInt();
+ currentNeighborsBuffer[i] = sum;
}
}
}