diff --git a/extended-it/src/test/java/apoc/vectordb/WeaviateTest.java b/extended-it/src/test/java/apoc/vectordb/WeaviateTest.java index d9b725d5ca..5b3aed4d27 100644 --- a/extended-it/src/test/java/apoc/vectordb/WeaviateTest.java +++ b/extended-it/src/test/java/apoc/vectordb/WeaviateTest.java @@ -455,6 +455,19 @@ public void queryReadOnlyVectorsWithMapping() { ); } + @Test + public void queryWithWrongEmbeddingSize() { + Map 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() { diff --git a/extended/src/main/java/apoc/vectordb/Weaviate.java b/extended/src/main/java/apoc/vectordb/Weaviate.java index cc56f61966..a153f6aaf8 100644 --- a/extended/src/main/java/apoc/vectordb/Weaviate.java +++ b/extended/src/main/java/apoc/vectordb/Weaviate.java @@ -5,6 +5,7 @@ import apoc.result.ListResult; import apoc.result.MapResult; 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; @@ -240,7 +241,13 @@ private Stream queryCommon(String hostOrKey, String collection, return getEmbeddingResultStream(conf, procedureCallContext, urlAccessChecker, tx, v -> { - Object getValue = ((Map) v).get("data").get("Get"); + Map mapResult = (Map) v; + List errors = (List) mapResult.get("errors"); + if (!errors.isEmpty()) { + 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) collectionValue).stream() .map(i -> {