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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import asyncio
import logging
from Util . LightRagUtil import initialize_pg_rag
# 在程序开始时添加以下配置
logging . basicConfig (
level = logging . INFO , # 设置日志级别为INFO
format = ' %(asctime)s - %(name)s - %(levelname)s - %(message)s '
)
# 或者如果你想更详细地控制日志输出
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 )
logging . basicConfig ( format = " %(levelname)s : %(message)s " , level = logging . INFO )
# 使用PG库后, 这个是没有用的,但目前的项目代码要求必传,就写一个吧。
WORKING_DIR = f " ./dsWorking "
#### 下面三个要注意写清楚内容 ####
# 1、工作空间【知识库名称】
workspace = " dsideal "
# 2、文档名称【不允许出现重复, 因为后面需要以此为条件查询】
docx_name = " sushi.txt "
# 3、文档路径
docx_path = " ../Txt/ " + docx_name
async def main ( ) :
try :
rag = await initialize_pg_rag ( WORKING_DIR = WORKING_DIR , workspace = workspace )
with open ( docx_path , " r " , encoding = " utf-8 " ) as f :
await rag . ainsert ( input = f . read ( ) , file_paths = [ docx_name ] ) # 添加来源参数
finally :
if rag :
await rag . finalize_storages ( )
if __name__ == " __main__ " :
asyncio . run ( main ( ) )