Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vertexai] Fix Datastore error on indexing large fields #558

Merged
merged 9 commits into from
Oct 29, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def __init__(
kind: str = "document_id",
text_property_name: str = "text",
metadata_property_name: str = "metadata",
exclude_from_indexes: List[str] = [],
lspataroG marked this conversation as resolved.
Show resolved Hide resolved
) -> None:
"""Constructor.
Args:
Expand All @@ -244,6 +245,7 @@ def __init__(
self._client = datastore_client
self._text_property_name = text_property_name
self._metadata_property_name = metadata_property_name
self.exclude_from_indexes = exclude_from_indexes
self._kind = kind

def mget(self, keys: Sequence[str]) -> List[Optional[Document]]:
Expand Down Expand Up @@ -289,7 +291,9 @@ def mset(self, key_value_pairs: Sequence[Tuple[str, Document]]) -> None:

entities = []
for key, document in zip(keys, documents):
entity = self._client.entity(key=key)
entity = self._client.entity(
key=key, exclude_from_indexes=self.exclude_from_indexes
)
entity[self._text_property_name] = document.page_content
entity[self._metadata_property_name] = document.metadata
entities.append(entity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ def from_components(
datastore_kind: str = "document_id",
datastore_text_property_name: str = "text",
datastore_metadata_property_name: str = "metadata",
exclude_from_indexes: List[str] = [],
lspataroG marked this conversation as resolved.
Show resolved Hide resolved
**kwargs: Dict[str, Any],
) -> "VectorSearchVectorStoreDatastore":
"""Takes the object creation out of the constructor.
Expand All @@ -399,6 +400,7 @@ def from_components(
index must be compatible with stream/batch updates.
kwargs: Additional keyword arguments to pass to
VertexAIVectorSearch.__init__().
exclude_from_indexes: Fields to exclude from datastore indexing

Returns:
A configured VectorSearchVectorStoreDatastore.
Expand Down Expand Up @@ -430,6 +432,7 @@ def from_components(
kind=datastore_kind,
text_property_name=datastore_text_property_name,
metadata_property_name=datastore_metadata_property_name,
exclude_from_indexes=exclude_from_indexes,
)

return cls(
Expand Down
Loading