msokolov commented on a change in pull request #1930:
URL: https://github.com/apache/lucene-solr/pull/1930#discussion_r499858704



##########
File path: lucene/core/src/java/org/apache/lucene/codecs/VectorWriter.java
##########
@@ -0,0 +1,253 @@
+/*
+ * 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;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.lucene.index.DocIDMerger;
+import org.apache.lucene.index.FieldInfo;
+import org.apache.lucene.index.MergeState;
+import org.apache.lucene.index.VectorValues;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.util.BytesRef;
+
+import static org.apache.lucene.search.DocIdSetIterator.NO_MORE_DOCS;
+
+/**
+ * Writes vectors to an index.
+ */
+public abstract class VectorWriter implements Closeable {
+
+  /** Sole constructor */
+  protected VectorWriter() {}
+
+  /** Write all values contained in the provided reader */
+  public abstract void writeField(FieldInfo fieldInfo, VectorValues values) 
throws IOException;
+
+  /** Called once at the end before close */
+  public abstract void finish() throws IOException;
+
+  /** Merge the vector values from multiple segments, for all fields */
+  public void merge(MergeState mergeState) throws IOException {
+    for (VectorReader reader : mergeState.vectorReaders) {
+      if (reader != null) {
+        reader.checkIntegrity();
+      }
+    }
+    for (FieldInfo fieldInfo : mergeState.mergeFieldInfos) {
+      if (fieldInfo.hasVectorValues()) {
+        mergeVectors(fieldInfo, mergeState);
+      }
+    }
+    finish();
+  }
+
+  private void mergeVectors(FieldInfo mergeFieldInfo, final MergeState 
mergeState) throws IOException {
+    if (mergeState.infoStream.isEnabled("VV")) {
+      mergeState.infoStream.message("VV", "merging " + mergeState.segmentInfo);
+    }
+    List<VectorValuesSub> subs = new ArrayList<>();
+    int dimension = -1;
+    VectorValues.ScoreFunction scoreFunction = null;
+    for (int i = 0; i < mergeState.vectorReaders.length; i++) {
+      VectorReader vectorReader = mergeState.vectorReaders[i];
+      if (vectorReader != null) {
+        if (mergeFieldInfo != null && mergeFieldInfo.hasVectorValues()) {
+          int segmentDimension = mergeFieldInfo.getVectorDimension();
+          VectorValues.ScoreFunction segmentScoreFunction = 
mergeFieldInfo.getVectorScoreFunction();
+          if (dimension == -1) {
+            dimension = segmentDimension;
+            scoreFunction = mergeFieldInfo.getVectorScoreFunction();
+          } else if (dimension != segmentDimension) {
+            throw new IllegalStateException("Varying dimensions for 
vector-valued field " + mergeFieldInfo.name
+                + ": " + dimension + "!=" + segmentDimension);
+          } else if (scoreFunction != segmentScoreFunction) {

Review comment:
       Yes, `IndexingChain.indexVector` calls 
`FieldInfo.setVectorDimensionAndScoreFunction`, which checks against existing 
values. It allows to go from 0 to non-zero dimension (setting scoreFunction at 
that time), but no other change is allowed. This is tested in TestVectorValues




----------------------------------------------------------------
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.

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

Reply via email to