You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question and didn't find it.
I am sure that this is a bug in LangChain rather than my code.
The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.
Example Code
The following code reproduces the error:
importos#change for your detailsos.environ["AZURE_AI_SEARCH_SERVICE_NAME"] ="service_name"os.environ["AZURE_AI_SEARCH_INDEX_NAME"] ="index_name"os.environ["AZURE_AI_SEARCH_API_KEY"] ="your-api-key"os.environ["AZURE_AI_SEARCH_ENDPOINT"] ="your-endpoint"fromlangchain_community.retrieversimportAzureAISearchRetrieverretriever=AzureAISearchRetriever(
content_key="content",
top_k=10,
index_name="your-index",
service_name="your-service",
)
retriever.invoke("What is the capital of France?")
Error Message and Stack Trace (if applicable)
Exception Traceback (most recent call last)
Cell In[40], line 1
----> 1 retriever.invoke("What is the capital of France?")
File ~/Documents/coding/agentic-frameworks/langchain-demo/.venv/lib/python3.13/site-packages/langchain_core/retrievers.py:258, in BaseRetriever.invoke(self, input, config, **kwargs)
256 _kwargs = kwargs if self._expects_other_args else {}
257 if self._new_arg_supported:
--> 258 result = self._get_relevant_documents(
259 input, run_manager=run_manager, **_kwargs
260 )
261 else:
262 result = self._get_relevant_documents(input, **_kwargs)
File ~/Documents/coding/agentic-frameworks/langchain-demo/.venv/lib/python3.13/site-packages/langchain_community/retrievers/azure_ai_search.py:206, in AzureAISearchRetriever._get_relevant_documents(self, query, run_manager)
203 def _get_relevant_documents(
204 self, query: str, *, run_manager: CallbackManagerForRetrieverRun
205 ) -> List[Document]:
--> 206 search_results = self._search(query)
208 return [
209 Document(page_content=result.pop(self.content_key), metadata=result)
210 for result in search_results
211 ]
File :6, in _search(self, query)
Exception: Error in search request: <Response [403]>
Description
I am trying to use the AzureAISearchRetriever from langchain_community.retrievers on langchain-community
When I want to authenticate with api-key, I get a 403 error, I traced back the error to this line:
I experienced this issue as well, same versions as described above. If you don't want to modify the code in langchain, a quick workaround can be to set some abitrary value for the "azure_ad_token" argument. Like this:
Hi! I'm working on this issue as part of my university open-source contribution project. I plan to submit a PR shortly. Please let me know if there's anything I should consider before proceeding. Thanks!
ccurme
transferred this issue from langchain-ai/langchain
May 5, 2025
Uh oh!
There was an error while loading. Please reload this page.
Checked other resources
Example Code
The following code reproduces the error:
Error Message and Stack Trace (if applicable)
Exception Traceback (most recent call last)
Cell In[40], line 1
----> 1 retriever.invoke("What is the capital of France?")
File ~/Documents/coding/agentic-frameworks/langchain-demo/.venv/lib/python3.13/site-packages/langchain_core/retrievers.py:258, in BaseRetriever.invoke(self, input, config, **kwargs)
256 _kwargs = kwargs if self._expects_other_args else {}
257 if self._new_arg_supported:
--> 258 result = self._get_relevant_documents(
259 input, run_manager=run_manager, **_kwargs
260 )
261 else:
262 result = self._get_relevant_documents(input, **_kwargs)
File ~/Documents/coding/agentic-frameworks/langchain-demo/.venv/lib/python3.13/site-packages/langchain_community/retrievers/azure_ai_search.py:206, in AzureAISearchRetriever._get_relevant_documents(self, query, run_manager)
203 def _get_relevant_documents(
204 self, query: str, *, run_manager: CallbackManagerForRetrieverRun
205 ) -> List[Document]:
--> 206 search_results = self._search(query)
208 return [
209 Document(page_content=result.pop(self.content_key), metadata=result)
210 for result in search_results
211 ]
File :6, in _search(self, query)
Exception: Error in search request: <Response [403]>
Description
I am trying to use the AzureAISearchRetriever from langchain_community.retrievers on langchain-community
When I want to authenticate with api-key, I get a 403 error, I traced back the error to this line:
I modified the code as mentioned in this issue:
langchain-ai/langchain@68d16d8#r155860761
And I was able to authenticate with api_key.
System Info
The text was updated successfully, but these errors were encountered: