llama_index icon indicating copy to clipboard operation
llama_index copied to clipboard

[Bug]: TypeError: object HeadApiResponse can't be used in 'await' expression

Open AlgerTK opened this issue 1 year ago • 3 comments

Bug Description

[RUN CODE] url = "https://127.0.0.1:9200" username = "elastic" password = "xxxx"

es_client = Elasticsearch( [url], basic_auth=(username, password), verify_certs=True, ca_certs='./server_cert.pem')

vector_store = ElasticsearchStore( index_name="example", es_client=es_client ) storage_context = StorageContext.from_defaults(vector_store=vector_store)

index = VectorStoreIndex.from_documents( documents, storage_context=storage_context, )

[VERSION] elasticsearch=8.13.0 llama-index-vector-stores-elasticsearch=0.1.7 llama-index=0.10.28

The Python Elasticsearch Clients elasticsearch[async] and elasticsearch both report the same error.

Version

0.10.28

Steps to Reproduce

I'm attempting to generate embeddings by utilizing the VectorStoreIndex.from_documents method.

Relevant Logs/Tracbacks

File "/opt/homebrew/Caskroom/miniconda/base/envs/rag/lib/python3.12/site-packages/llama_index/vector_stores/elasticsearch/base.py", line 281, in _create_index_if_not_exists
    if await self.client.indices.exists(index=index_name):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: object HeadApiResponse can't be used in 'await' expression

AlgerTK avatar Apr 12 '24 08:04 AlgerTK

It looks like you're facing a TypeError due to an issue with awaiting a non-coroutine object in the Elasticsearch integration with LlamaIndex. This problem often arises when asynchronous calls are not properly awaited or when attempting to await an object that doesn't support asynchronous operations.

Given that you're using the latest versions of the libraries involved, it's possible that this issue might have been addressed in a recent update or there's a specific usage pattern causing this error. Here are steps to troubleshoot and potentially resolve the issue:

  1. Check for Correct Await Usage: Ensure that all asynchronous functions, especially those interacting with Elasticsearch's async API, are correctly awaited. This includes verifying that you're not mistakenly awaiting a non-coroutine object.

  2. Review Asynchronous Client Usage: Confirm that you're using elasticsearch.AsyncElasticsearch appropriately for all asynchronous operations and not mixing it up with the synchronous client.

  3. Debugging: Add logging or use debugging tools to pinpoint the exact operation causing the TypeError. This can help identify if the issue is with how the Elasticsearch async client is used or with the structure of your asynchronous code.

  4. Library Versions and Updates: Since a similar issue was resolved in a past version of LlamaIndex, ensure your environment is up to date. If the problem persists, it might be worth checking the library's issue tracker or documentation for any known issues or updates regarding this error.

If after these steps the issue remains unresolved, providing more details about the implementation of VectorStoreIndex.from_documents and the specific interactions causing the error would be helpful for further diagnosis.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

dosubot[bot] avatar Apr 12 '24 08:04 dosubot[bot]

@AlgerTK Try updating your elastic client version. There's been a ton of back on worth on this error, and It comes down the elastic client version you are using

logan-markewich avatar Apr 12 '24 14:04 logan-markewich

Any specific guidance on versions? I am seeing this error with these versions elasticsearch: (8, 13, 0) llama_index.core : 0.10.31

scottmoney avatar Apr 25 '24 19:04 scottmoney

The ElasticsearchStore expects an AsyncElasticsearch object for es_client. It's described in the docstring. The type annotation could be clearer on this.

maxjakob avatar May 16 '24 09:05 maxjakob