Commit Graph

36657 Commits

Author SHA1 Message Date
Patrick Zhai 51ade888f3 Update wrong PR number in CHANGES.txt 2023-09-19 23:37:36 -07:00
Patrick Zhai ac62c58d46 Update wrong PR number in CHANGES.txt 2023-09-19 23:29:53 -07:00
Patrick Zhai f5d5dc289e Update wrong PR number in CHANGES.txt 2023-09-19 23:24:17 -07:00
Patrick Zhai 94b879a593 Add next minor version 9.9.0 2023-09-19 22:54:14 -07:00
Tony-X ca69ae6d98
Make FSTPostingsFormat load FSTs off-heap (#12552)
* Make FSTPostingsFormat load FSTs off-heap
2023-09-19 16:29:23 -04:00
Benjamin Trent fe348de619
Fix HNSW graph reading with excessive connections (#12571)
When re-using the HNSW graph during segment merges, it is possible that more than the configured M*2 connections could be made per vector.

In those instances, we should allow the graph to still be read from the codec and searchable.
2023-09-19 15:38:23 -04:00
Adrien Grand 1d0edd76a5 Fix compilation under Java 11. 2023-09-19 12:15:38 +02:00
Adrien Grand 36432fa672
Fix issues with BP tests and the security manager. (#12568)
The default ForkJoinPool implementation uses a thread factory that removes all
permissions on threads, so we need to create our own to avoid tests failing
with FS-based directories.
2023-09-19 08:55:48 +02:00
Dawid Weiss ebfbc831ab
Omit -Ptests.haltonfailure=false in failed test repro line #12565 (#12566) 2023-09-18 14:30:53 +02:00
Dawid Weiss cba2d19efa
TestPassageSelector.randomizedSanityCheck can fail when the random input is unfortunately clashing with an assertion #12562 (#12567) 2023-09-18 12:30:01 +02:00
Egor Potemkin d633c9b7d4
Fix: Lucene90DocValuesProducer.TermsDict.seekCeil doesn't always position bytes correctly (#12555) 2023-09-16 16:48:45 -07:00
Greg Miller 43c0d72b94 Add more detailed documentation related to GH#12560 2023-09-16 14:51:53 -07:00
Greg Miller 58a50bf44d
Defer #advanceExact on expression dependencies until their values are needed (#12560) 2023-09-15 16:26:14 -07:00
Adrien Grand 780e684340 CHANGES for #12489. 2023-09-14 18:58:52 +02:00
Adrien Grand 39f3777886
Add support for recursive graph bisection. (#12489)
Recursive graph bisection is an extremely effective algorithm to reorder doc
IDs in a way that improves both storage and query efficiency by clustering
similar documents together. It usually performs better than other techniques
that try to achieve a similar goal such as sorting the index in natural order
(e.g. by URL) or by a min-hash, though it comes at a higher index-time cost.

The [original paper](https://arxiv.org/pdf/1602.08820.pdf) is good but I found
this [reproducibility study](http://engineering.nyu.edu/~suel/papers/bp-ecir19.pdf)
to describe the algorithm in more practical ways.
2023-09-14 18:20:45 +02:00
Gokul Manoj 8ca471679d
Allow FilteredDocIdSetIterator.match(doc) to throw IOException (#12554) 2023-09-14 17:40:18 +02:00
Adrien Grand 37a42219fc
Reduce the overhead of ImpactsDISI. (#12490)
`ImpactsDISI` is nice: you give it an `ImpactsEnum`, typically coming from the
`PostingsFormat` and it will automatically skip hits whose score cannot be
greater than the minimum competitive score. This is the class that yields 10x
or more speedups on top-level `TermQuery`s compared to exhaustive evaluation.

However, when nested under a disjunction or a conjunction, `ImpactsDISI`
typically adds more overhead than it enables skipping. The reason is that on a
disjunction `a OR b`, the minimum competitive score of `a` is the minimum score
for the disjunction minus the maximum score of `b`. While this sort of
propagation of minimum competitive scores down the query tree sometimes helps,
it does hurt more than it helps on average, because `ImpactsDISI` adds quite
some overhead and the per-clauses minimum scores are usually so low that they
don't actually enable skipping hits. I looked into reducing this overhead, but
a big part of it is the additional virtual call, so the only way to get rid of
this overhead is to not wrap with an `ImpactsDISI` at all.

This means that scorers need a way to know whether they are producing the
top-level score, or whether they are producing a partial score that then gets
combined into the top-level score. Term queries would then only wrap with
`ImpactsDISI` when they produce the top-level score. Note that this does not
only include top-level term queries, but also conjunctions that have a single
scoring clause (`a #b`) or combinations of a term query and one or more
prohibited clauses (`a -b`).
2023-09-12 15:23:28 +02:00
Jim Ferenczi c26b0180bd
Introduce a random vector scorer in HNSW builder/searcher (#12529)
This PR involves the refactoring of the HNSW builder and searcher, aiming to create an abstraction for the random access and vector comparisons conducted during graph traversal.

The newly added RandomVectorScorer provides a means to directly compare ordinals, eliminating the need to expose the raw vector primitive type.
This scorer takes charge of vector retrieval and comparison during the graph's construction and search processes.

The primary purpose of this abstraction is to enable the implementation of various strategies.
For example, it opens the door to constructing the graph using the original float vectors while performing searches using their quantized int8 vector counterparts.
2023-09-12 13:57:07 +01:00
Tony-X d77195d705
Document why we need `lastPosBlockOffset` (#12541)
* Document why we need `lastPosBlockOffset`

* Let ./gradlew tidy fix the formatting

* Fix '<' with &lt;

---------

Co-authored-by: Tony Xu <tonyx@amazon.com>
2023-09-12 07:32:58 -04:00
Michael McCandless 57dd5a4bda
The bitsRequired passed during NodeHash rehash (when building an FST) (#12545) 2023-09-09 19:14:18 -04:00
Luca Cavanna a7202e2e6f
Close index readers in tests (#12544)
There are a few places where tests don't close index readers. This has
not caused problems so far, but it becomes an issue when the reader gets
an executor, because its shutdown happens as a closing listener of the
reader. This has become more evident since we now offload sequential
execution to the executor. If there's an executor, but it's never used,
no threads are created, and no threads are leaked. If we do use the
executor, and the reader is not closed, the test leaks threads.
2023-09-08 14:55:01 +02:00
Christine Poerschke ef42af65f2
clarify QueryVisitor.acceptField javadoc w.r.t. not being term-specific (#12540) 2023-09-06 11:18:46 +01:00
Luca Cavanna d62ca4a01f add missing changelog entry for #12498 2023-09-05 16:41:38 +02:00
Luca Cavanna da894151a6
Offload single slice to executor (#12515)
When an executor is set to the IndexSearcher, we should try and offload
most of the computation to such executor. Ideally, the caller thread
would only do light coordination work, and the executor is responsible
for the heavier workload. If we don't offload sequential execution to
the executor, it becomes very difficult to make any distinction about
the type of workload performed on the two sides.

Closes #12498
2023-09-05 16:30:20 +02:00
Luca Cavanna 947b2c5e5a
Unwrap execution exceptions cause and rethrow as is when possible (#12516)
When performing concurrent search, we may get an execution exception
from one or more slices. In that case, we'd like to rethrow the cause of
the execution exception, which we do by wrapping it into a new runtime
exception. Instead, we can rethrow runtime exceptions as-is, and the
same is true for io exceptions. Any other exception is still wrapped
into a new runtime exception. This unifies the exceptions that get
thrown between sequential codepath (when no executor is provided) and
concurrent codepath (when an executor is provided).
2023-09-05 15:55:48 +02:00
Chaitanya Gohel d631615665
Honor topvalue while determining isMissingvalueCompetitive in case bottom is not set (#12520) 2023-09-04 18:25:34 +02:00
zhangchao a52161b131
Update outdated comment about maxPointsInLeafNode in BKD tree (#12532) 2023-09-04 14:37:16 +02:00
Jack Wang 9fd45e3951
Enhancement 11236 lazy compute similarity score (#12480) 2023-09-01 11:05:49 -07:00
Benjamin Trent d1c3531161
Use panama vector for l2normalize (#12518)
Use panama vector for l2normalize
2023-08-29 08:33:49 -04:00
zhangchao 16e4874bb9
Remove unused variable in BKDWriter (#12512) 2023-08-22 15:50:47 +08:00
Luca Cavanna bb62720526
Simplify task executor for concurrent operations (#12499)
This commit removes the QueueSizeBasedExecutor (package private) in favour of simply offloading concurrent execution to the provided executor. In need of specific behaviour, it can all be included in the executor itself.

This removes an instanceof check that determines which type of executor wrapper is used, which means that some tasks may be executed on the caller thread depending on queue size, whenever a rejection happens, or always for the last slice. This behaviour is not configurable in any way, and is too rigid. Rather than making this pluggable, I propose to make Lucene less opinionated about concurrent tasks execution and require that users include their own execution strategy directly in the executor that they provide to the index searcher.

Relates to #12498
2023-08-21 21:54:37 +02:00
Jakub Slowinski fb8183332b
Fix stack overflow in RegExp for long string (#12462) 2023-08-16 22:45:20 -07:00
Shubham Chaudhary 368dbffef3
Replace consecutive close() calls and close() calls with null checks with IOUtils.close() (#12428) 2023-08-16 17:12:34 -07:00
tang donghai ec1367862d
Fix UTF32toUTF8 will produce invalid transition (#12472) 2023-08-16 13:59:07 -07:00
Benjamin Trent 4174b521dd
Rename ToParentBlockJoin[Byte|Float]KnnVectorQuery and adjust to return highest score child doc ID by parent id (#12510)
The current query is returning parent-id's based off of the nearest child-id score. However, its difficult to invert that relationship (meaning determining what exactly the nearest child was during search).

So, I changed the new `ToParentBlockJoin[Byte|Float]KnnVectorQuery` to `DiversifyingChildren[Byte|Float]KnnVectorQuery` and now it returns the nearest child-id instead of just that child's parent id. The results are still diversified by parent-id.

Now its easy to determine the nearest child vector as that is what the query is returning. To determine its parent, its as simple as using the previously provided parent bit set.

Related to: https://github.com/apache/lucene/pull/12434
2023-08-16 13:44:49 -04:00
Benjamin Trent 5a5aa2c8fa
GITHUB#12342 Add new maximum inner product vector similarity method (#12479)
The current dot-product score scaling and similarity implementation assumes normalized vectors. This disregards information that the model may store within the magnitude. 

See: https://github.com/apache/lucene/issues/12342#issuecomment-1658640222 for a good explanation for the need.

To prevent from breaking current scoring assumptions in Lucene, a new `MAXIMUM_INNER_PRODUCT` similarity function is added. 

Because the similarity from a `dotProduct` function call could be negative, this similarity scorer will scale negative dotProducts to between 0-1 and then all positive dotProduct values are from 1-MAX.

One concern with adding this similarity function is that it breaks the triangle inequality. It is assumed that this is needed to build graph structures. But, there is conflicting research here when it comes to real-world data.

See:
 - For: https://github.com/apache/lucene/issues/12342#issuecomment-1618258984
 - Against: https://github.com/apache/lucene/issues/12342#issuecomment-1631577657, https://github.com/apache/lucene/issues/12342#issuecomment-1631808301

To check if any transformation of the input is required to satisfy the triangle inequality, many tests have been ran

See:

 - https://github.com/apache/lucene/issues/12342#issuecomment-1653420640
 - https://github.com/apache/lucene/issues/12342#issuecomment-1656112434
 - https://github.com/apache/lucene/issues/12342#issuecomment-1656718447

If there are any additional tests, or issues with the provided tests & scripts, please let me know. We want to make sure this works well for our users.

closes: https://github.com/apache/lucene/issues/12342
2023-08-16 12:15:25 -04:00
Lu Xugang 71f6f59a75
Remove outdated comment in Scorer (#12494)
we should delete this comment since this constructor parameters already removed from LUCENE-2876 , it's description of 'given Similarity' is a lit bit confuse to reader.

Scorer always provide non-negative
2023-08-16 11:36:20 +08:00
Benjamin Trent 18b56bd002
ToParentBlockJoin[Byte|Float]KnnVectorQuery needs to handle the case when parents are missing (#12504)
This is a follow up to: https://github.com/apache/lucene/pull/12434

Adds a test for when parents are missing in the index and verifies we return no hits. Previously this would have thrown an NPE
2023-08-14 09:24:25 -04:00
Adrien Grand 47258cc9e9 Move changes of #12415 to 9.8 2023-08-11 22:39:36 +02:00
Adrien Grand 4d26cb2219
Optimize disjunction counts. (#12415)
This introduces `LeafCollector#collect(DocIdStream)` to enable collectors to
collect batches of doc IDs at once. `BooleanScorer` takes advantage of this by
creating a `DocIdStream` whose `count()` method counts the number of bits that
are set in the bit set of matches in the current window, instead of naively
iterating over all matches.

On wikimedium10m, this yields a ~20% speedup when counting hits for the `title
OR 12` query (2.9M hits).

Relates #12358
2023-08-11 22:37:37 +02:00
Benjamin Trent df8745e59e
Fix flaky testToString method for Knn Vector queries (#12500)
Periodically, the random indexer will force merge on close, this means that what was originally indexed as the zeroth document could no longer be the zeroth document.

This commit adjusts the assertion to ensure the to string format is as expected for `DocAndScoreQuery`, regardless of the matching doc-id in the test.

This seed shows the issue:
```
./gradlew test --tests TestKnnByteVectorQuery.testToString -Dtests.seed=B78CDB966F4B8FC5
```
2023-08-11 07:26:49 -04:00
Peter Gromov 13e747f95f
hunspell: simplify TrigramAutomaton to speed up the suggestion enumeration (#12491)
* hunspell: simplify TrigramAutomaton to speed up the suggestion enumeration

avoid the automaton access on definitely absent characters;
count the scores for all substring lengths together
2023-08-08 22:40:42 +02:00
Benjamin Trent dd4e66dad6
Fix test failure with zero-length vector (#12493)
This adds assertions around the random test vector dimension count and continues to generate random vectors until it has a `squareSum > 0`
2023-08-08 08:38:46 -04:00
Benjamin Trent a65cf8960a
Add ParentJoin KNN support (#12434)
A `join` within Lucene is built by adding child-docs and parent-docs in order. Since our vector field already supports sparse indexing, it should be able to support parent join indexing. 

However, when searching for the closest `k`, it is still the k nearest children vectors with no way to join back to the parent.

This commit adds this ability through some significant changes:
 - New leaf reader function that allows a collector for knn results
 - The knn results can then utilize bit-sets to join back to the parent id
 
This type of support is critical for nearest passage retrieval over larger documents. Generally, you want the top-k documents and knowledge of the nearest passages over each top-k document. Lucene's join functionality is a nice fit for this.

This does not replace the need for multi-valued vectors, which is important for other ranking methods (e.g. colbert token embeddings). But, it could be used in the case when metadata about the passage embedding must be stored (e.g. the related passage).
2023-08-07 14:46:42 -04:00
Adrien Grand 03ab02157a Revert "Stop aligning windows in BooleanScorer. (#12488)"
This reverts commit 09e3b43331.
2023-08-06 22:10:09 +02:00
Adrien Grand 09e3b43331
Stop aligning windows in BooleanScorer. (#12488)
BooleanScorer aligns windows to multiples of 2048, but it doesn't have to.
Actually, not aligning windows can help evaluate fewer windows overall and
speed up query evaluation.
2023-08-05 11:29:34 +02:00
Adrien Grand df3632cb03
Fix `DefaultBulkScorer` to not advance the competitive iterator beyond the end of the window. (#12481)
The way `DefaultBulkScorer` uses `ConjunctionDISI` may make it advance the
competitive iterator beyond the end of the window. This may cause bugs with
bulk scorers such as `BooleanScorer` that sometimes delegate to the single
clause that has matches in a given window of doc IDs. We should then make sure
to not advance the competitive iterator beyond the end of the window based on
this clause, as other clauses may have matches as well.
2023-08-03 07:19:27 +02:00
Adrien Grand acffcfaaf0
Reduce overhead of disabling scoring on `BooleanScorer`. (#12475)
This is a subset of #12415, which I'm extracting to its own pull request in
order to have separate data points in nightly benchmarks.

Results on `wikimedium10m` and `wikinightly` counting tasks:

```
                       CountTerm     4624.91      (6.4%)     4581.34      (6.4%)   -0.9% ( -12% -   12%) 0.640
                 CountAndHighMed      280.03      (4.5%)      280.15      (4.4%)    0.0% (  -8% -    9%) 0.974
                     CountPhrase        7.22      (3.0%)        7.24      (1.8%)    0.3% (  -4% -    5%) 0.728
                CountAndHighHigh       52.84      (4.9%)       53.12      (5.6%)    0.5% (  -9% -   11%) 0.755
                        PKLookup      232.01      (3.6%)      235.45      (2.8%)    1.5% (  -4% -    8%) 0.144
                 CountOrHighHigh       42.37      (6.1%)       56.04      (9.1%)   32.3% (  16% -   50%) 0.000
                  CountOrHighMed       30.56      (6.5%)       40.46      (9.8%)   32.4% (  15% -   52%) 0.000
```
2023-08-03 07:17:52 +02:00
Armin Braun e78feb7809
Clenup duplication in BKDWriter (#12469)
The logic for creating the writer runnable could be deduplicated.
Also, a couple of annonymous classes could be turned into lambdas.
2023-08-03 07:16:44 +02:00
Benjamin Trent 229dc7481e
Fix randomly failing field info format tests (#12473) 2023-08-02 14:10:57 -04:00