@@ -57,29 +57,33 @@ async def get_graphs(current_user: User = Depends(get_admin_user)):
5757 # 1. 获取默认 Neo4j 图谱信息
5858 neo4j_info = graph_base .get_graph_info ()
5959 if neo4j_info :
60- graphs .append ({
61- "id" : "neo4j" ,
62- "name" : "默认图谱" ,
63- "type" : "neo4j" ,
64- "description" : "Default graph database for uploaded documents" ,
65- "status" : neo4j_info .get ("status" , "unknown" ),
66- "created_at" : neo4j_info .get ("last_updated" ),
67- "node_count" : neo4j_info .get ("entity_count" , 0 ),
68- "edge_count" : neo4j_info .get ("relationship_count" , 0 )
69- })
60+ graphs .append (
61+ {
62+ "id" : "neo4j" ,
63+ "name" : "默认图谱" ,
64+ "type" : "neo4j" ,
65+ "description" : "Default graph database for uploaded documents" ,
66+ "status" : neo4j_info .get ("status" , "unknown" ),
67+ "created_at" : neo4j_info .get ("last_updated" ),
68+ "node_count" : neo4j_info .get ("entity_count" , 0 ),
69+ "edge_count" : neo4j_info .get ("relationship_count" , 0 ),
70+ }
71+ )
7072
7173 # 2. 获取 LightRAG 数据库信息
7274 lightrag_dbs = knowledge_base .get_lightrag_databases ()
7375 for db in lightrag_dbs :
74- graphs .append ({
75- "id" : db .get ("db_id" ),
76- "name" : db .get ("name" ),
77- "type" : "lightrag" ,
78- "description" : db .get ("description" ),
79- "status" : "active" , # LightRAG DBs are usually active if listed
80- "created_at" : db .get ("created_at" ),
81- "metadata" : db
82- })
76+ graphs .append (
77+ {
78+ "id" : db .get ("db_id" ),
79+ "name" : db .get ("name" ),
80+ "type" : "lightrag" ,
81+ "description" : db .get ("description" ),
82+ "status" : "active" , # LightRAG DBs are usually active if listed
83+ "created_at" : db .get ("created_at" ),
84+ "metadata" : db ,
85+ }
86+ )
8387
8488 return {"success" : True , "data" : graphs }
8589
@@ -118,7 +122,7 @@ async def get_subgraph(
118122 keyword = node_label ,
119123 max_depth = max_depth ,
120124 max_nodes = max_nodes ,
121- kgdb_name = db_id if not knowledge_base .is_lightrag_database (db_id ) else "neo4j"
125+ kgdb_name = db_id if not knowledge_base .is_lightrag_database (db_id ) else "neo4j" ,
122126 )
123127
124128 return {
@@ -136,8 +140,7 @@ async def get_subgraph(
136140
137141@graph .get ("/labels" )
138142async def get_graph_labels (
139- db_id : str = Query (..., description = "知识图谱ID" ),
140- current_user : User = Depends (get_admin_user )
143+ db_id : str = Query (..., description = "知识图谱ID" ), current_user : User = Depends (get_admin_user )
141144):
142145 """
143146 获取图谱的所有标签
@@ -154,8 +157,7 @@ async def get_graph_labels(
154157
155158@graph .get ("/stats" )
156159async def get_graph_stats (
157- db_id : str = Query (..., description = "知识图谱ID" ),
158- current_user : User = Depends (get_admin_user )
160+ db_id : str = Query (..., description = "知识图谱ID" ), current_user : User = Depends (get_admin_user )
159161):
160162 """
161163 获取图谱统计信息
@@ -175,23 +177,22 @@ async def get_graph_stats(
175177 entity_types [entity_type ] = entity_types .get (entity_type , 0 ) + 1
176178
177179 entity_types_list = [
178- {"type" : k , "count" : v }
179- for k , v in sorted (entity_types .items (), key = lambda x : x [1 ], reverse = True )
180+ {"type" : k , "count" : v } for k , v in sorted (entity_types .items (), key = lambda x : x [1 ], reverse = True )
180181 ]
181182
182183 return {
183184 "success" : True ,
184185 "data" : {
185186 "total_nodes" : len (knowledge_graph .nodes ),
186187 "total_edges" : len (knowledge_graph .edges ),
187- "entity_types" : entity_types_list
188- }
188+ "entity_types" : entity_types_list ,
189+ },
189190 }
190191 else :
191192 # Neo4j stats
192193 info = graph_base .get_graph_info (graph_name = db_id )
193194 if not info :
194- raise HTTPException (status_code = 404 , detail = "Graph info not found" )
195+ raise HTTPException (status_code = 404 , detail = "Graph info not found" )
195196
196197 return {
197198 "success" : True ,
@@ -200,11 +201,8 @@ async def get_graph_stats(
200201 "total_edges" : info .get ("relationship_count" , 0 ),
201202 # Neo4j info currently returns 'labels' list, not counts per label.
202203 # Improving this would require updating GraphDatabase.get_graph_info
203- "entity_types" : [
204- {"type" : label , "count" : "N/A" }
205- for label in info .get ("labels" , [])
206- ]
207- }
204+ "entity_types" : [{"type" : label , "count" : "N/A" } for label in info .get ("labels" , [])],
205+ },
208206 }
209207
210208 except Exception as e :
@@ -227,11 +225,7 @@ async def get_lightrag_subgraph(
227225):
228226 """(Deprecated) Use /graph/subgraph instead"""
229227 return await get_subgraph (
230- db_id = db_id ,
231- node_label = node_label ,
232- max_depth = max_depth ,
233- max_nodes = max_nodes ,
234- current_user = current_user
228+ db_id = db_id , node_label = node_label , max_depth = max_depth , max_nodes = max_nodes , current_user = current_user
235229 )
236230
237231
0 commit comments