Skip to content
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

Revert "Handle multi value vector fields in Nrtsearch" #603

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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