From 3fb9667c7713a6c22235b02b6d5d65a60be7dbc5 Mon Sep 17 00:00:00 2001 From: Amanda Rozi Kurnia <71978223+yoursemicolon@users.noreply.github.com> Date: Thu, 23 May 2024 10:39:17 +0700 Subject: [PATCH] fix: enforce attribute validation in VertexAISearchRetriever (#246) Co-authored-by: Amanda --- .../langchain_google_community/vertex_ai_search.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/community/langchain_google_community/vertex_ai_search.py b/libs/community/langchain_google_community/vertex_ai_search.py index 04e0425e..b5321e66 100644 --- a/libs/community/langchain_google_community/vertex_ai_search.py +++ b/libs/community/langchain_google_community/vertex_ai_search.py @@ -252,7 +252,7 @@ class VertexAISearchRetriever(BaseRetriever, _BaseVertexAISearchRetriever): class Config: """Configuration for this pydantic object.""" - extra = Extra.ignore + extra = Extra.forbid arbitrary_types_allowed = True underscore_attrs_are_private = True @@ -267,7 +267,11 @@ def __init__(self, **kwargs: Any) -> None: "`pip install langchain-google-community[vertexaisearch]`" ) from exc - super().__init__(**kwargs) + try: + super().__init__(**kwargs) + except ValueError as e: + print(f"Error initializing GoogleVertexAISearchRetriever: {str(e)}") + raise # For more information, refer to: # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store