import ijson import os from Tools.KG_Config import TOPIC # 文件路径 file_path = rf"d:\dsWork\dsProject\dsLightRag\Topic\{TOPIC}\vdb_entities.json" # 检查文件是否存在 if not os.path.exists(file_path): raise FileNotFoundError(f"文件不存在: {file_path}") # 使用ijson流式读取JSON文件 with open(file_path, 'r', encoding='utf-8') as f: # 流式迭代所有实体名称 print("正在读取实体...") entity_names = ijson.items(f, 'data.item.entity_name') entity_list = list(entity_names) print(f"共找到 {len(entity_list)} 个实体:") print("文件中的实体列表:") for entity in entity_list: print(f"- {entity}")