Skip to content

Commit 53854e4

Browse files
committed
Merge branch 'main' into dedup-raw-vectors
2 parents 46c0d27 + 9582ee9 commit 53854e4

95 files changed

Lines changed: 3614 additions & 1994 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lucene/CHANGES.txt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ Improvements
123123

124124
* GITHUB#15453: Avoid unnecessary sorting and instantiations in readMapOfStrings. (Benjamin Lerer)
125125

126-
* GITHUB#15574: Introduce TopGroupsCollectorManager to parallelize search when using TopGroupsCollector. (Binlong Gao)
127-
128126
* GITHUB#15225: Improve package documentation for org.apache.lucene.util. (Syed Mohammad Saad)
129127

130128
* GITHUB#15558: Refactor QueryCache for performance. (Sagar Upadhyaya)
@@ -263,6 +261,9 @@ API Changes
263261
* GITHUB#15803: Add ReaderUtil#partitionByLeaf to partition doc IDs from
264262
ScoreDoc hits by leaf reader. (Zihan Xu)
265263

264+
* GITHUB#15584: Add support for termdoc fields that use custom term freqs (via IndexOptions.DOCS_AND_CUSTOM_FREQS).
265+
IndexWriter counts their terms rather than summing their freqs. Use
266+
266267
New Features
267268
---------------------
268269

@@ -301,6 +302,11 @@ Improvements
301302

302303
* GITHUB#15976: Store DocValuesSkipper data in their own file. (Alan Woodward)
303304

305+
* GITHUB#15574: Introduce TopGroupsCollectorManager to parallelize search when using TopGroupsCollector. (Binlong Gao)
306+
307+
* GITHUB#15989: DocValuesRangeIterator always tries to use skipper-based block iteration
308+
as its approximation. (Alan Woodward)
309+
304310
Optimizations
305311
---------------------
306312
* GITHUB#15861: Optimise PhraseScorer by short circuiting non competitive documents in TOP_SCORES mode. (Prithvi S)
@@ -321,6 +327,8 @@ Optimizations
321327

322328
* GITHUB#15886: Cache frozen FieldType to skip redundant schema validation. (Tim Brooks)
323329

330+
* GITHUB#15942: Skip max score computation when sorting by relevance in BlockGroupingCollector (Binlong Gao)
331+
324332
* GITHUB#15902: Improve DiversifyingChildren performance by using primitive arrays(Alessandro Benedetti)
325333

326334
* GITHUB#15954: Use SkipBlockRangeIterator as the two-phase approximation in SortedNumericDocValuesRangeQuery. (Sagar Upadhyaya)
@@ -330,6 +338,12 @@ Optimizations
330338

331339
* GITHUB#15970: Reduce memory usage of fields with long terms during segment merges. (Alan Woodward)
332340

341+
* GITHUB#15868: Optimize DisjunctionMaxBulkScorer by reusing the inner LeafCollector across
342+
sub-scorers and resetting windowScores inline during replay instead of Arrays.fill. (Prithvi S)
343+
344+
* GITHUB#15732: Prevent writing vectors twice during merging HNSW graphs by allowing doing deferred work after calling
345+
merge for vectors is finshed. (Ignacio Vera)
346+
333347
Bug Fixes
334348
---------------------
335349
* GITHUB#15754: Fix HTMLStripCharFilter to prevent tags from incorrectly consuming subsequent

lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene101/Lucene101PostingsReader.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,11 @@ public void decodeTerm(
227227
termState.singletonDocID += BitUtil.zigZagDecode(l >>> 1);
228228
}
229229

