Skip to content

Commit

Permalink
Added exception message if conversion fails during graph creation
Browse files Browse the repository at this point in the history
Signed-off-by: Navneet Verma <navneev@amazon.com>
  • Loading branch information
navneet1v committed Apr 28, 2024
1 parent 3421a67 commit e0dd60c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ public static KNNCodecUtil.Pair getFloats(BinaryDocValues values) throws IOExcep
String vectorString = new String(bytesref.bytes, 1, bytesref.bytes.length - 1);
String[] array = vectorString.split(",");
vector = new float[array.length];
for (int i = 0; i < array.length; i++) {
vector[i] = Float.parseFloat(array[i]);
try {
for (int i = 0; i < array.length; i++) {
vector[i] = Float.parseFloat(array[i]);
}
} catch (Exception e) {
log.error("Error while converting floats for str: {}", vectorString, e);
}
stopWatch.stop();
log.info("Time taken to deserialize vector with string is : {} ms", stopWatch.totalTime().millis());
Expand Down Expand Up @@ -147,6 +151,6 @@ private static long getTotalLiveDocsCount(final BinaryDocValues binaryDocValues)

private static boolean isVectorRepresentedAsString(BytesRef bytesref) {
// Check if first bye is the special character that we have added or not.
return "$".equals(new String(bytesref.bytes, 0, 1));
return "N".equals(new String(bytesref.bytes, 0, 1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ Optional<ParsedVector> getVectorFromContextString(ParseContext context, int dime
int vectorIndex = 0;
XContentParser.Token token = context.parser().currentToken();
float value;
String vectors = "$";
String vectors = "N";
final ParsedVector.ParsedVectorBuilder parsedVector = ParsedVector.builder();
if (token == XContentParser.Token.START_ARRAY) {
token = context.parser().nextToken();
Expand Down Expand Up @@ -811,7 +811,7 @@ Optional<ParsedVector> getVectorFromContextString(ParseContext context, int dime
// as vectors have only $ so it will be fast
vectors = vectors + context.parser().text();
}
if (vectors.equals("$")) {
if (vectors.equals("N")) {
validateVectorDimension(dimension, vectorIndex);
parsedVector.vector(vector);
} else {
Expand Down

0 comments on commit e0dd60c

Please sign in to comment.