Skip to content
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

Azure AI Search Client Component Calling get_index function twice #29437

Open
5 tasks done
msetbar opened this issue Jan 27, 2025 · 2 comments
Open
5 tasks done

Azure AI Search Client Component Calling get_index function twice #29437

msetbar opened this issue Jan 27, 2025 · 2 comments
Labels
Ɑ: vector store Related to vector store module

Comments

@msetbar
Copy link
Contributor

msetbar commented Jan 27, 2025

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • 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).

Example Code

We have the following code:

openai_api_key: str = "PLACEHOLDER FOR YOUR API KEY"
openai_api_version: str = "2023-05-15"
model: str = "text-embedding-ada-002"

azure_endpoint: str = "PLACEHOLDER FOR YOUR AZURE OPENAI ENDPOINT"
azure_openai_api_key: str = "PLACEHOLDER FOR YOUR AZURE OPENAI KEY"
azure_openai_api_version: str = "2023-05-15"
azure_deployment: str = "text-embedding-ada-002"

vector_store_address: str = "YOUR_AZURE_SEARCH_ENDPOINT"
vector_store_password: str = "YOUR_AZURE_SEARCH_ADMIN_KEY"

embeddings: AzureOpenAIEmbeddings = AzureOpenAIEmbeddings(
    azure_deployment=azure_deployment,
    openai_api_version=azure_openai_api_version,
    azure_endpoint=azure_endpoint,
    api_key=azure_openai_api_key,
)

vector_store: AzureSearch = AzureSearch(
    azure_search_endpoint=vector_store_address,
    azure_search_key=vector_store_password,
    index_name=index_name,
    embedding_function=embeddings.embed_query,
    # Configure max retries for the Azure client
    additional_search_client_options={"retry_total": 4},
)

docs = vector_store.similarity_search(
    query="What did the president say about Ketanji Brown Jackson",
    k=3,
    search_type="similarity",
)
print(docs[0].page_content)

In AzureSearch, get_index function is called twice which is not needed. One is called for intialization of client and the second time is called for the intialization of client_async. Please check this line: https://github.com/langchain-ai/langchain/blob/master/libs/community/langchain_community/vectorstores/azuresearch.py#L361

Error Message and Stack Trace (if applicable)

It is just adding up a latency to AzureSearch component since it is called get_index function twice.

Description

I am trying to use LangChain to integrate with Azure AI Search and noticed that get_index function is getting called twice when trying to intialize AzureSearch.

System Info

System Information

OS: Linux
OS Version: #1 SMP PREEMPT Thu Jun 30 08:18:26 UTC 2022
Python Version: 3.10.14 (main, Jul 2 2024, 22:06:13) [GCC 12.2.0]

Package Information

langchain_core: 0.3.31
langchain: 0.3.15
langchain_community: 0.3.15
langsmith: 0.3.2
langchain_text_splitters: 0.3.5

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.11.11
async-timeout: 4.0.3
dataclasses-json: 0.6.7
httpx: 0.27.2
httpx-sse: 0.4.0
jsonpatch: 1.33
langsmith-pyo3: Installed. No version info available.
numpy: 1.26.4
orjson: 3.10.15
packaging: 24.1
pydantic: 2.10.4
pydantic-settings: 2.7.1
pytest: Installed. No version info available.
PyYAML: 6.0.1
requests: 2.32.3
requests-toolbelt: 1.0.0
rich: 13.9.4
SQLAlchemy: 2.0.36
tenacity: 9.0.0
typing-extensions: 4.12.2
zstandard: 0.23.0

@dosubot dosubot bot added the Ɑ: vector store Related to vector store module label Jan 27, 2025
@msetbar msetbar changed the title Azure AI Search Client Component Calling get_index function twicec\ Azure AI Search Client Component Calling get_index function twice Jan 27, 2025
@keenborder786
Copy link
Contributor

@msetbar one is for client and one is for async_client

@hrishi-008
Copy link
Contributor

Async should be instantiated if async_ is set to true in **kwargs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ɑ: vector store Related to vector store module
Projects
None yet
Development

No branches or pull requests

3 participants