230-
if (fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) {
230+
if (fieldInfo.getIndexOptions().subsumes(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)) {
231231
termState.posStartFP += in.readVLong();
232232
if (fieldInfo
233-
.getIndexOptions()
234-
.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS)
235-
>= 0
233+
.getIndexOptions()
234+
.subsumes(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS)
236235
|| fieldInfo.hasPayloads()) {
237236
termState.payStartFP += in.readVLong();
238237
}
@@ -403,10 +402,9 @@ private enum DeltaEncoding {
403402
public BlockPostingsEnum(FieldInfo fieldInfo, int flags, boolean needsImpacts)
404403
throws IOException {
405404
options = fieldInfo.getIndexOptions();
406-
indexHasFreq = options.compareTo(IndexOptions.DOCS_AND_FREQS) >= 0;
407-
indexHasPos = options.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
408-
indexHasOffsets =
409-
options.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
405+
indexHasFreq = options.subsumes(IndexOptions.DOCS_AND_FREQS);
406+
indexHasPos = options.subsumes(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
407+
indexHasOffsets = options.subsumes(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
410408
indexHasPayloads = fieldInfo.hasPayloads();
411409
indexHasOffsetsOrPayloads = indexHasOffsets || indexHasPayloads;
412410

lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene102/Lucene102BinaryFlatVectorsScorer.java

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.lucene.util.VectorUtil;
3131
import org.apache.lucene.util.hnsw.RandomVectorScorer;
3232
import org.apache.lucene.util.hnsw.RandomVectorScorerSupplier;
33+
import org.apache.lucene.util.hnsw.UpdateableRandomVectorScorer;
3334
import org.apache.lucene.util.quantization.OptimizedScalarQuantizer;
3435
import org.apache.lucene.util.quantization.OptimizedScalarQuantizer.QuantizationResult;
3536

@@ -54,7 +55,7 @@ public Lucene102BinaryFlatVectorsScorer(FlatVectorsScorer nonQuantizedDelegate)
5455
public RandomVectorScorerSupplier getRandomVectorScorerSupplier(
5556
VectorSimilarityFunction similarityFunction, KnnVectorValues vectorValues)
5657
throws IOException {
57-
throw new UnsupportedOperationException("Old codecs may only be used for reading");
58+
return nonQuantizedDelegate.getRandomVectorScorerSupplier(similarityFunction, vectorValues);
5859
}
5960

6061
@Override
@@ -98,6 +99,62 @@ public String toString() {
9899
return "Lucene102BinaryFlatVectorsScorer(nonQuantizedDelegate=" + nonQuantizedDelegate + ")";
99100
}
100101

102+
RandomVectorScorerSupplier getRandomVectorScorerSupplier(
103+
VectorSimilarityFunction similarityFunction,
104+
Lucene102BinaryQuantizedVectorsReader.OffHeapBinarizedQueryVectorValues scoringVectors,
105+
BinarizedByteVectorValues targetVectors) {
106+
return new BinarizedRandomVectorScorerSupplier(
107+
scoringVectors, targetVectors, similarityFunction);
108+
}
109+
110+
/** Vector scorer supplier over binarized vector values */
111+
static class BinarizedRandomVectorScorerSupplier implements RandomVectorScorerSupplier {
112+
private final Lucene102BinaryQuantizedVectorsReader.OffHeapBinarizedQueryVectorValues
113+
queryVectors;
114+
private final BinarizedByteVectorValues targetVectors;
115+
private final VectorSimilarityFunction similarityFunction;
116+
117+
BinarizedRandomVectorScorerSupplier(
118+
Lucene102BinaryQuantizedVectorsReader.OffHeapBinarizedQueryVectorValues queryVectors,
119+
BinarizedByteVectorValues targetVectors,
120+
VectorSimilarityFunction similarityFunction) {
121+
this.queryVectors = queryVectors;
122+
this.targetVectors = targetVectors;
123+
this.similarityFunction = similarityFunction;
124+
}
125+
126+
@Override
127+
public UpdateableRandomVectorScorer scorer() throws IOException {
128+
final BinarizedByteVectorValues targetVectors = this.targetVectors.copy();
129+
final Lucene102BinaryQuantizedVectorsReader.OffHeapBinarizedQueryVectorValues queryVectors =
130+
this.queryVectors.copy();
131+
return new UpdateableRandomVectorScorer.AbstractUpdateableRandomVectorScorer(targetVectors) {
132+
private QuantizationResult queryCorrections = null;
133+
private byte[] vector = null;
134+
135+
@Override
136+
public void setScoringOrdinal(int node) throws IOException {
137+
queryCorrections = queryVectors.getCorrectiveTerms(node);
138+
vector = queryVectors.vectorValue(node);
139+
}
140+
141+
@Override
142+
public float score(int node) throws IOException {
143+
if (vector == null || queryCorrections == null) {
144+
throw new IllegalStateException("setScoringOrdinal was not called");
145+
}
146+
return quantizedScore(vector, queryCorrections, targetVectors, node, similarityFunction);
147+
}
148+
};
149+
}
150+
151+
@Override
152+
public RandomVectorScorerSupplier copy() throws IOException {
153+
return new BinarizedRandomVectorScorerSupplier(
154+
queryVectors.copy(), targetVectors.copy(), similarityFunction);
155+
}
156+
}
157+
101158
static float quantizedScore(
102159
byte[] quantizedQuery,
103160
QuantizationResult queryCorrections,

0 commit comments

Comments
 (0)