-
Notifications
You must be signed in to change notification settings - Fork 15.1k
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
AzureSearch.avector_search_with_score() triggers "TypeError: 'AsyncSearchItemPaged' object is not iterable" when calling _results_to_documents() #24740
Comments
Actually, my fix (and, I presume, the original async code) still has a pretty fatal flaw: because all of these
Rather than having to re-establish the connection with each call, I have tried keeping it open and closing it on deletion of the |
I met the same issue lol. ` async def asemantic_hybrid_search_with_score_and_rerank(
|
I am also running into the same error message trying to call ainvoke on the AzureSearchVectorStoreRetriever, which is also using the methods described above. The synchronous call is working fine, but the async call causes the error "'AsyncSearchItemPaged' object is not iterable" during retrieval phase. |
@JuliaZamaitat, you can override the class to remove the |
**Description** Fix the asyncronous methods to retrieve documents from AzureSearch VectorStore. The previous changes from [this commit](ffe6ca9) create a similar code for the syncronous methods and the asyncronous ones but the asyncronous client return an asyncronous iterator "AsyncSearchItemPaged" as said in the issue #24740. To solve this issue, the syncronous iterators in asyncronous methods where changed to asyncronous iterators. @chrislrobert said in [this comment](#24740 (comment)) that there was a still a flaw due to `with` blocks that close the client after each call. I removed this `with` blocks in the `async_client` following the same pattern as the sync `client`. In order to close up the connections, a __del__ method is included to gently close up clients once the vectorstore object is destroyed. **Issue:** #24740 and #24064 **Dependencies:** No new dependencies for this change **Example notebook:** I created a notebook just to test the changes work and gives the same results as the syncronous methods for vector and hybrid search. With these changes, the asyncronous methods in the retriever work as well. ![image](https://github.com/user-attachments/assets/697e431b-9d7f-4d0d-b205-59d051ac2b67) **Lint and test**: Passes the tests and the linter
…-ai#24921) **Description** Fix the asyncronous methods to retrieve documents from AzureSearch VectorStore. The previous changes from [this commit](langchain-ai@ffe6ca9) create a similar code for the syncronous methods and the asyncronous ones but the asyncronous client return an asyncronous iterator "AsyncSearchItemPaged" as said in the issue langchain-ai#24740. To solve this issue, the syncronous iterators in asyncronous methods where changed to asyncronous iterators. @chrislrobert said in [this comment](langchain-ai#24740 (comment)) that there was a still a flaw due to `with` blocks that close the client after each call. I removed this `with` blocks in the `async_client` following the same pattern as the sync `client`. In order to close up the connections, a __del__ method is included to gently close up clients once the vectorstore object is destroyed. **Issue:** langchain-ai#24740 and langchain-ai#24064 **Dependencies:** No new dependencies for this change **Example notebook:** I created a notebook just to test the changes work and gives the same results as the syncronous methods for vector and hybrid search. With these changes, the asyncronous methods in the retriever work as well. ![image](https://github.com/user-attachments/assets/697e431b-9d7f-4d0d-b205-59d051ac2b67) **Lint and test**: Passes the tests and the linter
@prawiraelang I was confused too, as the changes were merged into |
Thanks @chrislrobert for your response. Let's wait then. Hopefully, the fix will be released soon. |
@prawiraelang It looks like this was included in 0.2.13 released on Aug. 28 — so just after we'd had this exchange! Have you been able to update and confirm that all works as expected? |
Yes, I also noticed that release and I've updated it. I can confirm that it works as expected. |
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
TypeError("'AsyncSearchItemPaged' object is not iterable")Traceback (most recent call last):
File "/Users/crobert/Code/Higher Bar AI/almitra-pilot-be/venv/lib/python3.10/site-packages/langchain/chains/base.py", line 208, in ainvoke
await self._acall(inputs, run_manager=run_manager)
File "/Users/crobert/Code/Higher Bar AI/almitra-pilot-be/venv/lib/python3.10/site-packages/langchain/chains/conversational_retrieval/base.py", line 212, in _acall
docs = await self._aget_docs(new_question, inputs, run_manager=_run_manager)
File "/Users/crobert/Code/Higher Bar AI/almitra-pilot-be/venv/lib/python3.10/site-packages/langchain/chains/conversational_retrieval/base.py", line 410, in _aget_docs
docs = await self.retriever.ainvoke(
File "/Users/crobert/Code/Higher Bar AI/almitra-pilot-be/venv/lib/python3.10/site-packages/langchain_core/retrievers.py", line 280, in ainvoke
raise e
File "/Users/crobert/Code/Higher Bar AI/almitra-pilot-be/venv/lib/python3.10/site-packages/langchain_core/retrievers.py", line 273, in ainvoke
result = await self._aget_relevant_documents(
File "/Users/crobert/Code/Higher Bar AI/almitra-pilot-be/venv/lib/python3.10/site-packages/langchain_community/vectorstores/azuresearch.py", line 1590, in _aget_relevant_documents
await self.vectorstore.asimilarity_search_with_relevance_scores(
File "/Users/crobert/Code/Higher Bar AI/almitra-pilot-be/venv/lib/python3.10/site-packages/langchain_community/vectorstores/azuresearch.py", line 663, in asimilarity_search_with_relevance_scores
result = await self.avector_search_with_score(query, k=k, **kwargs)
File "/Users/crobert/Code/Higher Bar AI/almitra-pilot-be/venv/lib/python3.10/site-packages/langchain_community/vectorstores/azuresearch.py", line 750, in avector_search_with_score
return _results_to_documents(results)
File "/Users/crobert/Code/Higher Bar AI/almitra-pilot-be/venv/lib/python3.10/site-packages/langchain_community/vectorstores/azuresearch.py", line 1623, in _results_to_documents
docs = [
TypeError: 'AsyncSearchItemPaged' object is not iterable
Description
This commit for issue #24064 caused a regression in async support. After that commit,
avector_search_with_score()
calls_asimple_search()
, which usesasync with self.async_client
, and then tries to call_results_to_documents()
with the results — but that triggers a "TypeError: 'AsyncSearchItemPaged' object is not iterable" because it usesAsyncSearchItemPaged
on a closed HTTP connection (because the connection closed at the end of the_asimple_search()
with
block.The original async PR #22075 seemed to have the right idea: the async results need to be handled within the
with
block. Looking at that code, it looks like it should probably work. However, if I roll back to 0.2.7, I run into the "KeyError('content_vector')" that triggered issue #24064. For the moment, I've gotten things running by overriding AzureSearch as follows:System Info
System Information
Package Information
The text was updated successfully, but these errors were encountered: