Find answers from the community

Updated 2 years ago

Note Help not needed anymore leaving

At a glance
Note: Help not needed anymore, leaving here for others' reference

I'm trying to use the PGVectorStore with async, and am starting it in an async method itself, which raises

Plain Text
RuntimeError: asyncio.run() cannot be called from a running event loop
sys:1: RuntimeWarning: coroutine 'VectorStoreIndex._async_add_nodes_to_index' was never awaited
sys:1: RuntimeWarning: coroutine 'run_async_tasks.<locals>._gather' was never awaited


This is occurring because the library defines a function run_async_tasks that... runs async tasks with asyncio.run() directly. The easy fix is to import nest_asyncio and monkeypatch asyncio. Personally, this hurts, knowing that under the hood, it's running a blocking operation by creating a new event loop :(
L
i
17 comments
Hmm, but isn't that a part in the code where it actually needs to wait for all async tasks to finish before continuing?

Tbh our async support can be a little janky. If you spot any easy improvements, I would definitely welcome a PR! ❀️
Yep, and I don't think the current design of the library would support things being fully async
I'll share my solution in a min or two, just wrapping it up. It does not fix the fact that these are actually sync but it makes it so you don't need to nest asyncio
*The issue is that if I go in my fork and remove the task system and make those methods async themselves, the methods that call them need to be async, and the methods that call THOSE, and so on, making the async creep everywhere when it shouldn't
yea I hear you. It's kind of a big headache. Even right now, async support means we have duplicate versions of the same function in most cases

I think we do actually want to refactor/fix this at some point though lol
Yeah I took a look and was like 'yep, not gonna do that'
for most libs that implement both sync and async APIs
you kind of just see they have two 'copies' of their codebase, one sync, one async
which feels like it might be where you guys are headed eventually πŸ˜‚ (nightmare to maintain though probably?)
I think actually, I want everything to be async, and the sync versions just use asyncio.run() lol. Not sure if that's a good idea or not, but would be a lot easier to maintain
@Logan M I work on a small library https://github.com/isaackogan/TikTokLive and I pretty much had to make that decision. Unfortunately just the nature of Python means you have either a fully sync library or a fully async library
Since Llamaindex is pretty much all about I/O, it kind of makes sense to be async
If there's any use for someone to help with a refactor like that, I can help πŸ‘πŸ‘
Exactly πŸ˜‚
Add a reply
Sign up and join the conversation on Discord