Skip to content

Commit

Permalink
Fixes 4233: Improve Weaviate error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vga91 committed Nov 19, 2024
1 parent 7c6254a commit 9dff2cd
Show file tree
Hide file tree
Showing 2 changed files with 21 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
9 changes: 8 additions & 1 deletion extended/src/main/java/apoc/vectordb/Weaviate.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -240,7 +241,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 (!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<Map>) collectionValue).stream()
.map(i -> {
Expand Down

0 comments on commit 9dff2cd

Please # to comment.