Skip to content

Commit 726731f

Browse files
authored
Allow a DataAccessHint to be passed during the construction of a Lucene99FlatVectorsReader (#15569)
This is a small change to allow the DataAccessHint to be passed during the construction of a Lucene99FlatVectorsReader. The reader if often used in conjunction with a graph, where random access is appropriate. However, the reader can be used without a graph, when implementing a so-called "flat" index, where SEQUENTIAL would likely be more appropriate.
1 parent cf41f22 commit 726731f

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

lucene/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ API Changes
197197
and throughput. This provides visibility into Lucene's merge backpressure mechanisms that can
198198
stall indexing when merge debt accumulates. (Zihan Xu)
199199

200+
* GITHUB#15569: Allow a DataAccessHint to be passed during the construction of Lucene99FlatVectorsReader
201+
(Chris Hegarty)
202+
200203
New Features
201204
---------------------
202205
* GITHUB#15328: VectorSimilarityFunction.getValues() now implements doubleVal allowing its

lucene/core/src/java/org/apache/lucene/codecs/lucene99/Lucene99FlatVectorsReader.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
import java.io.IOException;
2424
import java.util.Map;
25+
import java.util.Objects;
26+
import java.util.stream.Stream;
2527
import org.apache.lucene.codecs.CodecUtil;
2628
import org.apache.lucene.codecs.hnsw.FlatVectorsReader;
2729
import org.apache.lucene.codecs.hnsw.FlatVectorsScorer;
@@ -43,6 +45,7 @@
4345
import org.apache.lucene.store.FileDataHint;
4446
import org.apache.lucene.store.FileTypeHint;
4547
import org.apache.lucene.store.IOContext;
48+
import org.apache.lucene.store.IOContext.FileOpenHint;
4649
import org.apache.lucene.store.IndexInput;
4750
import org.apache.lucene.util.IOUtils;
4851
import org.apache.lucene.util.RamUsageEstimator;
@@ -65,13 +68,27 @@ public final class Lucene99FlatVectorsReader extends FlatVectorsReader {
6568

6669
public Lucene99FlatVectorsReader(SegmentReadState state, FlatVectorsScorer scorer)
6770
throws IOException {
71+
this(state, scorer, DataAccessHint.RANDOM);
72+
}
73+
74+
/**
75+
* Creates a Lucene99FlatVectorsReader.
76+
*
77+
* @param state the segment read state
78+
* @param scorer the flat vectors scorer
79+
* @param accessHint a data access hint, or null
80+
*/
81+
public Lucene99FlatVectorsReader(
82+
SegmentReadState state, FlatVectorsScorer scorer, DataAccessHint accessHint)
83+
throws IOException {
6884
super(scorer);
6985
int versionMeta = readMetadata(state);
7086
this.fieldInfos = state.fieldInfos;
71-
// Flat formats are used to randomly access vectors from their node ID that is stored
72-
// in the HNSW graph.
73-
dataContext =
74-
state.context.withHints(FileTypeHint.DATA, FileDataHint.KNN_VECTORS, DataAccessHint.RANDOM);
87+
FileOpenHint[] hints =
88+
Stream.of(FileTypeHint.DATA, FileDataHint.KNN_VECTORS, accessHint)
89+
.filter(Objects::nonNull)
90+
.toArray(FileOpenHint[]::new);
91+
dataContext = state.context.withHints(hints);
7592
try {
7693
vectorData =
7794
openDataInput(

0 commit comments

Comments
 (0)