Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
masci committed Dec 6, 2023
1 parent 5de94f9 commit 414fb98
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,17 @@ def run(self, documents: List[Document]):
:param documents: A list of Documents to embed.
"""

if not isinstance(documents, list) or not isinstance(documents[0], Document):
if not isinstance(documents, list) or documents and not isinstance(documents[0], Document):
msg = (
"CohereDocumentEmbedder expects a list of Documents as input."
"In case you want to embed a string, please use the CohereTextEmbedder."
)
raise TypeError(msg)

if not documents:
# return early if we were passed an empty list
return {"documents": [], "metadata": {}}

texts_to_embed = self._prepare_texts_to_embed(documents)

if self.use_async_client:
Expand Down
9 changes: 4 additions & 5 deletions integrations/cohere/tests/test_document_embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,9 @@ def test_run(self):
def test_run_wrong_input_format(self):
embedder = CohereDocumentEmbedder(api_key="test-api-key")

string_input = "text"
list_integers_input = [1, 2, 3]

with pytest.raises(TypeError, match="CohereDocumentEmbedder expects a list of Documents as input"):
embedder.run(documents=string_input)
embedder.run(documents="text")
with pytest.raises(TypeError, match="CohereDocumentEmbedder expects a list of Documents as input"):
embedder.run(documents=list_integers_input)
embedder.run(documents=[1, 2, 3])

assert embedder.run(documents=[]) == {"documents": [], "metadata": {}}

0 comments on commit 414fb98

Please sign in to comment.