Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: ValueError: Can't patch loop of type <class 'uvloop.Loop'> #17263

Open
leos-code opened this issue Dec 13, 2024 · 2 comments
Open

[Bug]: ValueError: Can't patch loop of type <class 'uvloop.Loop'> #17263

leos-code opened this issue Dec 13, 2024 · 2 comments
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized

Comments

@leos-code
Copy link

Bug Description

    qa_store = ElasticsearchStore(
        index_name="qa_doc_index",
        es_url=es_url,
        es_user="",
        es_password="",
        text_field="doc",
        vector_field="embedding"
    )

    qa_vector_index = VectorStoreIndex.from_vector_store(qa_store)
    qa_retriever = VectorIndexRetriever(
        index=qa_vector_index, similarity_top_k=3, verbose=True
    )
    ```
    
    When Call ElasticsearchStore happened

### Version

llama-index = "^0.12.2"、llama-index-vector-stores-elasticsearch = "^0.4.0"

### Steps to Reproduce

above

### Relevant Logs/Tracbacks

```shell
File "xxx/.venv/lib/python3.10/site-packages/llama_index/legacy/vector_stores/elasticsearch.py", line 191, in __init__
    nest_asyncio.apply()
  File "xxx/.venv/lib/python3.10/site-packages/nest_asyncio.py", line 19, in apply
    _patch_loop(loop)
  File "xxx/.venv/lib/python3.10/site-packages/nest_asyncio.py", line 193, in _patch_loop
    raise ValueError('Can\'t patch loop of type %s' % type(loop))
ValueError: Can't patch loop of type <class 'uvloop.Loop'>
@leos-code leos-code added bug Something isn't working triage Issue needs to be triaged/prioritized labels Dec 13, 2024
Copy link

dosubot bot commented Dec 13, 2024

The error you're encountering is due to a compatibility issue between nest_asyncio and uvloop. The nest_asyncio library is used to allow asynchronous code to run in environments that do not natively support it, such as Jupyter notebooks. However, nest_asyncio cannot patch event loops of type uvloop.Loop, which is causing the ValueError you see.

To resolve this issue, you can try the following approaches:

  1. Disable uvloop: If you don't specifically need uvloop, you can disable it by not importing or using it in your application. This will allow nest_asyncio to patch the default event loop.

  2. Use the Default Event Loop: Ensure that your application is using the default event loop provided by Python's asyncio module instead of uvloop. You can do this by not setting uvloop as the event loop policy.

  3. Remove nest_asyncio: If your environment supports asynchronous operations without nest_asyncio, you might be able to remove it from your code. This would involve ensuring that your environment can handle asynchronous event loops natively.

These steps should help you avoid the conflict between nest_asyncio and uvloop.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@leos-code
Copy link
Author

disable uvloop is work,but uvloop vs asyncio is better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized
Projects
None yet
Development

No branches or pull requests

1 participant