Skip to content

Commit e3cc304

Browse files
marcgibbonsccurme
andauthored
vectorstores[azure_search]: fix regression in 0.3.24 (#77)
Co-authored-by: Chester Curme <[email protected]>
1 parent 72fb093 commit e3cc304

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

libs/community/langchain_community/vectorstores/azuresearch.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import asyncio
44
import base64
5+
import copy
56
import itertools
67
import json
78
import logging
@@ -375,7 +376,9 @@ def __init__(
375376
default_fields=default_fields,
376377
user_agent=user_agent,
377378
cors_options=cors_options,
378-
additional_search_client_options=additional_search_client_options,
379+
additional_search_client_options=copy.deepcopy(
380+
additional_search_client_options
381+
),
379382
azure_credential=azure_credential,
380383
)
381384

libs/community/tests/unit_tests/vectorstores/test_azure_search.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from unittest.mock import patch
44

55
import pytest
6+
from pytest_socket import SocketBlockedError
67

78
from langchain_community.vectorstores.azuresearch import AzureSearch
89
from tests.integration_tests.vectorstores.fake_embeddings import FakeEmbeddings
@@ -192,6 +193,40 @@ def mock_create_index() -> None:
192193
assert vector_store.client._api_version == "test"
193194

194195

196+
@pytest.mark.requires("azure.search.documents")
197+
def test_additional_search_options_retry_policy() -> None:
198+
"""
199+
Reproduces bug captured in:
200+
https://github.com/langchain-ai/langchain-community/issues/76
201+
"""
202+
from azure.core.exceptions import HttpResponseError
203+
from azure.core.pipeline.policies import RetryPolicy
204+
from azure.search.documents.indexes import SearchIndexClient
205+
206+
def mock_create_index() -> None:
207+
pytest.fail("Should not create index in this test")
208+
209+
with patch.multiple(
210+
SearchIndexClient, get_index=mock_default_index, create_index=mock_create_index
211+
):
212+
vector_store = create_vector_store(
213+
additional_search_client_options={
214+
"retry_policy": RetryPolicy(
215+
total_retries=3,
216+
backoff_factor=0.5,
217+
timeout=5,
218+
),
219+
}
220+
)
221+
assert vector_store.client is not None
222+
223+
# Bug previously raised an:
224+
# AttributeError: 'coroutine' object has no attribute 'http_response'.
225+
# Expect a network connection to be made (and blocked).
226+
with pytest.raises((HttpResponseError, SocketBlockedError)):
227+
list(vector_store.client.search())
228+
229+
195230
@pytest.mark.requires("azure.search.documents")
196231
def test_ids_used_correctly() -> None:
197232
"""Check whether vector store uses the document ids when provided with them."""

0 commit comments

Comments
 (0)