From fb1c54db14f7349bb83c6d3b702f8027d36c92c1 Mon Sep 17 00:00:00 2001 From: Joshua Date: Thu, 30 Jan 2025 14:39:47 +0800 Subject: [PATCH] output hybrid error message in marqo logs --- .../java/ai/marqo/search/HybridSearcher.java | 21 ++++++ .../ai/marqo/search/HybridSearcherTest.java | 67 +++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/vespa/src/main/java/ai/marqo/search/HybridSearcher.java b/vespa/src/main/java/ai/marqo/search/HybridSearcher.java index 0c352197a..0c33415f1 100644 --- a/vespa/src/main/java/ai/marqo/search/HybridSearcher.java +++ b/vespa/src/main/java/ai/marqo/search/HybridSearcher.java @@ -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; @@ -105,6 +106,8 @@ public Result search(Query query, Execution execution) { + e.toString()); } + raiseErrorIfPresent(resultLexical, resultTensor); + logIfVerbose( "LEXICAL RESULTS: " + resultLexical.toString() @@ -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 diff --git a/vespa/src/test/java/ai/marqo/search/HybridSearcherTest.java b/vespa/src/test/java/ai/marqo/search/HybridSearcherTest.java index 246e98b91..965ea7af9 100644 --- a/vespa/src/test/java/ai/marqo/search/HybridSearcherTest.java +++ b/vespa/src/test/java/ai/marqo/search/HybridSearcherTest.java @@ -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.*; @@ -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); + } + } }