Issue with
asyncio.run
inside
PropertyGraphIndex
when running an API
Problem:
I'm working on ingesting documents into my
PropertyGraphIndex
while running an API that uses
llamaindex
. However, I encounter a
RuntimeError
because
llamaindex
is using
asyncio.run
inside the
SchemaLLMPathExtractor
, which conflicts with the running event loop in my API.
The error message I receive is:
RuntimeError: asyncio.run() cannot be called from a running event loop
I don't need this process to be asynchronous, I just need the ingestion to work properly in the existing API environment.
Here’s the problematic part of the code:
return asyncio.run(self.acall(nodes, show_progress=show_progress, **kwargs))
Does anyone have suggestions on how to handle this? Ideally, I want to make the ingestion work without needing to modify the event loop or make the ingestion process asynchronous.
Relevant Code Snippet:
kg_extractor: SchemaLLMPathExtractor = SchemaLLMPathExtractor(
llm=llm,
possible_entities=entity.entities.as_literal_typealias(),
possible_relations=entity.relationships.as_literal_typealias(),
kg_validation_schema=entity.validation_schema,
strict=True,
num_workers=4,
)
index = PropertyGraphIndex.from_existing(
property_graph_store=self.client,
llm=llm,
kg_extractors=[kg_extractor],
use_async=False,
embed_model=embeddings,
show_progress=True,
)
for document in documents:
index.insert(document)
Any tips or workarounds to handle this issue in a synchronous API? Thanks in advance!