Skip to content

Commit

Permalink
fixed incompatible typing python 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
lspataroG committed Dec 3, 2024
1 parent a8df3a8 commit 1211f60
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
16 changes: 12 additions & 4 deletions libs/vertexai/langchain_google_vertexai/vectorstores/_searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def find_neighbors(
filter_: Union[List[Namespace], None] = None,
numeric_filter: Union[List[NumericNamespace], None] = None,
*,
sparse_embeddings: Optional[List[Dict[str, List[int] | List[float]]]] = None,
sparse_embeddings: Optional[
List[Dict[str, Union[List[int], List[float]]]]
] = None,
rrf_ranking_alpha: float = 1,
) -> List[List[Dict[str, Any]]]:
"""Finds the k closes neighbors of each instance of embeddings.
Expand Down Expand Up @@ -70,7 +72,9 @@ def add_to_index(
metadatas: Union[List[dict], None] = None,
is_complete_overwrite: bool = False,
*,
sparse_embeddings: Optional[List[Dict[str, List[int] | List[float]]]] = None,
sparse_embeddings: Optional[
List[Dict[str, Union[List[int], List[float]]]]
] = None,
**kwargs: Any,
) -> None:
"""Adds documents to the index.
Expand Down Expand Up @@ -191,7 +195,9 @@ def add_to_index(
metadatas: Union[List[dict], None] = None,
is_complete_overwrite: bool = False,
*,
sparse_embeddings: Optional[List[Dict[str, List[int] | List[float]]]] = None,
sparse_embeddings: Optional[
List[Dict[str, Union[List[int], List[float]]]]
] = None,
**kwargs: Any,
) -> None:
"""Adds documents to the index.
Expand Down Expand Up @@ -233,7 +239,9 @@ def find_neighbors(
filter_: Union[List[Namespace], None] = None,
numeric_filter: Union[List[NumericNamespace], None] = None,
*,
sparse_embeddings: Optional[List[Dict[str, List[int] | List[float]]]] = None,
sparse_embeddings: Optional[
List[Dict[str, Union[List[int], List[float]]]]
] = None,
rrf_ranking_alpha: float = 1,
) -> List[List[Dict[str, Any]]]:
"""Finds the k closes neighbors of each instance of embeddings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def batch_update_index(
def to_data_points(
ids: List[str],
embeddings: List[List[float]],
sparse_embeddings: Optional[List[Dict[str, List[int] | List[float]]]] = None,
sparse_embeddings: Optional[List[Dict[str, Union[List[int], List[float]]]]] = None,
metadatas: Union[List[Dict[str, Any]], None] = None,
) -> List["meidx_types.IndexDataPoint"]:
"""Converts triplets id, embedding, metadata into IndexDataPoints instances.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ def add_texts_with_embeddings(
embeddings: List[List[float]],
metadatas: Union[List[dict], None] = None,
*,
sparse_embeddings: Optional[List[Dict[str, List[int] | List[float]]]] = None,
sparse_embeddings: Optional[
List[Dict[str, Union[List[int], List[float]]]]
] = None,
ids: Optional[List[str]] = None,
is_complete_overwrite: bool = False,
**kwargs: Any,
Expand Down
6 changes: 3 additions & 3 deletions libs/vertexai/tests/integration_tests/test_vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""

import os
from typing import Dict, List
from typing import Dict, List, Union
from uuid import uuid4

import pytest
Expand Down Expand Up @@ -280,7 +280,7 @@ def test_vector_store_hybrid_search(

query = "What are your favourite animals?"
embedding = embeddings.embed_query(query)
sparse_embedding: Dict[str, List[int] | List[float]] = {
sparse_embedding: Dict[str, Union[List[int], List[float]]] = {
"values": [0.5, 0.7],
"dimensions": [2, 4],
}
Expand Down Expand Up @@ -317,7 +317,7 @@ def test_add_texts_with_embeddings(
)
assert len(ids1) == 2

sparse_embeddings: List[Dict[str, List[int] | List[float]]] = [
sparse_embeddings: List[Dict[str, Union[List[int], List[float]]]] = [
{"values": [0.5, 0.7], "dimensions": [2, 4]}
] * 2
ids2 = vector_store.add_texts_with_embeddings(
Expand Down
6 changes: 3 additions & 3 deletions libs/vertexai/tests/unit_tests/test_vectorstores.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, List
from typing import Dict, List, Union
from unittest.mock import MagicMock

import pytest
Expand All @@ -11,7 +11,7 @@
def test_to_data_points():
ids = ["Id1"]
embeddings = [[0.0, 0.0]]
sparse_embeddings: List[Dict[str, List[int] | List[float]]] = [
sparse_embeddings: List[Dict[str, Union[List[int], List[float]]]] = [
{"values": [0.9, 0.3], "dimensions": [3, 20]}
]
metadatas = [
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_add_texts_with_embeddings():

def test_similarity_search_by_vector_with_score_output_shape():
embedding = [0.0, 0.5, 0.8]
sparse_embedding: Dict[str, List[int] | List[float]] = {
sparse_embedding: Dict[str, Union[List[int], List[float]]] = {
"values": [0.9, 0.3],
"dimensions": [3, 20],
}
Expand Down

0 comments on commit 1211f60

Please sign in to comment.