You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.0 KiB

2 weeks ago
import asyncio
5 days ago
import logging
4 days ago
import os
2 weeks ago
from Util.DocxUtil import get_docx_content_by_pandoc
4 days ago
from Util.LightRagUtil import initialize_rag
5 days ago
# 是不是清空重新生成
4 days ago
IS_CLEAR= True
5 days ago
# 更详细地控制日志输出
logger = logging.getLogger('lightrag')
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
logger.addHandler(handler)
6 days ago
4 days ago
2 weeks ago
async def main():
5 days ago
# 清空文件
if IS_CLEAR:
# 注释掉或删除以下清理代码
files_to_delete = [
"graph_chunk_entity_relation.graphml",
"kv_store_doc_status.json",
"kv_store_full_docs.json",
"kv_store_text_chunks.json",
"vdb_chunks.json",
"vdb_entities.json",
"vdb_relationships.json",
]
# 删除文件
for file in files_to_delete:
file_path = os.path.join(WORKING_DIR, file)
if os.path.exists(file_path):
os.remove(file_path)
logger.info(f"删除的文件:: {file_path}")
7 days ago
try:
# 注意默认设置使用NetworkX
rag = await initialize_rag(WORKING_DIR)
6 days ago
# 在docx_file 目录下遍历所有以KEMU开头的文件
for filename in os.listdir(docx_file):
if filename.startswith(KEMU):
file_path = os.path.join(docx_file, filename)
# 获取docx文件的内容
content = get_docx_content_by_pandoc(file_path)
await rag.ainsert(content, file_paths=[filename])
5 days ago
logger.info(f"Inserted content from {filename}")
7 days ago
except Exception as e:
5 days ago
logger.error(f"An error occurred: {e}")
7 days ago
finally:
await rag.finalize_storages()
2 weeks ago
4 days ago
#KEMUS=['JiHe','Math','SuShi','Chemistry','ShiJi','ChangChun']
4 days ago
KEMUS=['ShiJi']
2 weeks ago
4 days ago
for KEMU in KEMUS:
# 组装文件路径
WORKING_DIR = "./Topic/" + KEMU
docx_file = 'static/Txt/'
2 weeks ago
asyncio.run(main())
4 days ago