Skip to content

Commit

Permalink
Fixes #4233: Improve Weaviate error handling (#4239)
Browse files Browse the repository at this point in the history
* Fixes #4233: Improve Weaviate error handling

* fix tests
  • Loading branch information
vga91 authored Dec 2, 2024
1 parent b4ebf3f commit e70fcd6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 13 additions & 0 deletions extended-it/src/test/java/apoc/vectordb/WeaviateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,19 @@ public void queryReadOnlyVectorsWithMapping() {
);
}

@Test
public void queryWithWrongEmbeddingSize() {
Map<String, Object> conf = map(ALL_RESULTS_KEY, true,
FIELDS_KEY, FIELDS,
HEADERS_KEY, READONLY_AUTHORIZATION);

String expectedErrMsg = "distance between entrypoint and query node: vector lengths don't match: 4 vs 3";

assertFails(db, "CALL apoc.vectordb.weaviate.query($host, 'TestCollection', [0.2, 0.1, 0.9], null, 5, $conf)",
map("host", HOST, "conf", conf),
expectedErrMsg);
}

@Test
public void queryVectorsWithCreateRelWithoutVectorResult() {

Expand Down
10 changes: 9 additions & 1 deletion extended/src/main/java/apoc/vectordb/Weaviate.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import apoc.ml.RestAPIConfig;
import apoc.result.ListResult;
import apoc.result.MapResult;
import apoc.util.CollectionUtils;
import apoc.util.UrlResolver;
import org.apache.commons.lang3.StringUtils;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.security.URLAccessChecker;
Expand Down Expand Up @@ -240,7 +242,13 @@ private Stream<EmbeddingResult> queryCommon(String hostOrKey, String collection,

return getEmbeddingResultStream(conf, procedureCallContext, urlAccessChecker, tx,
v -> {
Object getValue = ((Map<String, Map>) v).get("data").get("Get");
Map<String, Map> mapResult = (Map<String, Map>) v;
List<Map> errors = (List<Map>) mapResult.get("errors");
if ( CollectionUtils.isNotEmpty(errors) ) {
String message = "An error occurred during Weaviate API response: \n" + StringUtils.join(errors, "\n");
throw new RuntimeException(message);
}
Object getValue = mapResult.get("data").get("Get");
Object collectionValue = ((Map) getValue).get(collection);
return ((List<Map>) collectionValue).stream()
.map(i -> {
Expand Down

0 comments on commit e70fcd6

Please sign in to comment.