fix demo
This commit is contained in:
parent
acb074d0f8
commit
6c8fa95214
10 changed files with 58 additions and 39 deletions
|
|
@ -655,6 +655,7 @@ setup_logger("lightrag", level="INFO")
|
||||||
|
|
||||||
# Note: Default settings use NetworkX
|
# Note: Default settings use NetworkX
|
||||||
# Initialize LightRAG with Neo4J implementation.
|
# Initialize LightRAG with Neo4J implementation.
|
||||||
|
async def initialize_rag():
|
||||||
rag = LightRAG(
|
rag = LightRAG(
|
||||||
working_dir=WORKING_DIR,
|
working_dir=WORKING_DIR,
|
||||||
llm_model_func=gpt_4o_mini_complete, # Use gpt_4o_mini_complete LLM model
|
llm_model_func=gpt_4o_mini_complete, # Use gpt_4o_mini_complete LLM model
|
||||||
|
|
@ -665,6 +666,8 @@ rag = LightRAG(
|
||||||
await rag.initialize_storages()
|
await rag.initialize_storages()
|
||||||
# Initialize pipeline status for document processing
|
# Initialize pipeline status for document processing
|
||||||
await initialize_pipeline_status()
|
await initialize_pipeline_status()
|
||||||
|
|
||||||
|
return rag
|
||||||
```
|
```
|
||||||
see test_neo4j.py for a working example.
|
see test_neo4j.py for a working example.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,8 @@ asyncio.run(test_funcs())
|
||||||
|
|
||||||
embedding_dimension = 3072
|
embedding_dimension = 3072
|
||||||
|
|
||||||
|
|
||||||
|
async def initialize_rag():
|
||||||
rag = LightRAG(
|
rag = LightRAG(
|
||||||
working_dir=WORKING_DIR,
|
working_dir=WORKING_DIR,
|
||||||
llm_model_func=llm_model_func,
|
llm_model_func=llm_model_func,
|
||||||
|
|
@ -91,8 +93,14 @@ rag = LightRAG(
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
rag.initialize_storages()
|
await rag.initialize_storages()
|
||||||
initialize_pipeline_status()
|
await initialize_pipeline_status()
|
||||||
|
|
||||||
|
return rag
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
rag = asyncio.run(initialize_rag())
|
||||||
|
|
||||||
book1 = open("./book_1.txt", encoding="utf-8")
|
book1 = open("./book_1.txt", encoding="utf-8")
|
||||||
book2 = open("./book_2.txt", encoding="utf-8")
|
book2 = open("./book_2.txt", encoding="utf-8")
|
||||||
|
|
@ -112,3 +120,7 @@ print(rag.query(query_text, param=QueryParam(mode="global")))
|
||||||
|
|
||||||
print("\nResult (Hybrid):")
|
print("\nResult (Hybrid):")
|
||||||
print(rag.query(query_text, param=QueryParam(mode="hybrid")))
|
print(rag.query(query_text, param=QueryParam(mode="hybrid")))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
|
||||||
|
|
@ -53,3 +53,7 @@ def main():
|
||||||
"What are the top themes in this story?", param=QueryParam(mode=mode)
|
"What are the top themes in this story?", param=QueryParam(mode=mode)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ async def initialize_rag():
|
||||||
async def main():
|
async def main():
|
||||||
try:
|
try:
|
||||||
# Initialize RAG instance
|
# Initialize RAG instance
|
||||||
rag = asyncio.run(initialize_rag())
|
rag = await initialize_rag()
|
||||||
|
|
||||||
# reading file
|
# reading file
|
||||||
with open("./book.txt", "r", encoding="utf-8") as f:
|
with open("./book.txt", "r", encoding="utf-8") as f:
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ async def initialize_rag():
|
||||||
async def main():
|
async def main():
|
||||||
try:
|
try:
|
||||||
# Initialize RAG instance
|
# Initialize RAG instance
|
||||||
rag = asyncio.run(initialize_rag())
|
rag = await initialize_rag()
|
||||||
|
|
||||||
with open("./book.txt", "r", encoding="utf-8") as f:
|
with open("./book.txt", "r", encoding="utf-8") as f:
|
||||||
await rag.ainsert(f.read())
|
await rag.ainsert(f.read())
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ async def initialize_rag():
|
||||||
async def main():
|
async def main():
|
||||||
try:
|
try:
|
||||||
# Initialize RAG instance
|
# Initialize RAG instance
|
||||||
rag = asyncio.run(initialize_rag())
|
rag = await initialize_rag()
|
||||||
|
|
||||||
with open("./book.txt", "r", encoding="utf-8") as f:
|
with open("./book.txt", "r", encoding="utf-8") as f:
|
||||||
await rag.ainsert(f.read())
|
await rag.ainsert(f.read())
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ async def initialize_rag():
|
||||||
async def main():
|
async def main():
|
||||||
try:
|
try:
|
||||||
# Initialize RAG instance
|
# Initialize RAG instance
|
||||||
rag = asyncio.run(initialize_rag())
|
rag = await initialize_rag()
|
||||||
|
|
||||||
# Extract and Insert into LightRAG storage
|
# Extract and Insert into LightRAG storage
|
||||||
with open(WORKING_DIR + "/docs.txt", "r", encoding="utf-8") as f:
|
with open(WORKING_DIR + "/docs.txt", "r", encoding="utf-8") as f:
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ async def initialize_rag():
|
||||||
async def main():
|
async def main():
|
||||||
try:
|
try:
|
||||||
# Initialize RAG instance
|
# Initialize RAG instance
|
||||||
rag = asyncio.run(initialize_rag())
|
rag = await initialize_rag()
|
||||||
|
|
||||||
with open("./book.txt", "r", encoding="utf-8") as f:
|
with open("./book.txt", "r", encoding="utf-8") as f:
|
||||||
rag.insert(f.read())
|
rag.insert(f.read())
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ async def initialize_rag():
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
# Initialize RAG instance
|
# Initialize RAG instance
|
||||||
rag = asyncio.run(initialize_rag())
|
rag = await initialize_rag()
|
||||||
|
|
||||||
# add embedding_func for graph database, it's deleted in commit 5661d76860436f7bf5aef2e50d9ee4a59660146c
|
# add embedding_func for graph database, it's deleted in commit 5661d76860436f7bf5aef2e50d9ee4a59660146c
|
||||||
rag.chunk_entity_relation_graph.embedding_func = rag.embedding_func
|
rag.chunk_entity_relation_graph.embedding_func = rag.embedding_func
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ async def initialize_rag():
|
||||||
# Example function demonstrating the new query_with_separate_keyword_extraction usage
|
# Example function demonstrating the new query_with_separate_keyword_extraction usage
|
||||||
async def run_example():
|
async def run_example():
|
||||||
# Initialize RAG instance
|
# Initialize RAG instance
|
||||||
rag = asyncio.run(initialize_rag())
|
rag = await initialize_rag()
|
||||||
|
|
||||||
book1 = open("./book_1.txt", encoding="utf-8")
|
book1 = open("./book_1.txt", encoding="utf-8")
|
||||||
book2 = open("./book_2.txt", encoding="utf-8")
|
book2 = open("./book_2.txt", encoding="utf-8")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue