37713 Commits

Author SHA1 Message Date
Christine Poerschke
2c81649e28
lucene-monitor: make TermFilteredPresearcher.ANYTOKEN[_FIELD] public (#13379) 2024-05-17 11:26:08 +01:00
Adrien Grand
c5331df1c4
Use IndexInput#prefetch for postings, skip data and impacts (#13364)
This uses the `IndexInput#prefetch` API for postings. This relies on heuristics, as we don't know ahead of time what data we will need from a postings list:
 - Postings lists are prefetched entirely when they are short (< 16kB).
 - Impacts enums also prefetch the first page of skip data.
 - Postings enums prefetc skip data on the first call to advance().

Positions, offsets and payloads are never prefetched.

Putting the `IndexInput#prefetch` call in `TermsEnum#postings` and `TermsEnum#impacts` works well because `BooleanQuery` will first create postings/impacts enums for all clauses before it starts unioning/intersecting them. This allows the prefetching logic to run in parallel across all clauses of the same query on the same segment.
2024-05-17 09:07:07 +02:00
Chris Hegarty
3d671a0fbe
Fix bug in SQ when just a single vector present in a segment (#13374)
This commit fixes a corner case in the ScalarQuantizer when just a single vector is present. I ran into this when updating a test that previously passed successfully with Lucene 9.10 but fails in 9.x.

The score error correction is calculated to be NaN, as there are no score docs or variance.
2024-05-16 14:59:56 +01:00
Chris Hegarty
731cecf730
Fix points writing with no values (#13378)
This commit updates the writer to handle the case where there are no values.

Previously (before #13369), there was a check that there were some points values before trying to write, this is no longer the case. The code in writeFieldNDims has an assumption that the values is not empty - an empty values will result in calculating a negative number of splits, and a negate array size to hold the splits.

The fix is trivial, return null when values is empty - null is an allowable return value from this method. Note: writeField1Dim is able to handle an empty values.
2024-05-16 14:24:00 +01:00
Benjamin Trent
b1d3c08619
Fix weird NRT bug #13353 (#13369)
The issue outlines the problem. When we have point value dimensions, segment core readers assume that there will be point files.

However, when allowing soft deletes and a document fails indexing failed before a point field could be written, this assumption fails. Consequently, the NRT fails to open. I settled on always flushing a point file if the field info says there are point fields, even if there aren't any docs in the buffer.

closes #13353
2024-05-15 09:37:19 -04:00
Adrien Grand
46f1f95ceb
Make IndexInput#prefetch take an offset. (#13363)
This makes `IndexInput#prefetch` take an offset instead of being relative to
the current position. This avoids requiring callers to seek only to call
`prefetch()`.
2024-05-14 18:43:21 +02:00
Sanjay Dutt
838b23ebed
Make Weight#scorerSupplier abstract, Weight#scorer final (#13319)
Co-authored-by: iamsanjay <sanjaydutt.india@yahoo.com>
2024-05-14 17:44:30 +02:00
Tim Grein
8e5409c9b4
Add sub query explanations in DisjunctionMaxQuery#explain on no-match (#13362) 2024-05-14 17:28:14 +02:00
Tim Grein
dae7181a97
Align toString methods in geo module (#13302)
* Align toString methods in geo module
2024-05-14 16:31:34 +02:00
panguixin
37837133c3
Remove unnecessary bit conversion for IndexSorter (#13320) 2024-05-14 15:05:51 +02:00
Benjamin Trent
3aa25baac7
Protect against nan & inf values in quantizer and test with tiny vectors (#13366) 2024-05-14 07:30:38 -04:00
Bruno Roustant
bcb62f56ad
Call ArrayUtil.copyArray instead of ArrayUtil.copySubArray for full array copy. (#13360) 2024-05-14 11:32:18 +02:00
Benjamin Trent
fc12cc1847
Fix vector scorer interface consistency (#13365)
Follow up to: #13181

I noticed the quantized interface had a slightly different name.

Additionally, testing showed we are inconsistent when there aren't any vectors to score. This makes the response consistent (e.g. null when there aren't any vectors).
2024-05-13 13:02:38 -04:00
Benjamin Trent
f10748cee7
Ensure negative scores aren not returned from scalar quantization scorer (#13356)
Depending on how we quantize and then scale, we can edge down below 0 for dotproduct scores.

This is exceptionally rare, I have only seen it in extreme circumstances in tests (with random data and low dimensionality).
2024-05-13 11:00:04 -04:00
Bruno Roustant
8c738ba010
Reduce memory usage of field maps in FieldInfos and BlockTree TermsReader. (#13327) 2024-05-13 15:49:41 +02:00
Chris Hegarty
25f1efd8eb
Fix default flat vector scorer supplier sharing backing array (#13355)
This commit fixes an issue in the default flat vector scorer supplier whereby subsequent scorers created by the supplier can affect previously created scorers.

The issue is that we're sharing the backing array from the vector values, and overwriting it in subsequent scorers. We just need to use the ordinal to protect the scorer instance from mutation.
2024-05-10 21:49:13 +01:00
zhongshanhao
701c75a412
Advoid the use of ImpactsDISI when no minimum competitive score has been set (#13343)
Co-authored-by: zhongshanhao <zhongshanhao@bilibili.com>
2024-05-10 18:27:00 +02:00
Adrien Grand
3003731aa9
Add IndexInput#prefetch. (#13337)
This adds `IndexInput#prefetch`, which is an optional operation that instructs
the `IndexInput` to start fetching bytes from storage in the background. These
bytes will be picked up by follow-up calls to the `IndexInput#readXXX` methods.
In the future, this will help Lucene move from a maximum of one I/O operation
per search thread to one I/O operation per search thread per `IndexInput`.
Typically, when running a query on two terms, the I/O into the terms dictionary
is sequential today. In the future, we would ideally do these I/Os in parallel
using this new API. Note that this will require API changes to some classes
including `TermsEnum`.

I settled on this API because it's simple and wouldn't require making all
Lucene APIs asynchronous to take advantage of extra I/O concurrency, which I
worry would make the query evaluation logic too complicated.

This change will require follow-ups to start using this new API when working
with terms dictionaries, postings, etc.

Relates #13179

Co-authored-by: Uwe Schindler <uschindler@apache.org>
2024-05-10 13:42:35 +02:00
boice
5ac88c750e
Performance improvements to use RWLock to access LRUQueryCache (#13306)
Elasticsearch (which based on lucene) can automatically infer types for users with its dynamic mapping feature. When users index some low cardinality fields, such as gender / age / status... they often use some numbers to represent the values, while ES will infer these fields as long, and ES uses BKD as the index of long fields. 

Just as #541 said, when the data volume grows, building the result set of low-cardinality fields will make the CPU usage and load very high even if we use a boolean query with filter clauses for low-cardinality fields. 

One reason is that it uses a ReentrantLock to limit accessing LRUQueryCache. QPS and costs of their queries are often high,  which often causes trying locking failures when obtaining the cache, resulting in low concurrency in accessing the cache.

So I replace the ReentrantLock with a ReentrantReadWriteLock. I only use the read lock when I need to get the cache for a query,
2024-05-10 07:04:26 -04:00
Adrien Grand
f3a52113a4
Remove unused "implements Accountable". (#13330)
A number of file formats no longer implement `Accountable`. This allows
removing this interface on a number of internal classes as well.
2024-05-09 23:27:18 +02:00
Benjamin Trent
b60e86c4b9
Add new VectorScorer interface to vector value iterators (#13181)
With quantized vectors, and with current vectors, we separate out the "scoring" vs. "iteration", requiring the user to always iterate the raw vectors and provide their own similarity function.

While this is flexible, it creates frustration in:

 - Just iterating and scoring, especially since the field already has a similarity function stored...Why can't we just know which one to use and use it!
 - Iterating and scoring quantized vectors. By default it would be good to be able to iterate and score quantized vectors (e.g. without going through the HNSW graph).

This significantly hampers support for true exact kNN search.

This commit extends the vector value iterators to be able to return a scorer given some vector value (what this PR demonstrates). The scorer contains a copy of the originating iterator and allows for iteration and scoring the most optimized way the provided codec can give. 

Users can still iterate vector values directly, read them on heap, and score any way they please.
2024-05-09 16:30:14 -04:00
Chris Hegarty
8d7e4174af
Add a separate option to allow running Panama Vectorization for all tests with suitable C2 defaults (#13351)
This commit adds a separate option, tests.defaultvectorization, to allow running Panama Vectorization for all tests with suitable C2 defaults.

For example:

./gradlew :lucene:core:test -Ptests.defaultvectorization=true
---------

Co-authored-by: Uwe Schindler <uschindler@apache.org>
2024-05-09 11:00:51 +01:00
Nhat Nguyen
06973f5723
Harden BaseDocValuesFormatTestCase (#13346)
We hit a Codec bug in Elasticsearch, but it went unnoticed because our 
tests extend from BaseDocValuesFormatTestCase, which doesn't attempt to
read the doc-values of the same document twice. This change strengthens
BaseDocValuesFormatTestCase checks and randomly inserts that access
pattern.
2024-05-07 09:04:25 -07:00
Michael Sokolov
30da7dabe0
gh-13340: Allow adding a parent field to an index with no fields (#13341) 2024-05-06 12:53:13 -04:00
Stefan Vodita
40cae087f7 Move lazy init facets from 10.0 to 9.11 2024-05-03 08:18:29 +00:00
Adrien Grand
c3b0e05249
Make segment/field attribute updates thread-safe. (#13331)
Because of concurrent merging (#13124), multiple threads may be updating
(different) attributes concurrently, so we need to make reads and writes to
attributes thread-safe.
2024-05-02 18:31:12 +02:00
Benjamin Trent
07b37eea71
Add test case to ensure scalar quantization adheres to known ranges (#13336)
Lucene provides int7 & int4 quantization, we should ensure via our tests that the quantized values are within expected ranges.
2024-05-02 09:25:04 -04:00
Benjamin Trent
7d87a773fd
Fix TestHnswBitVectorsFormat.testIndexAndSearchBitVectors flakiness (#13333) 2024-05-02 07:58:22 -04:00
Benjamin Trent
e40e1086f5
Improve int4 compressed comparisons performance (#13321)
This updates the int4 dot-product comparison to have an optimized one for when one of the vectors are compressed (the most common search case). This change actually makes the compressed search on ARM faster than the uncompressed. However, on AVX512/256, it still slightly slower than uncompressed, but it still much faster now with this optimization than before (eagerly decompressing).

This optimized is tied tightly with how the vectors are actually compressed and stored, consequently, I added a new scorer that is within the lucene99 codec.

So, this gives us 8x reduction over float32, well more than 2x faster queries than float32, and no need to rerank as the recall and accuracy are excellent.
2024-05-01 10:05:51 -04:00
Uwe Schindler
e6dac3400d
Improve MissingDoclet linter to check records correctly (#13332)
Improve MissingDoclet linter to check records correctly:
- exclude default ctors
- exclude accessor methods (like with enums)
- on "method" level checking also check that every record component has an @param tag
2024-04-30 18:00:06 +02:00
Robert Muir
9af3ef8952
IndexWriter: Treat java.lang.Error as tragedy (#13277)
Background:
Historically IndexWriter treated OutOfMemoryError special, for defensive
reasons. It was expanded to VirtualMachineError, to try to play it safe
in similar disastrous circumstances.

We should treat any Error as a tragedy, as it isn't an Exception, and it
isn't something a "reasonable" application should catch. IndexWriter
should be reasonable. See #7049 for some of the reasoning.

We can't pretend this will detect any possible scenario that might cause
harm, e.g. a jvm bug might simply miscompile some code and cause silent
corruption. But we should try harder by playing by the rules.

Closes #13275
Closes #7049
2024-04-23 21:40:22 -04:00
zhouhui
fb12e09ab5
Narrow MASKS and UTF8Byte.value's type, assign MASKS by left shift in UTF32ToUTF8 (#13310)
* Change MASKS from int[] to byte[], and assign it with left shift.

* Only set first byte for tmpUTF8.

* Only set first byte value for tmp utf8.

* Change value type from int to byte.

* Remove stale comment.
2024-04-23 10:21:01 -04:00
zhouhui
3c8467d353
Remove unnecessary assert, fix comment. (#13279) 2024-04-23 10:11:59 -04:00
Shubham Chaudhary
d57267a0e6
Fix TestLucene90FieldInfosFormat.testRandom (#13135) 2024-04-22 09:40:40 +01:00
zhouhui
3024e66e4a
Use Arrays.compareUnsigned instead of iterating compare. (#13252) 2024-04-19 10:01:16 +02:00
Zhang Chao
1f1181a079
Do not use mock merge policy for TestSimilarity (#13314) 2024-04-18 09:50:40 +08:00
Zhang Chao
f665bd196e
Fix test failure TestKnnByteVectorQuery#testTimeLimitingKnnCollectorManager (#13312) 2024-04-18 09:48:11 +08:00
Benjamin Trent
3d86ff2e6a
Add BitVectors format and make flat vectors format easier to extend (#13288)
Instead of making a separate thing pluggable inside of the FieldFormat, this instead keeps the vector similarities as they are, but allows a custom scorer to be provided to the FlatVector storage used by HNSW. 

This idea is akin to the compression extensions we have. But in this case, its for vector scorers. 

To show how this would work in practice, I took the liberty of adding a new HnswBitVectorsFormat in the sandbox module.

A larger part of the change is a refactor of the `RandomAccessVectorValues<T>` to remove the `<T>`. Nothing actually uses that any longer, and we should instead rely on well defined classes and stop relying on casting with generics (yuck).
2024-04-17 13:13:51 -04:00
Vigya Sharma
bc678ac67e
Use jdk11 primitives in test to allow backport to branch_9x (#13311) 2024-04-16 23:17:43 -07:00
Benjamin Trent
3ba7ebbad8
Add more backwards compability tests for Scalar quantization (#13298)
This adds more backwards compatibility coverage for scalar quantization. Adding a test that forces the older metadata version to be written and ensures that it can still be read.
2024-04-16 09:08:30 -04:00
Sanjay Dutt
dcb512289f
Convert FieldEntry to record (#13296)
Co-authored-by: iamsanjay <sanjaydutt.india@yahoo.com>
2024-04-16 11:34:44 +02:00
Zhang Chao
dca87235be
Fix test failure TestDocumentsImpl.testGetDocumentFields (#13303) 2024-04-15 21:56:51 +08:00
Tim Grein
1c3c094227
Use Float.compare/Double.compare instead of '==' in geo classes (#13301)
when using == to compare the floats -0.0 and 0.0 they will be considered equal but their hashcode is different.
2024-04-15 21:54:33 +08:00
Mayya Sharipova
0345fcabb3
UnifiedHighlighter highlight on multiple fields (#13268)
Add ability to UnifiedHighlighter to combine matches from multiple fields
to highlight a single field.

FastVectorHighlighter for a long time has an option to highlight a single field
based on matches from several fields. But UnifiedHighlighter was missing this option.

This adds this ability with a new function: `UnifiedHighlighter::withMaskedFieldsFunc` 
that sets up a function that given a field retuns a set of masked fields whose matches 
are combined  to highlight the given field.
2024-04-12 06:36:25 -04:00
Adrien Grand
e19238a7bd
Increase the default number of merge threads. (#13294)
You need as many merge threads as necessary to make sure that merges can keep
up with indexing. But this number depends on the data that you are indexing: if
you are only indexing stored fields, merges can copy compressed data directly
and merges are only a small fraction of the total indexing+flushing+merging
cost. But if you primary index knn vectors, merging N docs may require about as
much work as flushing N docs. If you add the fact that documents typically go
through multiple rounds of merging, the merging cost can end up being more than
half of the total indexing+flushing+merging cost.

This change proposes to update the default number of merge threads assuming an
intermediate scenario where merges perform about half of the total
indexing+flushing+merging work, ie. it gives half the threads of the system to
merges.

One goal of this change is to no longer have to configure a custom number of
merge threads on nightly benchmarks, which run on a highly concurrent machine.
2024-04-11 21:21:28 +02:00
Adrien Grand
fbea47b4f4 Tidy 2024-04-11 21:16:42 +02:00
Adrien Grand
927f081fb0
Disable ConcurrentMergeScheduler's auto I/O throttling by default. (#13293)
This is motivated by the fact that merges can hardly steal all I/O resources
from searches on modern NVMe drives. Merges are still not allowed to use all
CPU since they have a budget for the number of threads which is a fraction of
the number of threads that the host can run.

Closes #13193
2024-04-11 18:42:54 +02:00
zhouhui
0016c79c46
Remove unnecessary calculating for termLen. (#13291) 2024-04-11 08:04:27 -04:00
Christine Poerschke
f44ded0c95
fix s/Long/Fixed in FixedBitSet javadocs (#13290) 2024-04-11 11:21:49 +01:00
Adrien Grand
c22c913063 Move MIGRATE entry to the correct section. 2024-04-11 10:47:26 +02:00