From 11cf22dc0418a24ed1a0e5c2ed019b59b387c493 Mon Sep 17 00:00:00 2001 From: lspataroG <167472995+lspataroG@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:50:00 +0100 Subject: [PATCH 1/4] fixed BQ vector search batch_search (#629) --- .../bq_storage_vectorstores/bigquery.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/community/langchain_google_community/bq_storage_vectorstores/bigquery.py b/libs/community/langchain_google_community/bq_storage_vectorstores/bigquery.py index b28a1da8..fa41473b 100644 --- a/libs/community/langchain_google_community/bq_storage_vectorstores/bigquery.py +++ b/libs/community/langchain_google_community/bq_storage_vectorstores/bigquery.py @@ -301,7 +301,7 @@ def _create_search_query( if table_to_query is not None: embeddings_query = f""" with embeddings as ( - SELECT {self.embedding_field}, ROW_NUMBER() OVER() as row_num + SELECT {self.embedding_field}, row_num from `{table_to_query}` )""" @@ -390,6 +390,7 @@ def _create_temp_bq_table( df = pd.DataFrame([]) df[self.embedding_field] = embeddings + df["row_num"] = list(range(len(df))) table_id = ( f"{self.project_id}." f"{self.temp_dataset_name}." @@ -397,7 +398,8 @@ def _create_temp_bq_table( ) schema = [ - bigquery.SchemaField(self.embedding_field, "FLOAT64", mode="REPEATED") + bigquery.SchemaField(self.embedding_field, "FLOAT64", mode="REPEATED"), + bigquery.SchemaField("row_num", "INT64"), ] table_ref = bigquery.Table(table_id, schema=schema) table = self._bq_client.create_table(table_ref) @@ -483,7 +485,7 @@ def batch_search( ) if queries is not None: - embeddings = self.embedding.embed_documents(queries) + embeddings = [self.embedding.embed_query(query) for query in queries] if embeddings is None: raise ValueError("Could not obtain embeddings - value is None.") From d71155d4250e28124680b7b5944be7a1350a8f5c Mon Sep 17 00:00:00 2001 From: Leonid Kuligin Date: Thu, 12 Dec 2024 13:56:41 +0100 Subject: [PATCH 2/4] release 2.0.7 (#643) --- libs/genai/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/genai/pyproject.toml b/libs/genai/pyproject.toml index 3bd5caab..561e65f3 100644 --- a/libs/genai/pyproject.toml +++ b/libs/genai/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "langchain-google-genai" -version = "2.0.6" +version = "2.0.7" description = "An integration package connecting Google's genai package and LangChain" authors = [] readme = "README.md" From dbad3b8c9bbe33671f18ef86612d2bfd46ad959b Mon Sep 17 00:00:00 2001 From: Leonid Kuligin Date: Thu, 12 Dec 2024 15:00:36 +0100 Subject: [PATCH 3/4] enabled tool support for gemini2 (#640) --- .../langchain_google_genai/chat_models.py | 6 +++- .../tests/integration_tests/test_standard.py | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/libs/genai/langchain_google_genai/chat_models.py b/libs/genai/langchain_google_genai/chat_models.py index 45ad1cec..086fa23e 100644 --- a/libs/genai/langchain_google_genai/chat_models.py +++ b/libs/genai/langchain_google_genai/chat_models.py @@ -1374,7 +1374,11 @@ def create_cached_content( @property def _supports_tool_choice(self) -> bool: - return "gemini-1.5-pro" in self.model or "gemini-1.5-flash" in self.model + return ( + "gemini-1.5-pro" in self.model + or "gemini-1.5-flash" in self.model + or "gemini-2" in self.model + ) def _get_tool_name( diff --git a/libs/genai/tests/integration_tests/test_standard.py b/libs/genai/tests/integration_tests/test_standard.py index e8feaee9..a5a7d230 100644 --- a/libs/genai/tests/integration_tests/test_standard.py +++ b/libs/genai/tests/integration_tests/test_standard.py @@ -11,6 +11,36 @@ from langchain_google_genai import ChatGoogleGenerativeAI rate_limiter = InMemoryRateLimiter(requests_per_second=0.25) +rate_limiter_2_0 = InMemoryRateLimiter(requests_per_second=0.1) + + +class TestGeminiAI2Standard(ChatModelIntegrationTests): + @property + def chat_model_class(self) -> Type[BaseChatModel]: + return ChatGoogleGenerativeAI + + @property + def chat_model_params(self) -> dict: + return { + "model": "models/gemini-2.0-flash-exp", + "rate_limiter": rate_limiter_2_0, + } + + @pytest.mark.xfail(reason="with_structured_output with JSON schema not supported.") + async def test_structured_output_async(self, model: BaseChatModel) -> None: + await super().test_structured_output_async(model) + + @pytest.mark.xfail(reason="with_structured_output with JSON schema not supported.") + def test_structured_output(self, model: BaseChatModel) -> None: + super().test_structured_output(model) + + @pytest.mark.xfail(reason="with_structured_output with JSON schema not supported.") + def test_structured_output_pydantic_2_v1(self, model: BaseChatModel) -> None: + super().test_structured_output_pydantic_2_v1(model) + + @pytest.mark.xfail(reason="investigate") + def test_bind_runnables_as_tools(self, model: BaseChatModel) -> None: + super().test_bind_runnables_as_tools(model) class TestGeminiAIStandard(ChatModelIntegrationTests): From 8c569edcab6b48f3f57390ded48f1af2e75eac8b Mon Sep 17 00:00:00 2001 From: Elizabeth Wu Date: Mon, 16 Dec 2024 23:56:00 +1100 Subject: [PATCH 4/4] Update featurestore.py (#624) Updated to include numeric_filters. --- .../bq_storage_vectorstores/featurestore.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/community/langchain_google_community/bq_storage_vectorstores/featurestore.py b/libs/community/langchain_google_community/bq_storage_vectorstores/featurestore.py index 47dd5766..7f5eb388 100644 --- a/libs/community/langchain_google_community/bq_storage_vectorstores/featurestore.py +++ b/libs/community/langchain_google_community/bq_storage_vectorstores/featurestore.py @@ -421,6 +421,7 @@ def _search_embedding( entity_id: Optional[str] = None, k: int = 5, string_filters: Optional[List[dict]] = None, + numeric_filters: Optional[List[dict]] = None, per_crowding_attribute_neighbor_count: Optional[int] = None, approximate_neighbor_candidates: Optional[int] = None, leaf_nodes_search_fraction: Optional[float] = None, @@ -438,6 +439,7 @@ def _search_embedding( embedding=embedding, neighbor_count=k, string_filters=string_filters, + numeric_filters=numeric_filters, per_crowding_attribute_neighbor_count=per_crowding_attribute_neighbor_count, parameters={ "approximate_neighbor_candidates": approximate_neighbor_candidates,