2024-10-29 15:36:07 -04:00
|
|
|
import os
|
|
|
|
from lightrag import LightRAG, QueryParam
|
|
|
|
from lightrag.llm import gpt_4o_mini_complete, gpt_4o_complete
|
|
|
|
|
|
|
|
#########
|
|
|
|
# Uncomment the below two lines if running in a jupyter notebook to handle the async nature of rag.insert()
|
|
|
|
# import nest_asyncio
|
|
|
|
# nest_asyncio.apply()
|
|
|
|
#########
|
|
|
|
|
2024-10-30 17:48:14 -04:00
|
|
|
WORKING_DIR = "./local_neo4jWorkDir"
|
2024-10-29 15:36:07 -04:00
|
|
|
|
|
|
|
if not os.path.exists(WORKING_DIR):
|
|
|
|
os.mkdir(WORKING_DIR)
|
|
|
|
|
|
|
|
rag = LightRAG(
|
|
|
|
working_dir=WORKING_DIR,
|
2024-11-01 08:47:52 -04:00
|
|
|
llm_model_func=gpt_4o_mini_complete, # Use gpt_4o_mini_complete LLM model
|
2024-11-01 11:01:50 -04:00
|
|
|
kg="Neo4JStorage",
|
2024-11-01 16:29:36 -04:00
|
|
|
log_level="INFO"
|
2024-10-29 15:36:07 -04:00
|
|
|
# llm_model_func=gpt_4o_complete # Optionally, use a stronger model
|
|
|
|
)
|
|
|
|
|
2024-11-01 16:11:19 -04:00
|
|
|
with open("./book.txt") as f:
|
|
|
|
rag.insert(f.read())
|
2024-10-29 15:36:07 -04:00
|
|
|
|
|
|
|
# Perform naive search
|
|
|
|
print(rag.query("What are the top themes in this story?", param=QueryParam(mode="naive")))
|
|
|
|
|
|
|
|
# Perform local search
|
|
|
|
print(rag.query("What are the top themes in this story?", param=QueryParam(mode="local")))
|
|
|
|
|
|
|
|
# Perform global search
|
|
|
|
print(rag.query("What are the top themes in this story?", param=QueryParam(mode="global")))
|
|
|
|
|
|
|
|
# Perform hybrid search
|
|
|
|
print(rag.query("What are the top themes in this story?", param=QueryParam(mode="hybrid")))
|