[GitHub] [lucene] jpountz commented on a change in pull request #534: LUCENE-10183: KnnVectorsWriter#writeField to take KnnVectorsReader instead of VectorValues

2022-01-05 Thread GitBox


jpountz commented on a change in pull request #534:
URL: https://github.com/apache/lucene/pull/534#discussion_r778880348



##
File path: 
lucene/core/src/test/org/apache/lucene/codecs/perfield/TestPerFieldKnnVectorsFormat.java
##
@@ -172,9 +171,14 @@ public KnnVectorsWriter fieldsWriter(SegmentWriteState 
state) throws IOException
   KnnVectorsWriter writer = delegate.fieldsWriter(state);
   return new KnnVectorsWriter() {
 @Override
-public void writeField(FieldInfo fieldInfo, VectorValues values) 
throws IOException {
+public void writeField(FieldInfo fieldInfo, KnnVectorsReader 
knnVectorsReader)
+throws IOException {
   fieldsWritten.add(fieldInfo.name);
-  writer.writeField(fieldInfo, values);
+  // assert that knnVectorsReader#getVectorValues returns different 
instances upon repeated
+  // calls

Review comment:
   This is the sort of things that we usually check via 
AssertingKnnVectorsReader.




-- 
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-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] jpountz commented on a change in pull request #534: LUCENE-10183: KnnVectorsWriter#writeField to take KnnVectorsReader instead of VectorValues

2022-01-03 Thread GitBox


jpountz commented on a change in pull request #534:
URL: https://github.com/apache/lucene/pull/534#discussion_r777482319



##
File path: lucene/core/src/java/org/apache/lucene/codecs/KnnVectorsWriter.java
##
@@ -107,7 +110,36 @@ private void mergeVectors(FieldInfo mergeFieldInfo, final 
MergeState mergeState)
 }
 // Create a new VectorValues by iterating over the sub vectors, mapping 
the resulting
 // docids using docMaps in the mergeState.
-writeField(mergeFieldInfo, new VectorValuesMerger(subs, mergeState));
+writeField(
+mergeFieldInfo,
+new KnnVectorsReader() {
+  @Override
+  public long ramBytesUsed() {
+return 0;
+  }
+
+  @Override
+  public void close() throws IOException {
+throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public void checkIntegrity() throws IOException {
+throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public VectorValues getVectorValues(String field) throws IOException 
{
+return new VectorValuesMerger(subs, mergeState);

Review comment:
   This way, the `VectorValues` in subs would be shared across all callers 
of `getVectorValues`. I think we need to re-create `subs` every time 
`getVectorValues` is called.




-- 
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-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene] jpountz commented on a change in pull request #534: LUCENE-10183: KnnVectorsWriter#writeField to take KnnVectorsReader instead of VectorValues

2021-12-14 Thread GitBox


jpountz commented on a change in pull request #534:
URL: https://github.com/apache/lucene/pull/534#discussion_r768405655



##
File path: 
lucene/core/src/java/org/apache/lucene/index/EmptyKnnVectorsReader.java
##
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import org.apache.lucene.codecs.KnnVectorsReader;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.util.Bits;
+
+/** Abstract base class implementing a {@link KnnVectorsReader} that has no 
vector values. */
+public abstract class EmptyKnnVectorsReader extends KnnVectorsReader {

Review comment:
   We do it for doc values because doc values support 5 different types 
(numeric, sorted numeric, sorted, sorted set, binary) and the empty producer 
helps only implement the doc values type that we care about. Since there is a 
single type of vectors, I don't think we need this empty producer, let's remove 
it and extend KnnVectorsReader directly?

##
File path: lucene/core/src/java/org/apache/lucene/index/VectorValuesWriter.java
##
@@ -109,11 +110,15 @@ private void updateBytesUsed() {
   public void flush(Sorter.DocMap sortMap, KnnVectorsWriter knnVectorsWriter) 
throws IOException {
 VectorValues vectorValues =
 new BufferedVectorValues(docsWithField, vectors, 
fieldInfo.getVectorDimension());
-if (sortMap != null) {
-  knnVectorsWriter.writeField(fieldInfo, new 
SortingVectorValues(vectorValues, sortMap));
-} else {
-  knnVectorsWriter.writeField(fieldInfo, vectorValues);
-}
+KnnVectorsReader vectorsReader =
+new EmptyKnnVectorsReader() {
+  @Override
+  public VectorValues getVectorValues(String field) throws IOException 
{
+return sortMap != null ? new SortingVectorValues(vectorValues, 
sortMap) : vectorValues;

Review comment:
   This is incorrect as it would return the same instance every time it is 
called. We should instantiate a new BufferedVectorValues instance every time 
this method is called.




-- 
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-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org