fix demo
Browse files- README.md +12 -9
- examples/lightrag_azure_openai_demo.py +35 -23
- examples/lightrag_bedrock_demo.py +4 -0
- examples/lightrag_nvidia_demo.py +1 -1
- examples/lightrag_openai_compatible_demo.py +1 -1
- examples/lightrag_openai_compatible_demo_embedding_cache.py +1 -1
- examples/lightrag_oracle_demo.py +1 -1
- examples/lightrag_tidb_demo.py +1 -1
- examples/lightrag_zhipu_postgres_demo.py +1 -1
- examples/query_keyword_separation_example.py +1 -1
README.md
CHANGED
|
@@ -655,16 +655,19 @@ setup_logger("lightrag", level="INFO")
|
|
| 655 |
|
| 656 |
# Note: Default settings use NetworkX
|
| 657 |
# Initialize LightRAG with Neo4J implementation.
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
|
|
|
| 663 |
|
| 664 |
-
# Initialize database connections
|
| 665 |
-
await rag.initialize_storages()
|
| 666 |
-
# Initialize pipeline status for document processing
|
| 667 |
-
await initialize_pipeline_status()
|
|
|
|
|
|
|
| 668 |
```
|
| 669 |
see test_neo4j.py for a working example.
|
| 670 |
|
|
|
|
| 655 |
|
| 656 |
# Note: Default settings use NetworkX
|
| 657 |
# Initialize LightRAG with Neo4J implementation.
|
| 658 |
+
async def initialize_rag():
|
| 659 |
+
rag = LightRAG(
|
| 660 |
+
working_dir=WORKING_DIR,
|
| 661 |
+
llm_model_func=gpt_4o_mini_complete, # Use gpt_4o_mini_complete LLM model
|
| 662 |
+
graph_storage="Neo4JStorage", #<-----------override KG default
|
| 663 |
+
)
|
| 664 |
|
| 665 |
+
# Initialize database connections
|
| 666 |
+
await rag.initialize_storages()
|
| 667 |
+
# Initialize pipeline status for document processing
|
| 668 |
+
await initialize_pipeline_status()
|
| 669 |
+
|
| 670 |
+
return rag
|
| 671 |
```
|
| 672 |
see test_neo4j.py for a working example.
|
| 673 |
|
examples/lightrag_azure_openai_demo.py
CHANGED
|
@@ -81,34 +81,46 @@ asyncio.run(test_funcs())
|
|
| 81 |
|
| 82 |
embedding_dimension = 3072
|
| 83 |
|
| 84 |
-
rag = LightRAG(
|
| 85 |
-
working_dir=WORKING_DIR,
|
| 86 |
-
llm_model_func=llm_model_func,
|
| 87 |
-
embedding_func=EmbeddingFunc(
|
| 88 |
-
embedding_dim=embedding_dimension,
|
| 89 |
-
max_token_size=8192,
|
| 90 |
-
func=embedding_func,
|
| 91 |
-
),
|
| 92 |
-
)
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
|
| 98 |
-
book2 = open("./book_2.txt", encoding="utf-8")
|
| 99 |
|
| 100 |
-
|
|
|
|
| 101 |
|
| 102 |
-
|
|
|
|
| 103 |
|
| 104 |
-
print("
|
| 105 |
-
print(rag.query(query_text, param=QueryParam(mode="
|
| 106 |
|
| 107 |
-
print("\nResult (
|
| 108 |
-
print(rag.query(query_text, param=QueryParam(mode="
|
| 109 |
|
| 110 |
-
print("\nResult (Global):")
|
| 111 |
-
print(rag.query(query_text, param=QueryParam(mode="global")))
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
|
|
|
| 81 |
|
| 82 |
embedding_dimension = 3072
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
+
async def initialize_rag():
|
| 86 |
+
rag = LightRAG(
|
| 87 |
+
working_dir=WORKING_DIR,
|
| 88 |
+
llm_model_func=llm_model_func,
|
| 89 |
+
embedding_func=EmbeddingFunc(
|
| 90 |
+
embedding_dim=embedding_dimension,
|
| 91 |
+
max_token_size=8192,
|
| 92 |
+
func=embedding_func,
|
| 93 |
+
),
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
await rag.initialize_storages()
|
| 97 |
+
await initialize_pipeline_status()
|
| 98 |
+
|
| 99 |
+
return rag
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def main():
|
| 103 |
+
rag = asyncio.run(initialize_rag())
|
| 104 |
+
|
| 105 |
+
book1 = open("./book_1.txt", encoding="utf-8")
|
| 106 |
+
book2 = open("./book_2.txt", encoding="utf-8")
|
| 107 |
+
|
| 108 |
+
rag.insert([book1.read(), book2.read()])
|
| 109 |
|
| 110 |
+
query_text = "What are the main themes?"
|
|
|
|
| 111 |
|
| 112 |
+
print("Result (Naive):")
|
| 113 |
+
print(rag.query(query_text, param=QueryParam(mode="naive")))
|
| 114 |
|
| 115 |
+
print("\nResult (Local):")
|
| 116 |
+
print(rag.query(query_text, param=QueryParam(mode="local")))
|
| 117 |
|
| 118 |
+
print("\nResult (Global):")
|
| 119 |
+
print(rag.query(query_text, param=QueryParam(mode="global")))
|
| 120 |
|
| 121 |
+
print("\nResult (Hybrid):")
|
| 122 |
+
print(rag.query(query_text, param=QueryParam(mode="hybrid")))
|
| 123 |
|
|
|
|
|
|
|
| 124 |
|
| 125 |
+
if __name__ == "__main__":
|
| 126 |
+
main()
|
examples/lightrag_bedrock_demo.py
CHANGED
|
@@ -53,3 +53,7 @@ def main():
|
|
| 53 |
"What are the top themes in this story?", param=QueryParam(mode=mode)
|
| 54 |
)
|
| 55 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
"What are the top themes in this story?", param=QueryParam(mode=mode)
|
| 54 |
)
|
| 55 |
)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
if __name__ == "__main__":
|
| 59 |
+
main()
|
examples/lightrag_nvidia_demo.py
CHANGED
|
@@ -125,7 +125,7 @@ async def initialize_rag():
|
|
| 125 |
async def main():
|
| 126 |
try:
|
| 127 |
# Initialize RAG instance
|
| 128 |
-
rag =
|
| 129 |
|
| 130 |
# reading file
|
| 131 |
with open("./book.txt", "r", encoding="utf-8") as f:
|
|
|
|
| 125 |
async def main():
|
| 126 |
try:
|
| 127 |
# Initialize RAG instance
|
| 128 |
+
rag = await initialize_rag()
|
| 129 |
|
| 130 |
# reading file
|
| 131 |
with open("./book.txt", "r", encoding="utf-8") as f:
|
examples/lightrag_openai_compatible_demo.py
CHANGED
|
@@ -77,7 +77,7 @@ async def initialize_rag():
|
|
| 77 |
async def main():
|
| 78 |
try:
|
| 79 |
# Initialize RAG instance
|
| 80 |
-
rag =
|
| 81 |
|
| 82 |
with open("./book.txt", "r", encoding="utf-8") as f:
|
| 83 |
await rag.ainsert(f.read())
|
|
|
|
| 77 |
async def main():
|
| 78 |
try:
|
| 79 |
# Initialize RAG instance
|
| 80 |
+
rag = await initialize_rag()
|
| 81 |
|
| 82 |
with open("./book.txt", "r", encoding="utf-8") as f:
|
| 83 |
await rag.ainsert(f.read())
|
examples/lightrag_openai_compatible_demo_embedding_cache.py
CHANGED
|
@@ -81,7 +81,7 @@ async def initialize_rag():
|
|
| 81 |
async def main():
|
| 82 |
try:
|
| 83 |
# Initialize RAG instance
|
| 84 |
-
rag =
|
| 85 |
|
| 86 |
with open("./book.txt", "r", encoding="utf-8") as f:
|
| 87 |
await rag.ainsert(f.read())
|
|
|
|
| 81 |
async def main():
|
| 82 |
try:
|
| 83 |
# Initialize RAG instance
|
| 84 |
+
rag = await initialize_rag()
|
| 85 |
|
| 86 |
with open("./book.txt", "r", encoding="utf-8") as f:
|
| 87 |
await rag.ainsert(f.read())
|
examples/lightrag_oracle_demo.py
CHANGED
|
@@ -107,7 +107,7 @@ async def initialize_rag():
|
|
| 107 |
async def main():
|
| 108 |
try:
|
| 109 |
# Initialize RAG instance
|
| 110 |
-
rag =
|
| 111 |
|
| 112 |
# Extract and Insert into LightRAG storage
|
| 113 |
with open(WORKING_DIR + "/docs.txt", "r", encoding="utf-8") as f:
|
|
|
|
| 107 |
async def main():
|
| 108 |
try:
|
| 109 |
# Initialize RAG instance
|
| 110 |
+
rag = await initialize_rag()
|
| 111 |
|
| 112 |
# Extract and Insert into LightRAG storage
|
| 113 |
with open(WORKING_DIR + "/docs.txt", "r", encoding="utf-8") as f:
|
examples/lightrag_tidb_demo.py
CHANGED
|
@@ -87,7 +87,7 @@ async def initialize_rag():
|
|
| 87 |
async def main():
|
| 88 |
try:
|
| 89 |
# Initialize RAG instance
|
| 90 |
-
rag =
|
| 91 |
|
| 92 |
with open("./book.txt", "r", encoding="utf-8") as f:
|
| 93 |
rag.insert(f.read())
|
|
|
|
| 87 |
async def main():
|
| 88 |
try:
|
| 89 |
# Initialize RAG instance
|
| 90 |
+
rag = await initialize_rag()
|
| 91 |
|
| 92 |
with open("./book.txt", "r", encoding="utf-8") as f:
|
| 93 |
rag.insert(f.read())
|
examples/lightrag_zhipu_postgres_demo.py
CHANGED
|
@@ -59,7 +59,7 @@ async def initialize_rag():
|
|
| 59 |
|
| 60 |
async def main():
|
| 61 |
# Initialize RAG instance
|
| 62 |
-
rag =
|
| 63 |
|
| 64 |
# add embedding_func for graph database, it's deleted in commit 5661d76860436f7bf5aef2e50d9ee4a59660146c
|
| 65 |
rag.chunk_entity_relation_graph.embedding_func = rag.embedding_func
|
|
|
|
| 59 |
|
| 60 |
async def main():
|
| 61 |
# Initialize RAG instance
|
| 62 |
+
rag = await initialize_rag()
|
| 63 |
|
| 64 |
# add embedding_func for graph database, it's deleted in commit 5661d76860436f7bf5aef2e50d9ee4a59660146c
|
| 65 |
rag.chunk_entity_relation_graph.embedding_func = rag.embedding_func
|
examples/query_keyword_separation_example.py
CHANGED
|
@@ -102,7 +102,7 @@ async def initialize_rag():
|
|
| 102 |
# Example function demonstrating the new query_with_separate_keyword_extraction usage
|
| 103 |
async def run_example():
|
| 104 |
# Initialize RAG instance
|
| 105 |
-
rag =
|
| 106 |
|
| 107 |
book1 = open("./book_1.txt", encoding="utf-8")
|
| 108 |
book2 = open("./book_2.txt", encoding="utf-8")
|
|
|
|
| 102 |
# Example function demonstrating the new query_with_separate_keyword_extraction usage
|
| 103 |
async def run_example():
|
| 104 |
# Initialize RAG instance
|
| 105 |
+
rag = await initialize_rag()
|
| 106 |
|
| 107 |
book1 = open("./book_1.txt", encoding="utf-8")
|
| 108 |
book2 = open("./book_2.txt", encoding="utf-8")
|