mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-20 05:43:55 +00:00
Added consistent timeout for Vectara calls (#8892)
- Description: consistent timeout at 60s for all calls to Vectara API - Tag maintainer: @rlancemartin, @eyurtsev --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
parent
642b57c7ff
commit
a7824f16f2
@ -39,6 +39,7 @@ class Vectara(VectorStore):
|
|||||||
vectara_customer_id: Optional[str] = None,
|
vectara_customer_id: Optional[str] = None,
|
||||||
vectara_corpus_id: Optional[str] = None,
|
vectara_corpus_id: Optional[str] = None,
|
||||||
vectara_api_key: Optional[str] = None,
|
vectara_api_key: Optional[str] = None,
|
||||||
|
vectara_api_timeout: int = 60,
|
||||||
):
|
):
|
||||||
"""Initialize with Vectara API."""
|
"""Initialize with Vectara API."""
|
||||||
self._vectara_customer_id = vectara_customer_id or os.environ.get(
|
self._vectara_customer_id = vectara_customer_id or os.environ.get(
|
||||||
@ -62,6 +63,7 @@ class Vectara(VectorStore):
|
|||||||
self._session = requests.Session() # to reuse connections
|
self._session = requests.Session() # to reuse connections
|
||||||
adapter = requests.adapters.HTTPAdapter(max_retries=3)
|
adapter = requests.adapters.HTTPAdapter(max_retries=3)
|
||||||
self._session.mount("http://", adapter)
|
self._session.mount("http://", adapter)
|
||||||
|
self.vectara_api_timeout = vectara_api_timeout
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def embeddings(self) -> Optional[Embeddings]:
|
def embeddings(self) -> Optional[Embeddings]:
|
||||||
@ -96,6 +98,7 @@ class Vectara(VectorStore):
|
|||||||
data=json.dumps(body),
|
data=json.dumps(body),
|
||||||
verify=True,
|
verify=True,
|
||||||
headers=self._get_post_headers(),
|
headers=self._get_post_headers(),
|
||||||
|
timeout=self.vectara_api_timeout,
|
||||||
)
|
)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
logger.error(
|
logger.error(
|
||||||
@ -116,7 +119,7 @@ class Vectara(VectorStore):
|
|||||||
headers=self._get_post_headers(),
|
headers=self._get_post_headers(),
|
||||||
url="https://api.vectara.io/v1/core/index",
|
url="https://api.vectara.io/v1/core/index",
|
||||||
data=json.dumps(request),
|
data=json.dumps(request),
|
||||||
timeout=30,
|
timeout=self.vectara_api_timeout,
|
||||||
verify=True,
|
verify=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -168,6 +171,7 @@ class Vectara(VectorStore):
|
|||||||
files=files,
|
files=files,
|
||||||
verify=True,
|
verify=True,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
|
timeout=self.vectara_api_timeout,
|
||||||
)
|
)
|
||||||
|
|
||||||
if response.status_code == 409:
|
if response.status_code == 409:
|
||||||
@ -288,7 +292,7 @@ class Vectara(VectorStore):
|
|||||||
headers=self._get_post_headers(),
|
headers=self._get_post_headers(),
|
||||||
url="https://api.vectara.io/v1/query",
|
url="https://api.vectara.io/v1/query",
|
||||||
data=data,
|
data=data,
|
||||||
timeout=10,
|
timeout=self.vectara_api_timeout,
|
||||||
)
|
)
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
|
Loading…
Reference in New Issue
Block a user