Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions providers/cohere/src/airflow/providers/cohere/hooks/cohere.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def create_embeddings(
embedding_types=["float"],
request_options=self.request_options,
)
# NOTE: Return type `EmbedByTypeResponseEmbeddings` was removed temporarily due to limitations
# in XCom serialization/deserialization of complex types like Cohere embeddings and Pydantic models.
#
# Tracking issue: https://github.com/apache/airflow/issues/50867
# Once that issue is resolved, XCom (de)serialization of such types will be supported and
# we can safely restore the `EmbedByTypeResponseEmbeddings` return type here.
if response.embeddings.float_ is None:
raise ValueError("Embeddings response is missing float_ field")
return response.embeddings.float_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ def hook(self) -> CohereHook:
def execute(self, context: Context) -> list[list[float]]:
"""Embed texts using Cohere embed services."""
embedding_response = self.hook.create_embeddings(self.input_text)

# Extract just the embeddings list, which is serializable
# NOTE: Return type `EmbedByTypeResponseEmbeddings` was removed temporarily due to limitations
# in XCom serialization/deserialization of complex types like Cohere embeddings and Pydantic models.
#
# Tracking issue: https://github.com/apache/airflow/issues/50867
# Once that issue is resolved, XCom (de)serialization of such types will be supported, and
# we can safely restore the `EmbedByTypeResponseEmbeddings` return type here.
return embedding_response