Open yyoussef11 opened 3 days ago
Hey @yyoussef11! 👋 I'm here to help you squash those bugs and answer your burning questions! Let's tackle this issue together and get things back on track.
To resolve the "RuntimeError: Event loop is closed" when creating an index using Neo4jPropertyGraphStore
and PropertyGraphIndex
in llama-index
, ensure that the Neo4j connection is properly closed after the index creation. Here is the relevant code snippet:
from llama_index.core.indices.property_graph import PropertyGraphIndex
from llama_index.graph_stores.neo4j import Neo4jPropertyGraphStore
# Create a Neo4jPropertyGraphStore instance
graph_store = Neo4jPropertyGraphStore(
username="neo4j",
password="neo4j",
url="bolt://localhost:7687",
database="neo4j"
)
# Create the index
index = PropertyGraphIndex.from_documents(
documents,
property_graph_store=graph_store,
)
# Close the Neo4j connection explicitly
graph_store.close()
Ensure that you call graph_store.close()
after creating the index to close the Neo4j connection explicitly. This should help in avoiding the "RuntimeError: Event loop is closed" error [1].
Additionally, when dealing with asynchronous operations, make sure to manage the event loop properly. Here are some best practices:
Avoid Nested Event Loops: Ensure that asyncio.run
is not called within an already running event loop. Check if an event loop is already running using asyncio.get_event_loop().is_running()
.
Use await
in Asynchronous Contexts: When inside an asynchronous function, use await
instead of asyncio.run
to avoid blocking the event loop.
Graceful Shutdown: Ensure that all asynchronous tasks are properly awaited and completed before shutting down the event loop to avoid resource leaks.
Error Handling: Implement proper error handling for asynchronous tasks to manage exceptions and ensure the stability of the application [2].
By following these steps, you should be able to mitigate the "RuntimeError: Event loop is closed" error and ensure smooth operation of your index creation process.
To continue talking to Dosu, mention @dosu.
Usually "event look closed" means some other error happened
Try pip install -U llama-index-embeddings-ollama
Also test your embed model and llm on its own
print(llm.complete("hello"))
print(embed_model.get_text_embedding("hello"))
hello @logan-markewich thanks for the answer i was able to run the 2 prints, actually i am using ollama embeddings for a Redis vector store and it is perfectly working. Even when i used KnowledgeGraphIndex with Neo4jGraphStore i did not face issues with the embeddings. It was only when i moved to PropertyGraphIndex and Neo4jPropertyGraphStore that i started facing the mentioned issues.
To note that the suggestion of dosubot resulted in the same error. even after manually closing the connection to the graph_store, i still faced the issue.
FYI am using python 3.12
Did you update your ollama embeddings though?
@logan-markewich yes, i have the latest ollama embeddings: llama-index-embeddings-ollama==0.3.0 i have started from a fresh environment with a new python and new llama index packages.
Bug Description
I am using Neo4jPropertyGraphStore and then trying to create an index from the documents. (i got the same error even without using the from_documents) as i saw in other documentations as well (same error) Also note that i am using Ollama for Embeddings and for LLM
upon creating the index, i am facing the issue RuntimeError: Event loop is closed
To note that i have a big interest in Neo4jPropertyGraphStore and PropertyGraphIndex since i will be able to reuse the index from another file (or solution)
something like mentioned here:
Version
llama-index==0.11.9
Steps to Reproduce
Ollama embeddings version: llama-index-embeddings-ollama==0.3.0 graph stores: llama-index-graph-stores-neo4j==0.3.2 llama index core: llama-index-core==0.11.9
Scenario 1: using PropertyGraphIndex from documents while using async = False (based on this https://github.com/run-llama/llama_index/issues/15292)
Got the error: sys:1: RuntimeWarning: coroutine 'SimpleLLMPathExtractor._aextract' was never awaited Note: looping over several directories failed, however i got documents from 1 directory for this one.
Scenario 2: using PropertyGraphIndex from documents with async = True (default) i received an error: AttributeError: 'NoneType' object has no attribute 'send'
Scenario 3: mentioning the kg_extractor:
Error: AttributeError: 'NoneType' object has no attribute 'send'
Relevant Logs/Tracbacks