mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-25 08:03:39 +00:00
community[patch]: langchain_community.vectorstores.azuresearch Raise LangChainException instead of bare Exception (#23935)
Raise `LangChainException` instead of `Exception`. This alleviates the need for library users to use bare try/except to handle exceptions raised by `AzureSearch`. Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
This commit is contained in:
parent
3d16dcd88d
commit
cc451effd1
@ -29,6 +29,7 @@ from langchain_core.callbacks import (
|
|||||||
)
|
)
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
from langchain_core.embeddings import Embeddings
|
from langchain_core.embeddings import Embeddings
|
||||||
|
from langchain_core.exceptions import LangChainException
|
||||||
from langchain_core.pydantic_v1 import root_validator
|
from langchain_core.pydantic_v1 import root_validator
|
||||||
from langchain_core.retrievers import BaseRetriever
|
from langchain_core.retrievers import BaseRetriever
|
||||||
from langchain_core.utils import get_from_env
|
from langchain_core.utils import get_from_env
|
||||||
@ -463,7 +464,7 @@ class AzureSearch(VectorStore):
|
|||||||
response = self.client.upload_documents(documents=data)
|
response = self.client.upload_documents(documents=data)
|
||||||
# Check if all documents were successfully uploaded
|
# Check if all documents were successfully uploaded
|
||||||
if not all(r.succeeded for r in response):
|
if not all(r.succeeded for r in response):
|
||||||
raise Exception(response)
|
raise LangChainException(response)
|
||||||
# Reset data
|
# Reset data
|
||||||
data = []
|
data = []
|
||||||
|
|
||||||
@ -477,7 +478,7 @@ class AzureSearch(VectorStore):
|
|||||||
if all(r.succeeded for r in response):
|
if all(r.succeeded for r in response):
|
||||||
return ids
|
return ids
|
||||||
else:
|
else:
|
||||||
raise Exception(response)
|
raise LangChainException(response)
|
||||||
|
|
||||||
async def aadd_embeddings(
|
async def aadd_embeddings(
|
||||||
self,
|
self,
|
||||||
@ -521,7 +522,7 @@ class AzureSearch(VectorStore):
|
|||||||
response = await async_client.upload_documents(documents=data)
|
response = await async_client.upload_documents(documents=data)
|
||||||
# Check if all documents were successfully uploaded
|
# Check if all documents were successfully uploaded
|
||||||
if not all(r.succeeded for r in response):
|
if not all(r.succeeded for r in response):
|
||||||
raise Exception(response)
|
raise LangChainException(response)
|
||||||
# Reset data
|
# Reset data
|
||||||
data = []
|
data = []
|
||||||
|
|
||||||
@ -536,7 +537,7 @@ class AzureSearch(VectorStore):
|
|||||||
if all(r.succeeded for r in response):
|
if all(r.succeeded for r in response):
|
||||||
return ids
|
return ids
|
||||||
else:
|
else:
|
||||||
raise Exception(response)
|
raise LangChainException(response)
|
||||||
|
|
||||||
def delete(self, ids: Optional[List[str]] = None, **kwargs: Any) -> bool:
|
def delete(self, ids: Optional[List[str]] = None, **kwargs: Any) -> bool:
|
||||||
"""Delete by vector ID.
|
"""Delete by vector ID.
|
||||||
|
Loading…
Reference in New Issue
Block a user