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

Update bedrock.py #3462

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 11 additions & 3 deletions unstructured/embed/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,17 @@ def embed_query(self, query):
return np.array(self.bedrock_client.embed_query(query))

def embed_documents(self, elements: List[Element]) -> List[Element]:
embeddings = self.bedrock_client.embed_documents([str(e) for e in elements])
elements_with_embeddings = self._add_embeddings_to_elements(elements, embeddings)
return elements_with_embeddings
# filter out empty text
non_empty_elements = [e for e in elements if e.text.strip()]
embeddings = self.bedrock_client.embed_documents(
[str(e) for e in non_empty_elements]
)
elements_with_embeddings = self._add_embeddings_to_elements(
non_empty_elements, embeddings
)
result = elements_with_embeddings + [e for e in elements if not e.text.strip()]
return result


def _add_embeddings_to_elements(self, elements, embeddings) -> List[Element]:
assert len(elements) == len(embeddings)
Expand Down
Loading