Skip to content

Commit

Permalink
Revert "Handle multi value vector fields in Nrtsearch (#594)" (#603)
Browse files Browse the repository at this point in the history
This reverts commit 612a8e6.
  • Loading branch information
vim345 authored Oct 20, 2023
1 parent 7278ad8 commit d8d664b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
import com.yelp.nrtsearch.server.luceneserver.doc.LoadedDocValues.SingleVector;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.lucene.codecs.KnnVectorsFormat;
import org.apache.lucene.codecs.lucene95.Lucene95HnswVectorsFormat;
import org.apache.lucene.document.BinaryDocValuesField;
Expand Down Expand Up @@ -169,32 +167,18 @@ public KnnVectorsFormat getVectorsFormat() {
public void parseDocumentField(
Document document, List<String> fieldValues, List<List<String>> facetHierarchyPaths) {
float[] floatArr = null;
List<String> cleanedFieldValues = new ArrayList<>();
if (fieldValues.size() > 1 && !isMultiValue()) {
if (getVectorDimensions() == fieldValues.size()) {
// A hacky way to merge multi value data generated in ElasticPipe as long as the size of
// input array is the same as the vector dimension size.
// TODO: Fix the issue in the indexer and remove this hacky block.
String joined =
String.join(
", ", fieldValues.stream().map(Object::toString).collect(Collectors.toList()));
cleanedFieldValues.add("[" + joined + "]");
} else {
throw new IllegalArgumentException(
"Cannot index multiple values into single value field: " + getName());
}
} else {
cleanedFieldValues.addAll(fieldValues);
}
if (cleanedFieldValues.size() == 1) {
throw new IllegalArgumentException(
"Cannot index multiple values into single value field: " + getName());
} else if (fieldValues.size() == 1) {
if (hasDocValues() && docValuesType == DocValuesType.BINARY) {
floatArr = parseVectorFieldToFloatArr(cleanedFieldValues.get(0));
floatArr = parseVectorFieldToFloatArr(fieldValues.get(0));
byte[] floatBytes = convertFloatArrToBytes(floatArr);
document.add(new BinaryDocValuesField(getName(), new BytesRef(floatBytes)));
}
if (isSearchable()) {
if (floatArr == null) {
floatArr = parseVectorFieldToFloatArr(cleanedFieldValues.get(0));
floatArr = parseVectorFieldToFloatArr(fieldValues.get(0));
}
validateVectorForSearch(floatArr);
document.add(new KnnFloatVectorField(getName(), floatArr, similarityFunction));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ public class VectorFieldDefTest extends ServerTestCase {
private static final List<String> VECTOR_FIELD_VALUES =
Arrays.asList("[1.0, 2.5, 1000.1000]", "[0.1, -2.0, 5.6]");

private static final List<String> VECTOR_FIELD_EPIPE_VALUES = Arrays.asList("1.2", "3.4", "5.6");

@Override
protected List<String> getIndices() {
return List.of(DEFAULT_TEST_INDEX, VECTOR_SEARCH_INDEX_NAME);
Expand Down Expand Up @@ -228,22 +226,6 @@ public void vectorDimensionMismatchTest() {
"The size of the vector data: 2 should match vectorDimensions field property: 3"));
}

@Test
public void vectorFieldMultiValueSameSizeAsDimension() throws Exception {
List<AddDocumentRequest> documentRequests = new ArrayList<>();
documentRequests.add(
AddDocumentRequest.newBuilder()
.setIndexName(DEFAULT_TEST_INDEX)
.putFields(
FIELD_NAME,
AddDocumentRequest.MultiValuedField.newBuilder()
.addAllValue(VECTOR_FIELD_EPIPE_VALUES)
.build())
.build());

addDocuments(documentRequests.stream());
}

@Test
public void vectorFieldMultiValueExceptionTest() {
List<AddDocumentRequest> documentRequests = new ArrayList<>();
Expand Down

0 comments on commit d8d664b

Please sign in to comment.