Skip to content

Commit

Permalink
Merge branch 'main' into vector-search-hybrid
Browse files Browse the repository at this point in the history
  • Loading branch information
lspataroG authored Dec 17, 2024
2 parents 961546e + 8c569ed commit fcc7905
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
)"""

Expand Down Expand Up @@ -390,14 +390,16 @@ 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}."
f"{self.table_name}_{uuid.uuid4().hex}"
)

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)
Expand Down Expand Up @@ -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.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion libs/genai/langchain_google_genai/chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion libs/genai/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
30 changes: 30 additions & 0 deletions libs/genai/tests/integration_tests/test_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit fcc7905

Please sign in to comment.