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.

43 lines
1.3 KiB

2 weeks ago
import asyncio
2 weeks ago
from lightrag import LightRAG
2 weeks ago
from lightrag.kg.shared_storage import initialize_pipeline_status
from raganything import RAGAnything
2 weeks ago
2 weeks ago
from Util.RagUtil import create_llm_model_func, create_vision_model_func, create_embedding_func
2 weeks ago
2 weeks ago
async def load_existing_lightrag():
# 索引位置
2 weeks ago
WORKING_DIR = "./Topic/Chemistry"
2 weeks ago
2 weeks ago
# 创建 LLM 模型自定义函数
2 weeks ago
llm_model_func = create_llm_model_func()
2 weeks ago
# 创建可视模型自定义函数
2 weeks ago
vision_model_func = create_vision_model_func(llm_model_func)
2 weeks ago
# 创建嵌入模型自定义函数
2 weeks ago
embedding_func = create_embedding_func()
2 weeks ago
# 声明LightRAG实例
2 weeks ago
lightrag_instance = LightRAG(
2 weeks ago
working_dir=WORKING_DIR,
2 weeks ago
llm_model_func=llm_model_func,
embedding_func=embedding_func
2 weeks ago
)
2 weeks ago
# 初始化
2 weeks ago
await lightrag_instance.initialize_storages()
await initialize_pipeline_status()
2 weeks ago
# 创建RAGAnything实例依托于LightRAG实例
2 weeks ago
rag = RAGAnything(
2 weeks ago
lightrag=lightrag_instance,
2 weeks ago
vision_model_func=vision_model_func,
)
2 weeks ago
# 查询
2 weeks ago
result = await rag.aquery(
2 weeks ago
"氢气与氧气的反应方程式是什么?",
2 weeks ago
mode="hybrid"
)
print("查询结果:", result)
if __name__ == "__main__":
2 weeks ago
asyncio.run(load_existing_lightrag())