Skip to content

Commit

Permalink
output hybrid error message in marqo logs
Browse files Browse the repository at this point in the history
  • Loading branch information
vicilliar committed Jan 30, 2025
1 parent 8980c62 commit fb1c54d
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
21 changes: 21 additions & 0 deletions vespa/src/main/java/ai/marqo/search/HybridSearcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.yahoo.search.Query;
import com.yahoo.search.Result;
import com.yahoo.search.Searcher;
import com.yahoo.search.result.ErrorMessage;
import com.yahoo.search.result.Hit;
import com.yahoo.search.result.HitGroup;
import com.yahoo.search.searchchain.AsyncExecution;
Expand Down Expand Up @@ -105,6 +106,8 @@ public Result search(Query query, Execution execution) {
+ e.toString());
}

raiseErrorIfPresent(resultLexical, resultTensor);

logIfVerbose(
"LEXICAL RESULTS: "
+ resultLexical.toString()
Expand Down Expand Up @@ -284,6 +287,24 @@ HitGroup rrf(
return result;
}

void raiseErrorIfPresent(Result resultLexical, Result resultTensor) {
// Raise error if either result list has an error. Make sure error messages are combined
String tensorOrLexicalErrors = "";
ErrorMessage tensorError = resultTensor.hits().getError();
if (tensorError != null) {
tensorOrLexicalErrors += "Error in TENSOR search in RRF: " + tensorError + "\n";
}

ErrorMessage lexicalError = resultLexical.hits().getError();
if (lexicalError != null) {
tensorOrLexicalErrors += "Error in LEXICAL search in RRF: " + lexicalError;
}

if (!tensorOrLexicalErrors.isEmpty()) {
throw new RuntimeException(tensorOrLexicalErrors);
}
}

/**
* Extracts mapped Tensor Address from cell then adds it as key to rank features, with cell value as the value.
* @param cell
Expand Down
67 changes: 67 additions & 0 deletions vespa/src/test/java/ai/marqo/search/HybridSearcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.yahoo.component.chain.Chain;
import com.yahoo.search.*;
import com.yahoo.search.query.ranking.RankFeatures;
import com.yahoo.search.result.ErrorMessage;
import com.yahoo.search.result.Hit;
import com.yahoo.search.result.HitGroup;
import com.yahoo.search.searchchain.*;
Expand Down Expand Up @@ -379,4 +380,70 @@ private static Query getHybridQuery(
.put("query(marqo__fields_to_rank_tensor)", fieldsToRankTensor);
return query;
}

@Nested
class RaiseErrorIfPresentTest {
@Test
void shouldRaiseErrorIfLexicalResultHasError() {
Result resultLexical =
new Result(
new Query(),
ErrorMessage.createInternalServerError("Example lexical error"));
Result resultTensor = new Result(new Query());
RuntimeException exception =
assertThrows(
RuntimeException.class,
() -> {
hybridSearcher.raiseErrorIfPresent(resultLexical, resultTensor);
});
assertThat(exception.getMessage()).contains("Error in LEXICAL search in RRF:");
assertThat(exception.getMessage()).contains("Example lexical error");
}

@Test
void shouldRaiseErrorIfTensorResultHasError() {
Result resultLexical = new Result(new Query());
Result resultTensor =
new Result(
new Query(),
ErrorMessage.createInternalServerError("Example tensor error"));
RuntimeException exception =
assertThrows(
RuntimeException.class,
() -> {
hybridSearcher.raiseErrorIfPresent(resultLexical, resultTensor);
});
assertThat(exception.getMessage()).contains("Error in TENSOR search in RRF:");
assertThat(exception.getMessage()).contains("Example tensor error");
}

@Test
void shouldRaiseErrorIfBothResultsHaveError() {
Result resultLexical =
new Result(
new Query(),
ErrorMessage.createInternalServerError("Example lexical error"));
Result resultTensor =
new Result(
new Query(),
ErrorMessage.createInternalServerError("Example tensor error"));
RuntimeException exception =
assertThrows(
RuntimeException.class,
() -> {
hybridSearcher.raiseErrorIfPresent(resultLexical, resultTensor);
});
assertThat(exception.getMessage()).contains("Error in TENSOR search in RRF:");
assertThat(exception.getMessage()).contains("Example tensor error");
assertThat(exception.getMessage()).contains("\nError in LEXICAL search in RRF:");
assertThat(exception.getMessage()).contains("Example lexical error");
}

@Test
void shouldNotRaiseErrorIfNeitherResultHasError() {
Result resultLexical = new Result(new Query());
Result resultTensor = new Result(new Query());
hybridSearcher.raiseErrorIfPresent(resultLexical, resultTensor);
}
}
}

0 comments on commit fb1c54d

Please sign in to comment.