You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2022/07/30 22:42:33 UTC
[GitHub] [lucene] msokolov opened a new pull request, #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
msokolov opened a new pull request, #1054:
URL: https://github.com/apache/lucene/pull/1054
I made a new PR because there was so much merging required after 9.3 release and switching this to 9.4. Other changes since the previous version:
1. byte-formatted vectors are now exposed in the Field api again
2. byte-based comparisons are done in VectorSimilarityFunction instead of being special-cased
3. I moved VectorEncoding from o.a.l.util.hnsw to o.a.l.index package since it needs to be supported by any vector codec
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] msokolov commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
msokolov commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r949249778
##########
lucene/core/src/java/org/apache/lucene/codecs/KnnVectorsFormat.java:
##########
@@ -76,6 +78,15 @@ public static KnnVectorsFormat forName(String name) {
/** Returns a {@link KnnVectorsReader} to read the vectors from the index. */
public abstract KnnVectorsReader fieldsReader(SegmentReadState state) throws IOException;
+ /**
+ * Returns the current KnnVectorsFormat version number. Indexes written using the format will be
+ * "stamped" with this version.
+ */
+ public int currentVersion() {
Review Comment:
I agree this is messy -- are you suggesting the codec would provide a `randomVectorEncoding` method? Or is there some other way of detecting the Codec version?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] msokolov commented on pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
msokolov commented on PR #1054:
URL: https://github.com/apache/lucene/pull/1054#issuecomment-1201912373
OK - I pushed a commit which actually adds the byte encoding to the whole Fields API - I had missed a few bits there :) So I think this is complete, but I still need to do some end-to-end testing
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] msokolov commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
msokolov commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r939722013
##########
lucene/core/src/test/org/apache/lucene/util/hnsw/KnnGraphTester.java:
##########
@@ -248,7 +269,9 @@ private void run(String... args) throws Exception {
if (docVectorsPath == null) {
throw new IllegalArgumentException("missing -docs arg");
}
- matchDocs = generateRandomBitSet(numDocs, selectivity);
+ if (prefilter) {
Review Comment:
ah, I see thanks. So I guess we must do this if selectivity < 1?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] msokolov commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
msokolov commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r949250783
##########
lucene/core/src/java/org/apache/lucene/search/KnnVectorQuery.java:
##########
@@ -133,22 +130,21 @@ private TopDocs searchLeaf(LeafReaderContext ctx, Weight filterWeight) throws IO
return NO_RESULTS;
}
- BitSet bitSet = createBitSet(scorer.iterator(), liveDocs, maxDoc);
- BitSetIterator filterIterator = new BitSetIterator(bitSet, bitSet.cardinality());
+ BitSet acceptDocs = createBitSet(scorer.iterator(), liveDocs, maxDoc);
- if (filterIterator.cost() <= k) {
+ if (acceptDocs.cardinality() <= k) {
Review Comment:
OK I missed this point, sorry. I'm open to re-refactoring :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] msokolov commented on pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
msokolov commented on PR #1054:
URL: https://github.com/apache/lucene/pull/1054#issuecomment-1201127574
ehh - I missed adding bytes-suport to KnnVectorField; will follow up
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] jtibshirani commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
jtibshirani commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r950631270
##########
lucene/core/src/java/org/apache/lucene/util/VectorUtil.java:
##########
@@ -213,4 +243,48 @@ public static void add(float[] u, float[] v) {
u[i] += v[i];
}
}
+
+ /**
+ * Dot product computed over signed bytes.
+ *
+ * @param a bytes containing a vector
+ * @param b bytes containing another vector, of the same dimension
+ * @return the value of the dot product of the two vectors
+ */
+ public static float dotProduct(BytesRef a, BytesRef b) {
+ assert a.length == b.length;
+ int total = 0;
+ int aOffset = a.offset, bOffset = b.offset;
+ for (int i = 0; i < a.length; i++) {
+ total += a.bytes[aOffset++] * b.bytes[bOffset++];
+ }
+ return total;
+ }
+
+ /**
+ * Dot product score computed over signed bytes, scaled to be in [0, 1].
+ *
+ * @param a bytes containing a vector
+ * @param b bytes containing another vector, of the same dimension
+ * @return the value of the similarity function applied to the two vectors
+ */
+ public static float dotProductScore(BytesRef a, BytesRef b) {
+ // divide by 2 * 2^14 (maximum absolute value of product of 2 signed bytes) * len
+ return (1 + dotProduct(a, b)) / (float) (a.length * (1 << 15));
+ }
+
+ /**
+ * Convert a floating point vector to an array of bytes using casting; the vector values should be
+ * in [-128,127]
+ *
+ * @param vector a vector
+ * @return a new BytesRef containing the vector's values cast to byte.
+ */
+ public static BytesRef toBytesRef(float[] vector) {
Review Comment:
Then maybe we could do a check in `Lucene94HnswVectorsReader`? The main thing I had in mind was if a user accidentally provides a query where the elements don't fall in the range [-128, 127]. We would silently cast the floats to bytes, which could result in incorrect search results.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] msokolov commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
msokolov commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r950423184
##########
lucene/core/src/java/org/apache/lucene/search/KnnVectorQuery.java:
##########
@@ -133,22 +130,21 @@ private TopDocs searchLeaf(LeafReaderContext ctx, Weight filterWeight) throws IO
return NO_RESULTS;
}
- BitSet bitSet = createBitSet(scorer.iterator(), liveDocs, maxDoc);
- BitSetIterator filterIterator = new BitSetIterator(bitSet, bitSet.cardinality());
+ BitSet acceptDocs = createBitSet(scorer.iterator(), liveDocs, maxDoc);
- if (filterIterator.cost() <= k) {
+ if (acceptDocs.cardinality() <= k) {
Review Comment:
I think what bothered me was that we were creating a `BitSetIterator` even when we didn't use it, except as a holder for the cost, which also we had to cast. How's this? https://github.com/apache/lucene/pull/1075
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] msokolov commented on pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
msokolov commented on PR #1054:
URL: https://github.com/apache/lucene/pull/1054#issuecomment-1220873853
Thanks so much for the review @jtibshirani -- I will post some PRs with fixes today, although I may not be able to address everything you raised
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] kaivalnp commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
kaivalnp commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r940501321
##########
lucene/core/src/test/org/apache/lucene/util/hnsw/KnnGraphTester.java:
##########
@@ -248,7 +269,9 @@ private void run(String... args) throws Exception {
if (docVectorsPath == null) {
throw new IllegalArgumentException("missing -docs arg");
}
- matchDocs = generateRandomBitSet(numDocs, selectivity);
+ if (prefilter) {
Review Comment:
Sounds good!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] msokolov commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
msokolov commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r950503788
##########
lucene/core/src/java/org/apache/lucene/document/KnnVectorField.java:
##########
@@ -117,6 +160,21 @@ public KnnVectorField(String name, float[] vector, FieldType fieldType) {
fieldsData = vector;
}
+ /**
+ * Creates a numeric vector field. Fields are single-valued: each document has either one value or
+ * no value. Vectors of a single field share the same dimension and similarity function.
+ *
+ * @param name field name
+ * @param vector value
+ * @param fieldType field type
+ * @throws IllegalArgumentException if any parameter is null, or the vector is empty or has
+ * dimension > 1024.
+ */
+ public KnnVectorField(String name, BytesRef vector, FieldType fieldType) {
Review Comment:
https://github.com/apache/lucene/pull/1076 for this; also addreses the javadoc comment below and fixes a bug
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] jtibshirani commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
jtibshirani commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r950624287
##########
lucene/core/src/java/org/apache/lucene/search/KnnVectorQuery.java:
##########
@@ -133,22 +130,21 @@ private TopDocs searchLeaf(LeafReaderContext ctx, Weight filterWeight) throws IO
return NO_RESULTS;
}
- BitSet bitSet = createBitSet(scorer.iterator(), liveDocs, maxDoc);
- BitSetIterator filterIterator = new BitSetIterator(bitSet, bitSet.cardinality());
+ BitSet acceptDocs = createBitSet(scorer.iterator(), liveDocs, maxDoc);
- if (filterIterator.cost() <= k) {
+ if (acceptDocs.cardinality() <= k) {
Review Comment:
That approach works for me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] msokolov commented on pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
msokolov commented on PR #1054:
URL: https://github.com/apache/lucene/pull/1054#issuecomment-1207262818
I made the needed changes to KnnGraphTester and ran several tests with different datasets. I believe this version of the PR addresses all the previous comments, and I'd like to move ahead and commit this to main branch soon with a fast follow backport to 9.x.
Re tests:The "electronics" dataset is a proprietary set of vectors; the GloVe data set is open source. I rescaled the GloVe data and converted to bytes by multiplying each sample by 400 and then clipping to [-128,127].
The results are reasonable; roughly a 10% decrease in indexing times, and similar or a bit smaller reduction in query times in most cases. In a few cases the reduction is much more - eg in `GloVe-M=100-beamWidth=400`. It seems that in this case the index based on 8-bit vectors fit in a single segment, while the baseline index was spread across two segments. Generally the quantized indexes are smaller. The amount of reduction depends a lot on: (1) the dimension of the vectors and (2) the number of graph arcs per document. Basically the more of the index is taken up by the vector data (.vec file) the greater the reduction in size.
## baseline electronics (256 dim)
|recall| latency| nDoc| fanout| maxConn| beamWidth| visited| index ms|
|---|---|---|---|---|---|---|---|
|0.932| 0.37| 10000| 0| 16| 32| 100| 1497|
|0.962| 0.48| 10000| 50| 16| 32| 150| 0|
|0.959| 0.44| 10000| 0| 16| 64| 100| 2666|
|0.980| 0.57| 10000| 50| 16| 64| 150| 0|
|0.940| 0.40| 10000| 0| 32| 32| 100| 1465|
|0.968| 0.51| 10000| 50| 32| 32| 150| 0|
|0.966| 0.46| 10000| 0| 32| 64| 100| 2602|
|0.984| 0.61| 10000| 50| 32| 64| 150| 0|
|0.901| 0.55| 100000| 0| 16| 32| 100| 21830|
|0.933| 0.71| 100000| 50| 16| 32| 150| 0|
|0.938| 0.63| 100000| 0| 16| 64| 100| 41997|
|0.963| 0.82| 100000| 50| 16| 64| 150| 0|
|0.915| 0.57| 100000| 0| 32| 32| 100| 22212|
|0.949| 0.80| 100000| 50| 32| 32| 150| 0|
|0.952| 0.71| 100000| 0| 32| 64| 100| 45915|
|0.973| 0.99| 100000| 50| 32| 64| 150| 0|
|0.853| 0.71| 1000000| 0| 16| 32| 100| 337099|
|0.894| 0.92| 1000000| 50| 16| 32| 150| 0|
|0.910| 0.84| 1000000| 0| 16| 64| 100| 626227|
|0.939| 1.08| 1000000| 50| 16| 64| 150| 0|
|0.871| 0.85| 1000000| 0| 32| 32| 100| 372921|
|0.910| 1.04| 1000000| 50| 32| 32| 150| 0|
|0.928| 1.00| 1000000| 0| 32| 64| 100| 713421|
|0.956| 1.30| 1000000| 50| 32| 64| 150| 0|
## electronics 256 quantized bytes
|recall| latency| nDoc| fanout| maxConn| beamWidth| visited| index ms|
|---|---|---|---|---|---|---|---|
|0.932| 0.40| 10000| 0| 16| 32| 100| 1653|
|0.961| 0.51| 10000| 50| 16| 32| 150| 0|
|0.959| 0.45| 10000| 0| 16| 64| 100| 2992|
|0.979| 0.58| 10000| 50| 16| 64| 150| 0|
|0.940| 0.40| 10000| 0| 32| 32| 100| 1543|
|0.968| 0.54| 10000| 50| 32| 32| 150| 0|
|0.966| 0.51| 10000| 0| 32| 64| 100| 2928|
|0.984| 0.62| 10000| 50| 32| 64| 150| 0|
|0.901| 0.50| 100000| 0| 16| 32| 100| 22502|
|0.935| 0.69| 100000| 50| 16| 32| 150| 0|
|0.938| 0.64| 100000| 0| 16| 64| 100| 40918|
|0.963| 0.81| 100000| 50| 16| 64| 150| 0|
|0.916| 0.56| 100000| 0| 32| 32| 100| 23693|
|0.948| 0.77| 100000| 50| 32| 32| 150| 0|
|0.952| 0.73| 100000| 0| 32| 64| 100| 43528|
|0.973| 0.92| 100000| 50| 32| 64| 150| 0|
|0.854| 0.61| 1000000| 0| 16| 32| 100| 324533|
|0.894| 0.80| 1000000| 50| 16| 32| 150| 0|
|0.907| 0.71| 1000000| 0| 16| 64| 100| 575319|
|0.937| 0.93| 1000000| 50| 16| 64| 150| 0|
|0.872| 0.65| 1000000| 0| 32| 32| 100| 341945|
|0.909| 0.88| 1000000| 50| 32| 32| 150| 0|
|0.929| 0.87| 1000000| 0| 32| 64| 100| 645656|
|0.957| 1.10| 1000000| 50| 32| 64| 150| 0|
## Glove 100 baseline
|recall| latency| nDoc| fanout| maxConn| beamWidth| visited| index ms|
|---|---|---|---|---|---|---|---|
|0.963| 0.65| 10000| 0| 100| 200| 100| 7189|
|0.993| 0.99| 10000| 100| 100| 200| 200| 0|
|0.973| 0.71| 10000| 0| 100| 400| 100| 11174|
|0.996| 1.08| 10000| 100| 100| 400| 200| 0|
|0.963| 0.67| 10000| 0| 200| 200| 100| 7634|
|0.993| 0.98| 10000| 100| 200| 200| 200| 0|
|0.972| 0.73| 10000| 0| 200| 400| 100| 11347|
|0.996| 1.09| 10000| 100| 200| 400| 200| 0|
|0.887| 1.47| 100000| 0| 100| 200| 100| 215773|
|0.952| 2.44| 100000| 100| 100| 200| 200| 0|
|0.918| 1.80| 100000| 0| 100| 400| 100| 424821|
|0.972| 3.09| 100000| 100| 100| 400| 200| 0|
|0.887| 1.46| 100000| 0| 200| 200| 100| 208859|
|0.952| 2.55| 100000| 100| 200| 200| 200| 0|
|0.918| 1.83| 100000| 0| 200| 400| 100| 430869|
|0.972| 3.09| 100000| 100| 200| 400| 200| 0|
|0.824| 3.15| 1000000| 0| 100| 200| 100| 3946321|
|0.893| 5.18| 1000000| 100| 100| 200| 200| 0|
|0.859| 3.61| 1000000| 0| 100| 400| 100| 9402514|
|0.923| 6.27| 1000000| 100| 100| 400| 200| 0|
|0.874| 3.86| 1000000| 0| 200| 200| 100| 3413582|
|0.932| 6.88| 1000000| 100| 200| 200| 200| 0|
|0.904| 4.95| 1000000| 0| 200| 400| 100| 7758411|
|0.957| 8.66| 1000000| 100| 200| 400| 200| 0|
## Glove 100 byte quantized
|recall| latency| nDoc| fanout| maxConn| beamWidth| visited| index ms|
|---|---|---|---|---|---|---|---|
|0.962| 0.70| 10000| 0| 100| 200| 100| 8259|
|0.993| 1.06| 10000| 100| 100| 200| 200| 0|
|0.973| 0.74| 10000| 0| 100| 400| 100| 12799|
|0.996| 1.15| 10000| 100| 100| 400| 200| 0|
|0.962| 0.66| 10000| 0| 200| 200| 100| 8331|
|0.993| 1.07| 10000| 100| 200| 200| 200| 0|
|0.973| 0.75| 10000| 0| 200| 400| 100| 12497|
|0.996| 1.15| 10000| 100| 200| 400| 200| 0|
|0.887| 1.32| 100000| 0| 100| 200| 100| 169558|
|0.952| 2.08| 100000| 100| 100| 200| 200| 0|
|0.917| 1.51| 100000| 0| 100| 400| 100| 363433|
|0.972| 2.74| 100000| 100| 100| 400| 200| 0|
|0.887| 1.24| 100000| 0| 200| 200| 100| 174706|
|0.952| 2.12| 100000| 100| 200| 200| 200| 0|
|0.917| 1.51| 100000| 0| 200| 400| 100| 366009|
|0.972| 2.70| 100000| 100| 200| 400| 200| 0|
|0.820| 1.85| 1000000| 0| 100| 200| 100| 3681623|
|0.891| 3.37| 1000000| 100| 100| 200| 200| 0|
|0.856| 2.48| 1000000| 0| 100| 400| 100| 8957531|
|0.921| 4.37| 1000000| 100| 100| 400| 200| 0|
|0.873| 3.66| 1000000| 0| 200| 200| 100| 3041750|
|0.932| 6.57| 1000000| 100| 200| 200| 200| 0|
|0.905| 4.75| 1000000| 0| 200| 400| 100| 7676780|
|0.957| 8.66| 1000000| 100| 200| 400| 200| 0|
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] msokolov commented on pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
msokolov commented on PR #1054:
URL: https://github.com/apache/lucene/pull/1054#issuecomment-1209274547
I'll push to main later today if I don't see any further discussion, and let it percolate for a bit before backporting to 9.x
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] jtibshirani commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
jtibshirani commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r950631408
##########
lucene/core/src/java/org/apache/lucene/codecs/KnnFieldVectorsWriter.java:
##########
@@ -20,8 +20,12 @@
import java.io.IOException;
import org.apache.lucene.util.Accountable;
-/** Vectors' writer for a field */
-public abstract class KnnFieldVectorsWriter implements Accountable {
+/**
+ * Vectors' writer for a field
+ *
+ * @param <T> an array type; the type of vectors to be written
+ */
+public abstract class KnnFieldVectorsWriter<T> implements Accountable {
Review Comment:
Oh okay, I must have missed those objections from an earlier PR draft. I understand and appreciate your "progress over perfection" approach here. I've been trying out refactorings so I could suggest cleaner ways forward, but nothing has stuck so far... I'll continue to chip away at it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] msokolov commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
msokolov commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r949256714
##########
lucene/core/src/java/org/apache/lucene/util/VectorUtil.java:
##########
@@ -213,4 +243,48 @@ public static void add(float[] u, float[] v) {
u[i] += v[i];
}
}
+
+ /**
+ * Dot product computed over signed bytes.
+ *
+ * @param a bytes containing a vector
+ * @param b bytes containing another vector, of the same dimension
+ * @return the value of the dot product of the two vectors
+ */
+ public static float dotProduct(BytesRef a, BytesRef b) {
+ assert a.length == b.length;
+ int total = 0;
+ int aOffset = a.offset, bOffset = b.offset;
+ for (int i = 0; i < a.length; i++) {
+ total += a.bytes[aOffset++] * b.bytes[bOffset++];
+ }
+ return total;
+ }
+
+ /**
+ * Dot product score computed over signed bytes, scaled to be in [0, 1].
+ *
+ * @param a bytes containing a vector
+ * @param b bytes containing another vector, of the same dimension
+ * @return the value of the similarity function applied to the two vectors
+ */
+ public static float dotProductScore(BytesRef a, BytesRef b) {
+ // divide by 2 * 2^14 (maximum absolute value of product of 2 signed bytes) * len
+ return (1 + dotProduct(a, b)) / (float) (a.length * (1 << 15));
+ }
+
+ /**
+ * Convert a floating point vector to an array of bytes using casting; the vector values should be
+ * in [-128,127]
+ *
+ * @param vector a vector
+ * @return a new BytesRef containing the vector's values cast to byte.
+ */
+ public static BytesRef toBytesRef(float[] vector) {
Review Comment:
hmm, that seems costly to me. I think these VectorUtil methods should be tuned for performance not safety, and we should find a way to move the safety checks up to a higher-level API?
##########
lucene/core/src/java/org/apache/lucene/index/VectorEncoding.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.index;
+
+/** The numeric datatype of the vector values. */
+public enum VectorEncoding {
+
+ /**
+ * Encodes vector using 8 bits of precision per sample. Use only with DOT_PRODUCT similarity.
Review Comment:
no
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] msokolov commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
msokolov commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r949255426
##########
lucene/core/src/java/org/apache/lucene/codecs/KnnFieldVectorsWriter.java:
##########
@@ -20,8 +20,12 @@
import java.io.IOException;
import org.apache.lucene.util.Accountable;
-/** Vectors' writer for a field */
-public abstract class KnnFieldVectorsWriter implements Accountable {
+/**
+ * Vectors' writer for a field
+ *
+ * @param <T> an array type; the type of vectors to be written
+ */
+public abstract class KnnFieldVectorsWriter<T> implements Accountable {
Review Comment:
well I guess this is the key bone of contention. TBH I have thrown up my hands and just want whatever we can get merged that gets us the space savings. There were objections to the other way, so I switched back to this way. This way is more API-pure I guess, but requires more methods and API surface area. I don't mind if we switch it again, but I'm probably not going to drive that effort.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] msokolov merged pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
msokolov merged PR #1054:
URL: https://github.com/apache/lucene/pull/1054
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] msokolov commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
msokolov commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r940165941
##########
lucene/core/src/test/org/apache/lucene/util/hnsw/KnnGraphTester.java:
##########
@@ -248,7 +269,9 @@ private void run(String... args) throws Exception {
if (docVectorsPath == null) {
throw new IllegalArgumentException("missing -docs arg");
}
- matchDocs = generateRandomBitSet(numDocs, selectivity);
+ if (prefilter) {
Review Comment:
FYI: I did a couple of runs with `filterSelectivity==0.1` and `prefilter` and no `prefilter`, and it seems to work OK - no errors and the prefilter case returned higher recall / lower latency for the same other settings
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] jtibshirani commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
jtibshirani commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r948548244
##########
lucene/core/src/java/org/apache/lucene/search/KnnVectorQuery.java:
##########
@@ -133,22 +130,21 @@ private TopDocs searchLeaf(LeafReaderContext ctx, Weight filterWeight) throws IO
return NO_RESULTS;
}
- BitSet bitSet = createBitSet(scorer.iterator(), liveDocs, maxDoc);
- BitSetIterator filterIterator = new BitSetIterator(bitSet, bitSet.cardinality());
+ BitSet acceptDocs = createBitSet(scorer.iterator(), liveDocs, maxDoc);
- if (filterIterator.cost() <= k) {
+ if (acceptDocs.cardinality() <= k) {
Review Comment:
Whenever possible, we should avoiding calling `cardinality` multiple times since it can run in linear time. I thought the original logic was clearer (but I'm biased since I wrote it 😊 )
##########
lucene/core/src/java/org/apache/lucene/index/VectorEncoding.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.index;
+
+/** The numeric datatype of the vector values. */
+public enum VectorEncoding {
+
+ /**
+ * Encodes vector using 8 bits of precision per sample. Use only with DOT_PRODUCT similarity.
Review Comment:
Is it still true that it should only be used with DOT_PRODUCT similarity?
##########
lucene/core/src/java/org/apache/lucene/codecs/KnnVectorsFormat.java:
##########
@@ -76,6 +78,15 @@ public static KnnVectorsFormat forName(String name) {
/** Returns a {@link KnnVectorsReader} to read the vectors from the index. */
public abstract KnnVectorsReader fieldsReader(SegmentReadState state) throws IOException;
+ /**
+ * Returns the current KnnVectorsFormat version number. Indexes written using the format will be
+ * "stamped" with this version.
+ */
+ public int currentVersion() {
Review Comment:
It seems confusing to have a new concept of "version" separate from the codec version. It's only used in `BaseKnnVectorsFormatTestCase` -- could we instead make the `randomVectorEncoding` overridable? It would default to all encodings but older codecs could override it and just return float32?
##########
lucene/core/src/java/org/apache/lucene/document/KnnVectorField.java:
##########
@@ -117,6 +160,21 @@ public KnnVectorField(String name, float[] vector, FieldType fieldType) {
fieldsData = vector;
}
+ /**
+ * Creates a numeric vector field. Fields are single-valued: each document has either one value or
+ * no value. Vectors of a single field share the same dimension and similarity function.
+ *
+ * @param name field name
+ * @param vector value
+ * @param fieldType field type
+ * @throws IllegalArgumentException if any parameter is null, or the vector is empty or has
+ * dimension > 1024.
+ */
+ public KnnVectorField(String name, BytesRef vector, FieldType fieldType) {
Review Comment:
I think this method is only meant to be used with `VectorEncoding.BYTE`? Then it'd be good to validate this on the `FieldType`. The same thought applies to the float-oriented constructor.
##########
lucene/core/src/java/org/apache/lucene/codecs/lucene94/Lucene94HnswVectorsWriter.java:
##########
@@ -249,6 +261,29 @@ private void writeSortingField(FieldWriter fieldData, int maxDoc, Sorter.DocMap
mockGraph);
}
+ private long writeSortedFloat32Vectors(FieldWriter<?> fieldData, int[] ordMap)
+ throws IOException {
+ long vectorDataOffset = vectorData.alignFilePointer(Float.BYTES);
+ final ByteBuffer buffer =
+ ByteBuffer.allocate(fieldData.dim * Float.BYTES).order(ByteOrder.LITTLE_ENDIAN);
+ final BytesRef binaryValue = new BytesRef(buffer.array());
+ for (int ordinal : ordMap) {
+ float[] vector = (float[]) fieldData.vectors.get(ordinal);
+ buffer.asFloatBuffer().put(vector);
+ vectorData.writeBytes(binaryValue.bytes, binaryValue.offset, binaryValue.length);
+ }
+ return vectorDataOffset;
+ }
+
+ private long writeSortedByteVectors(FieldWriter<?> fieldData, int[] ordMap) throws IOException {
+ long vectorDataOffset = vectorData.alignFilePointer(Float.BYTES);
+ for (int ordinal : ordMap) {
+ byte[] vector = (byte[]) fieldData.vectors.get(ordinal);
Review Comment:
Is it correct to cast to `byte[]` here? I think that these values are `BytesRef`.
##########
lucene/core/src/java/org/apache/lucene/util/VectorUtil.java:
##########
@@ -213,4 +243,48 @@ public static void add(float[] u, float[] v) {
u[i] += v[i];
}
}
+
+ /**
+ * Dot product computed over signed bytes.
+ *
+ * @param a bytes containing a vector
+ * @param b bytes containing another vector, of the same dimension
+ * @return the value of the dot product of the two vectors
+ */
+ public static float dotProduct(BytesRef a, BytesRef b) {
+ assert a.length == b.length;
+ int total = 0;
+ int aOffset = a.offset, bOffset = b.offset;
+ for (int i = 0; i < a.length; i++) {
+ total += a.bytes[aOffset++] * b.bytes[bOffset++];
+ }
+ return total;
+ }
+
+ /**
+ * Dot product score computed over signed bytes, scaled to be in [0, 1].
+ *
+ * @param a bytes containing a vector
+ * @param b bytes containing another vector, of the same dimension
+ * @return the value of the similarity function applied to the two vectors
+ */
+ public static float dotProductScore(BytesRef a, BytesRef b) {
+ // divide by 2 * 2^14 (maximum absolute value of product of 2 signed bytes) * len
+ return (1 + dotProduct(a, b)) / (float) (a.length * (1 << 15));
+ }
+
+ /**
+ * Convert a floating point vector to an array of bytes using casting; the vector values should be
+ * in [-128,127]
+ *
+ * @param vector a vector
+ * @return a new BytesRef containing the vector's values cast to byte.
+ */
+ public static BytesRef toBytesRef(float[] vector) {
Review Comment:
Should we verify that each element lies within the expected range? This would definitely indicate an error, but right now we silently allow it and just cast the floats to bytes.
##########
lucene/core/src/java/org/apache/lucene/codecs/KnnFieldVectorsWriter.java:
##########
@@ -20,8 +20,12 @@
import java.io.IOException;
import org.apache.lucene.util.Accountable;
-/** Vectors' writer for a field */
-public abstract class KnnFieldVectorsWriter implements Accountable {
+/**
+ * Vectors' writer for a field
+ *
+ * @param <T> an array type; the type of vectors to be written
+ */
+public abstract class KnnFieldVectorsWriter<T> implements Accountable {
Review Comment:
One of our goals discussed on the JIRA was to avoid having exposing multiple element types in the APIs. We accomplished that for the read APIs where we always use `float[]`. But in the write APIs we expose separate `float[]` and `BytesRef` versions. This affects a bunch of places (`KnnVectorField`, all the writer implementations, `IndexingChain`, etc.)
I wonder if we could standardize on one type for the write APIs too, for example always accept `float[]`. That could help remove some places where we need to check the encoding (like `IndexingChain`) and remove some generics?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] msokolov commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
msokolov commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r950423611
##########
lucene/core/src/java/org/apache/lucene/codecs/lucene94/Lucene94HnswVectorsWriter.java:
##########
@@ -249,6 +261,29 @@ private void writeSortingField(FieldWriter fieldData, int maxDoc, Sorter.DocMap
mockGraph);
}
+ private long writeSortedFloat32Vectors(FieldWriter<?> fieldData, int[] ordMap)
+ throws IOException {
+ long vectorDataOffset = vectorData.alignFilePointer(Float.BYTES);
+ final ByteBuffer buffer =
+ ByteBuffer.allocate(fieldData.dim * Float.BYTES).order(ByteOrder.LITTLE_ENDIAN);
+ final BytesRef binaryValue = new BytesRef(buffer.array());
+ for (int ordinal : ordMap) {
+ float[] vector = (float[]) fieldData.vectors.get(ordinal);
+ buffer.asFloatBuffer().put(vector);
+ vectorData.writeBytes(binaryValue.bytes, binaryValue.offset, binaryValue.length);
+ }
+ return vectorDataOffset;
+ }
+
+ private long writeSortedByteVectors(FieldWriter<?> fieldData, int[] ordMap) throws IOException {
+ long vectorDataOffset = vectorData.alignFilePointer(Float.BYTES);
+ for (int ordinal : ordMap) {
+ byte[] vector = (byte[]) fieldData.vectors.get(ordinal);
Review Comment:
I posted a fix here https://github.com/apache/lucene/pull/1074
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] jtibshirani commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
jtibshirani commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r950631004
##########
lucene/core/src/java/org/apache/lucene/codecs/KnnVectorsFormat.java:
##########
@@ -76,6 +78,15 @@ public static KnnVectorsFormat forName(String name) {
/** Returns a {@link KnnVectorsReader} to read the vectors from the index. */
public abstract KnnVectorsReader fieldsReader(SegmentReadState state) throws IOException;
+ /**
+ * Returns the current KnnVectorsFormat version number. Indexes written using the format will be
+ * "stamped" with this version.
+ */
+ public int currentVersion() {
Review Comment:
Here's what I had in mind: https://github.com/apache/lucene/pull/1077. We would just move the checks to test classes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] msokolov commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
msokolov commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r949257124
##########
lucene/core/src/java/org/apache/lucene/document/KnnVectorField.java:
##########
@@ -117,6 +160,21 @@ public KnnVectorField(String name, float[] vector, FieldType fieldType) {
fieldsData = vector;
}
+ /**
+ * Creates a numeric vector field. Fields are single-valued: each document has either one value or
+ * no value. Vectors of a single field share the same dimension and similarity function.
+ *
+ * @param name field name
+ * @param vector value
+ * @param fieldType field type
+ * @throws IllegalArgumentException if any parameter is null, or the vector is empty or has
+ * dimension > 1024.
+ */
+ public KnnVectorField(String name, BytesRef vector, FieldType fieldType) {
Review Comment:
good idea
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] msokolov commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
msokolov commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r934048743
##########
lucene/core/src/java/org/apache/lucene/codecs/lucene94/CompressingVectorValues.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.codecs.lucene94;
+
+import java.io.IOException;
+import org.apache.lucene.index.FilterVectorValues;
+import org.apache.lucene.index.VectorValues;
+import org.apache.lucene.util.BytesRef;
+
+/** convert from floating point to single byte */
+public class CompressingVectorValues extends FilterVectorValues {
Review Comment:
oh - this can be deleted now
##########
lucene/core/src/java/org/apache/lucene/codecs/lucene94/Lucene94HnswVectorsFormat.java:
##########
@@ -156,6 +157,11 @@ public KnnVectorsReader fieldsReader(SegmentReadState state) throws IOException
return new Lucene94HnswVectorsReader(state);
}
+ @Override
+ public int currentVersion() {
Review Comment:
I'm not sure if we really need this -- it's used only in BaseKnnVectorsFormatTestCase to decide whether to test the BYTE format. Maybe there's a less-intrusive way to make the test work now and going forward? But I didn't like the idea of having instanceof checks on the codec that might have to be updated with each release.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
[GitHub] [lucene] kaivalnp commented on a diff in pull request #1054: LUCENE-10577: enable quantization of HNSW vectors to 8 bits
Posted by GitBox <gi...@apache.org>.
kaivalnp commented on code in PR #1054:
URL: https://github.com/apache/lucene/pull/1054#discussion_r939698986
##########
lucene/core/src/test/org/apache/lucene/util/hnsw/KnnGraphTester.java:
##########
@@ -248,7 +269,9 @@ private void run(String... args) throws Exception {
if (docVectorsPath == null) {
throw new IllegalArgumentException("missing -docs arg");
}
- matchDocs = generateRandomBitSet(numDocs, selectivity);
+ if (prefilter) {
Review Comment:
This `matchDocs` should be created even for post-filtered search, because it is used in `computeNN` to check which docs are filtered during brute-force search
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org