Skip to content

Commit fb294b0

Browse files
authored
fix: add runtime checks for graph accessors in multiple classes (#774)
1 parent 6f83cdf commit fb294b0

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

geaflow-ai/src/main/java/org/apache/geaflow/ai/GeaFlowMemoryServer.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,12 @@ public String addEntity(@Param("graphName") String graphName,
160160
memoryMutableGraph.addEdge(((GraphEdge) entity).getEdge());
161161
}
162162
}
163+
GraphMemoryServer insertServer = CACHE.getServerByName(graphName);
164+
if (insertServer == null || insertServer.getGraphAccessors().isEmpty()) {
165+
throw new RuntimeException("Server or graph accessor not available for graph: " + graphName);
166+
}
163167
CACHE.getConsolidateServer().executeConsolidateTask(
164-
CACHE.getServerByName(graphName).getGraphAccessors().get(0), memoryMutableGraph);
168+
insertServer.getGraphAccessors().get(0), memoryMutableGraph);
165169
return "Success to add entities, num: " + graphEntities.size();
166170
}
167171

@@ -213,6 +217,9 @@ public String execQuery(@Param("sessionId") String sessionId,
213217
VectorSearch search = new VectorSearch(null, sessionId);
214218
search.addVector(new KeywordVector(query));
215219
server.search(search);
220+
if (server.getGraphAccessors().isEmpty()) {
221+
throw new RuntimeException("No graph accessor available for session: " + sessionId);
222+
}
216223
Context context = server.verbalize(sessionId,
217224
new SubgraphSemanticPromptFunction(server.getGraphAccessors().get(0)));
218225
return context.toString();

geaflow-ai/src/main/java/org/apache/geaflow/ai/GraphMemoryServer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ public String search(VectorSearch search) {
8181
sessionManagement.createSession(sessionId);
8282
}
8383

84+
if (graphAccessors.isEmpty()) {
85+
throw new RuntimeException("No graph accessor available");
86+
}
8487
for (IndexStore indexStore : indexStores) {
8588
if (indexStore instanceof EntityAttributeIndexStore) {
8689
SessionOperator searchOperator = new SessionOperator(graphAccessors.get(0), indexStore);

geaflow-ai/src/main/java/org/apache/geaflow/ai/service/ServerMemoryCache.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,17 @@ public void putGraph(Graph g) {
3838
}
3939

4040
public void putServer(GraphMemoryServer server) {
41+
if (server.getGraphAccessors().isEmpty()) {
42+
throw new RuntimeException("Cannot register server without graph accessor");
43+
}
4144
name2Server.put(server.getGraphAccessors().get(0)
4245
.getGraphSchema().getName(), server);
4346
}
4447

4548
public void putSession(GraphMemoryServer server, String sessionId) {
49+
if (server.getGraphAccessors().isEmpty()) {
50+
throw new RuntimeException("Cannot register session without graph accessor");
51+
}
4652
session2GraphName.put(sessionId,
4753
server.getGraphAccessors().get(0).getGraphSchema().getName());
4854
}

0 commit comments

Comments
 (0)