Azure AI Search Retriever giving 'AsyncSearchItemPaged' object is not iterable #25390
Replies: 1 comment
-
To resolve the Here is the relevant part of the code that should be correct: async def _aget_relevant_documents(
self, query: str, *, run_manager: AsyncCallbackManagerForRetrieverRun
) -> List[Document]:
search_results = await self._asearch(query)
return [
Document(page_content=result.pop(self.content_key), metadata=result)
for result in search_results
] If you are still encountering the error, ensure that the async def _aget_relevant_documents(
self, query: str, *, run_manager: AsyncCallbackManagerForRetrieverRun
) -> List[Document]:
search_results = await self._asearch(query)
# Debug statement to check the type of search_results
print(f"search_results type: {type(search_results)}")
return [
Document(page_content=result.pop(self.content_key), metadata=result)
for result in search_results
] If async def _asearch(self, query: str) -> List[dict]:
search_url = self._build_search_url(query)
if not self.aiosession:
async with aiohttp.ClientSession() as session:
async with session.get(search_url, headers=self._headers) as response:
response_json = await response.json()
else:
async with self.aiosession.get(
search_url, headers=self._headers
) as response:
response_json = await response.json()
return response_json["value"] Ensure that |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
Invoking:
financial_reportings_mulitple_orgs
with{'query': 'Cisco performance in 2023'}
2024-08-14 09:47:32 - HTTP Request: POST https://icx-oai-eastus2-lab-01.openai.azure.com//openai/deployments/text-embedding-ada-002/embeddings?api-version=2023-09-01-preview "HTTP/1.1 200 OK"
2024-08-14 09:47:32 - 'AsyncSearchItemPaged' object is not iterable
Traceback (most recent call last):
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/site-packages/chainlit/utils.py", line 44, in wrapper
return await user_function(**params_values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/site-packages/chainlit/init.py", line 164, in with_parent_id
await func(message)
File "/home/nathan/Documents/Azure/azure-financebot-chainlit/main.py", line 206, in on_message
async for chunk in executor.astream(
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/site-packages/langchain/agents/agent.py", line 1789, in astream
async for step in iterator:
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/site-packages/langchain/agents/agent_iterator.py", line 266, in aiter
async for chunk in self.agent_executor._aiter_next_step(
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/site-packages/langchain/agents/agent.py", line 1535, in _aiter_next_step
result = await asyncio.gather(
^^^^^^^^^^^^^^^^^^^^^
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/asyncio/tasks.py", line 349, in __wakeup
future.result()
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/asyncio/tasks.py", line 277, in __step
result = coro.send(None)
^^^^^^^^^^^^^^^
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/site-packages/langchain/agents/agent.py", line 1568, in _aperform_agent_action
observation = await tool.arun(
^^^^^^^^^^^^^^^^
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/site-packages/langchain_core/tools.py", line 737, in arun
raise error_to_raise
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/site-packages/langchain_core/tools.py", line 704, in arun
response = await asyncio.create_task(coro, context=context) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/asyncio/futures.py", line 287, in await
yield self # This tells Task to wait for completion.
^^^^^^^^^^
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/asyncio/tasks.py", line 349, in __wakeup
future.result()
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/asyncio/futures.py", line 203, in result
raise self._exception.with_traceback(self._exception_tb)
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/asyncio/tasks.py", line 277, in __step
result = coro.send(None)
^^^^^^^^^^^^^^^
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/site-packages/langchain_core/tools.py", line 829, in _arun
return await self.coroutine(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/site-packages/langchain_core/tools.py", line 1307, in _aget_relevant_documents
docs = await retriever.ainvoke(query, config={"callbacks": callbacks})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/site-packages/langchain_core/retrievers.py", line 314, in ainvoke
raise e
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/site-packages/langchain_core/retrievers.py", line 307, in ainvoke
result = await self._aget_relevant_documents(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/site-packages/langchain_community/vectorstores/azuresearch.py", line 1595, in _aget_relevant_documents
docs = await self.vectorstore.ahybrid_search(query, k=self.k, **params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/site-packages/langchain_community/vectorstores/azuresearch.py", line 853, in ahybrid_search
docs_and_scores = await self.ahybrid_search_with_score(query, k=k, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/site-packages/langchain_community/vectorstores/azuresearch.py", line 900, in ahybrid_search_with_score
return _results_to_documents(results)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nathan/miniconda3/envs/langserve-azure/lib/python3.11/site-packages/langchain_community/vectorstores/azuresearch.py", line 1622, in _results_to_documents
docs = [
^
TypeError: 'AsyncSearchItemPaged' object is not iterable
System Info
langchain==0.2.13
langchain-chroma==0.1.2
langchain-cli==0.0.29
langchain-community==0.2.12
langchain-core==0.2.30
langchain-openai==0.1.21
langchain-text-splitters==0.2.2
langchainhub==0.1.21
Python 3.12
Beta Was this translation helpful? Give feedback.
All reactions