-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove vector values copy() methods, moving IndexInput.clone() and temp storage into lower-level interfaces #13872
Open
msokolov
wants to merge
27
commits into
apache:main
Choose a base branch
from
msokolov:knn-dictionary
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
0b76ac3
refactor float vector values random access
1c2977f
refactor byte vector values random access
debac32
make sure KnnVectorValues.iterator() always returns a new value
273e8ed
fix cloning/sharing of vector scorer resources
ce70f4c
renaming
b4febca
tidy
2fca27c
more renaming
2e51380
EMPTY
3b8d70f
CHANGES and MIGRATE entries
f5e0260
a little more renaming
9c68a6e
mopping up some more values->vectors
f035183
fix javadoc
23c7497
fix error introduced in refactoring (init lastSubIndex to -1 instead …
63a4d83
Add BaseKnnVectorsFormatTestCase.testRecall() and fix map ord to doc …
2099589
Add BaseKnnVectorsFormatTestCase.testRecall() and fix map ord to doc …
6141900
handle stray prints
61a0d79
test all similarities and more queries
5a6d709
fix Lucene90Hnsw that was aliasing vector values
bbe4d28
remove stray print
1a2c3bb
Merge remote-tracking branch 'origin/main' into knn-dictionary
568372f
fix initialization bug in SlowCompositeCodecReaderWrapper
da06288
simplifications from PR feedback
ed233ba
fix off-heap scorer by falling back to on-heap.
ChrisHegarty 5c2cb2d
Merge branch 'main' into knn-dictionary
ChrisHegarty 4284360
fix aliasing of vector scratch in quantized scorer
f1e0007
update flat vectors scorer to use only two vector dictionaries
ChrisHegarty ef13bad
reuse Floats and RandomVectorScorers
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ public abstract class FloatVectorValues extends KnnVectorValues { | |
protected FloatVectorValues() {} | ||
|
||
/** A random access (lookup by ord) provider of the vector values */ | ||
public abstract static class Floats { | ||
public abstract static class Floats implements AutoCloseable { | ||
/** | ||
* Return the vector value for the given vector ordinal which must be in [0, size() - 1], | ||
* otherwise IndexOutOfBoundsException is thrown. The returned array may be shared across calls. | ||
|
@@ -42,6 +42,11 @@ public abstract static class Floats { | |
*/ | ||
public abstract float[] get(int ord) throws IOException; | ||
|
||
@Override | ||
public void close() throws IOException { | ||
// by default do nothing. Some implementations do more interesting resource management. | ||
} | ||
|
||
/** A Floats containing no vectors. Throws UnsupportedOperationException if get() is called. */ | ||
public static final Floats EMPTY = | ||
new Floats() { | ||
|
@@ -118,6 +123,9 @@ public Floats vectors() { | |
public float[] get(int ord) throws IOException { | ||
return vectors.get(ord); | ||
} | ||
|
||
@Override | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops this is redundant |
||
public void close() {} | ||
}; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.lucene.util.hnsw; | ||
|
||
/** | ||
* A collection of objects that is threadsafe, providing offer(T) that tries to add an element and | ||
* poll() that removes and returns an element or null. The storage will never grow. There are no | ||
* guarantees about which object will be returned from poll(), just that it will be one that was | ||
* added by offer(). | ||
*/ | ||
public class Bag<T> { | ||
private static final int DEFAULT_CAPACITY = 64; | ||
|
||
private final Object[] elements; | ||
private int writeTo; | ||
private int readFrom; | ||
|
||
public Bag() { | ||
this(DEFAULT_CAPACITY); | ||
} | ||
|
||
public Bag(int capacity) { | ||
elements = new Object[capacity]; | ||
} | ||
|
||
public synchronized boolean offer(T element) { | ||
if (full()) { | ||
return false; | ||
} | ||
elements[writeTo] = element; | ||
writeTo = (writeTo + 1) % elements.length; | ||
return true; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public synchronized T poll() { | ||
if (empty()) { | ||
return null; | ||
} | ||
T result = (T) elements[readFrom]; | ||
readFrom = (readFrom + 1) % elements.length; | ||
return result; | ||
} | ||
|
||
private boolean full() { | ||
int headroom = readFrom - 1 - writeTo; | ||
if (headroom < 0) { | ||
headroom += elements.length; | ||
} | ||
return headroom == 0; | ||
} | ||
|
||
private boolean empty() { | ||
return readFrom == writeTo; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these changes to the quantized reader/writer might be needed, but not just for the Floats case