Add finalize_storages to sample code
This commit is contained in:
@@ -92,54 +92,62 @@ async def initialize_rag():
|
|||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
# Initialize RAG instance
|
rag = None
|
||||||
rag = await initialize_rag()
|
try:
|
||||||
|
# Initialize RAG instance
|
||||||
|
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())
|
||||||
|
|
||||||
# Perform naive search
|
# Perform naive search
|
||||||
print("\n=====================")
|
print("\n=====================")
|
||||||
print("Query mode: naive")
|
print("Query mode: naive")
|
||||||
print("=====================")
|
print("=====================")
|
||||||
print(
|
print(
|
||||||
await rag.aquery(
|
await rag.aquery(
|
||||||
"What are the top themes in this story?", param=QueryParam(mode="naive")
|
"What are the top themes in this story?", param=QueryParam(mode="naive")
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
# Perform local search
|
# Perform local search
|
||||||
print("\n=====================")
|
print("\n=====================")
|
||||||
print("Query mode: local")
|
print("Query mode: local")
|
||||||
print("=====================")
|
print("=====================")
|
||||||
print(
|
print(
|
||||||
await rag.aquery(
|
await rag.aquery(
|
||||||
"What are the top themes in this story?", param=QueryParam(mode="local")
|
"What are the top themes in this story?", param=QueryParam(mode="local")
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
# Perform global search
|
# Perform global search
|
||||||
print("\n=====================")
|
print("\n=====================")
|
||||||
print("Query mode: global")
|
print("Query mode: global")
|
||||||
print("=====================")
|
print("=====================")
|
||||||
print(
|
print(
|
||||||
await rag.aquery(
|
await rag.aquery(
|
||||||
"What are the top themes in this story?", param=QueryParam(mode="global")
|
"What are the top themes in this story?", param=QueryParam(mode="global")
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
# Perform hybrid search
|
# Perform hybrid search
|
||||||
print("\n=====================")
|
print("\n=====================")
|
||||||
print("Query mode: hybrid")
|
print("Query mode: hybrid")
|
||||||
print("=====================")
|
print("=====================")
|
||||||
print(
|
print(
|
||||||
await rag.aquery(
|
await rag.aquery(
|
||||||
"What are the top themes in this story?", param=QueryParam(mode="hybrid")
|
"What are the top themes in this story?", param=QueryParam(mode="hybrid")
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
except Exception as e:
|
||||||
|
print(f"An error occurred: {e}")
|
||||||
|
finally:
|
||||||
|
if rag:
|
||||||
|
await rag.finalize_storages()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Configure logging before running the main function
|
# Configure logging before running the main function
|
||||||
configure_logging()
|
configure_logging()
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
print("\nDone!")
|
||||||
|
Reference in New Issue
Block a user