Skip to content

When passing api_key and not ad_token, condition takes the empty string of the ad token instead of apo_key #33

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

Open
5 tasks done
erne2086 opened this issue Apr 25, 2025 · 4 comments

Comments

@erne2086
Copy link

erne2086 commented Apr 25, 2025

Checked other resources

  • I added a very descriptive title to this issue.
  • 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:

import os
#change for your details
os.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"

from langchain_community.retrievers import AzureAISearchRetriever

retriever = 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 modified the code as mentioned in this issue:

langchain-ai/langchain@68d16d8#r155860761

And I was able to authenticate with api_key.

System Info

uv pip show langchain-community
Name: langchain-community
Version: 0.3.22
Location: /Users/ejcv/Documents/coding/agentic-frameworks/langchain-demo/.venv/lib/python3.13/site-packages
Requires: aiohttp, dataclasses-json, httpx-sse, langchain, langchain-core, langsmith, numpy, pydantic-settings, pyyaml, requests, sqlalchemy, tenacity
Required-by:
uv pip show langchain          
Name: langchain
Version: 0.3.24
Location: /Users/ejcv/Documents/coding/agentic-frameworks/langchain-demo/.venv/lib/python3.13/site-packages
Requires: langchain-core, langchain-text-splitters, langsmith, pydantic, pyyaml, requests, sqlalchemy
Required-by: langchain-community
@kavinkumar807
Copy link

@erne2086 will check with this

@tol-dawn
Copy link

tol-dawn commented May 1, 2025

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:

retriever = AzureAISearchRetriever(
                content_key="content",
                top_k=3,
                index_name=search_index_name,
                service_name=ai_search_endpoint,
                azure_ad_token="True")

@Satya-Indukuri
Copy link
Contributor

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 ccurme transferred this issue from langchain-ai/langchain May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants