@@ -221,152 +221,6 @@ async def get_neo4j_node(
221221# =============================================================================
222222
223223
224- @graph .get ("/lightrag/test-data" )
225- async def create_test_graph_data (
226- db_id : str = Query (..., description = "数据库ID" ), current_user : User = Depends (get_admin_user )
227- ):
228- """
229- 创建测试图谱数据(临时API,用于演示图谱功能)
230- """
231- try :
232- logger .info (f"创建测试图谱数据 - db_id: { db_id } " )
233-
234- # 检查是否是 LightRAG 数据库
235- if not knowledge_base .is_lightrag_database (db_id ):
236- raise HTTPException (
237- status_code = 400 , detail = f"数据库 { db_id } 不是 LightRAG 类型,图谱功能仅支持 LightRAG 知识库"
238- )
239-
240- # 获取 LightRAG 实例
241- rag_instance = await knowledge_base ._get_lightrag_instance (db_id )
242- if not rag_instance :
243- raise HTTPException (status_code = 404 , detail = f"LightRAG 数据库 { db_id } 不存在或无法访问" )
244-
245- # 创建测试图谱数据
246- test_nodes = [
247- {
248- 'id' : '宋晓宁' ,
249- 'labels' : ['人物' ],
250- 'entity_type' : 'person' ,
251- 'properties' : {
252- 'entity_id' : '宋晓宁' ,
253- 'entity_type' : 'person' ,
254- 'description' : '人工智能学院项目负责人' ,
255- 'file_path' : 'test'
256- }
257- },
258- {
259- 'id' : '江南大学' ,
260- 'labels' : ['机构' ],
261- 'entity_type' : 'organization' ,
262- 'properties' : {
263- 'entity_id' : '江南大学' ,
264- 'entity_type' : 'organization' ,
265- 'description' : '江南大学' ,
266- 'file_path' : 'test'
267- }
268- },
269- {
270- 'id' : '食品安全知识图谱' ,
271- 'labels' : ['项目' ],
272- 'entity_type' : 'project' ,
273- 'properties' : {
274- 'entity_id' : '食品安全知识图谱' ,
275- 'entity_type' : 'project' ,
276- 'description' : '食品安全知识图谱和监管控制平台的构建与应用示范' ,
277- 'file_path' : 'test'
278- }
279- },
280- {
281- 'id' : '无锡君桥汽车租赁有限公司' ,
282- 'labels' : ['公司' ],
283- 'entity_type' : 'company' ,
284- 'properties' : {
285- 'entity_id' : '无锡君桥汽车租赁有限公司' ,
286- 'entity_type' : 'company' ,
287- 'description' : '汽车租赁服务公司' ,
288- 'file_path' : 'test'
289- }
290- },
291- {
292- 'id' : '租车费' ,
293- 'labels' : ['费用' ],
294- 'entity_type' : 'expense' ,
295- 'properties' : {
296- 'entity_id' : '租车费' ,
297- 'entity_type' : 'expense' ,
298- 'description' : '租车费用300元' ,
299- 'file_path' : 'test'
300- }
301- }
302- ]
303-
304- test_edges = [
305- {
306- 'id' : '宋晓宁-江南大学-工作于' ,
307- 'source' : '宋晓宁' ,
308- 'target' : '江南大学' ,
309- 'type' : 'WORKS_AT' ,
310- 'properties' : {
311- 'description' : '宋晓宁工作于江南大学' ,
312- 'keywords' : '工作关系'
313- }
314- },
315- {
316- 'id' : '宋晓宁-食品安全知识图谱-负责' ,
317- 'source' : '宋晓宁' ,
318- 'target' : '食品安全知识图谱' ,
319- 'type' : 'RESPONSIBLE_FOR' ,
320- 'properties' : {
321- 'description' : '宋晓宁负责食品安全知识图谱项目' ,
322- 'keywords' : '负责关系'
323- }
324- },
325- {
326- 'id' : '宋晓宁-租车费-产生' ,
327- 'source' : '宋晓宁' ,
328- 'target' : '租车费' ,
329- 'type' : 'INCURRED' ,
330- 'properties' : {
331- 'description' : '宋晓宁产生租车费用' ,
332- 'keywords' : '费用关系'
333- }
334- },
335- {
336- 'id' : '租车费-无锡君桥汽车租赁有限公司-支付给' ,
337- 'source' : '租车费' ,
338- 'target' : '无锡君桥汽车租赁有限公司' ,
339- 'type' : 'PAID_TO' ,
340- 'properties' : {
341- 'description' : '租车费支付给无锡君桥汽车租赁有限公司' ,
342- 'keywords' : '支付关系'
343- }
344- }
345- ]
346-
347- result = {
348- "success" : True ,
349- "data" : {
350- "nodes" : test_nodes ,
351- "edges" : test_edges ,
352- "is_truncated" : False ,
353- "total_nodes" : len (test_nodes ),
354- "total_edges" : len (test_edges ),
355- },
356- }
357-
358- logger .info (f"成功创建测试图谱 - 节点数: { len (test_nodes )} , 边数: { len (test_edges )} " )
359- return result
360-
361- except HTTPException :
362- # 重新抛出 HTTP 异常
363- raise
364- except Exception as e :
365- logger .error (f"创建测试图谱数据失败: { e } " )
366- logger .error (f"Traceback: { traceback .format_exc ()} " )
367- raise HTTPException (status_code = 500 , detail = f"创建测试图谱数据失败: { str (e )} " )
368-
369-
370224@graph .get ("/lightrag/stats" )
371225async def get_lightrag_stats (
372226 db_id : str = Query (..., description = "数据库ID" ), current_user : User = Depends (get_admin_user )
0 commit comments