Skip to content

Commit

Permalink
simplify documents_to_batch
Browse files Browse the repository at this point in the history
  • Loading branch information
anakin87 committed Mar 22, 2024
1 parent 9749ee0 commit 2683a74
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@ def documents_to_batch(
for document in documents:
payload = document.to_dict(flatten=False)
vector = {}
if embedding_field in payload and payload[embedding_field] is not None:
dense_vector = payload.pop(embedding_field) or []

dense_vector = payload.pop(embedding_field, None)
if dense_vector is not None:
vector[DENSE_VECTORS_NAME] = dense_vector
if (
sparse_embedding_field in payload
and payload[sparse_embedding_field] is not None
and payload[sparse_embedding_field] != ""
):
sparse_vector = payload.pop(sparse_embedding_field, {"indices": [], "values": []})

sparse_vector = payload.pop(sparse_embedding_field, None)
if sparse_vector is not None:
sparse_vector_instance = rest.SparseVector(**sparse_vector)
vector[SPARSE_VECTORS_NAME] = sparse_vector_instance

_id = self.convert_id(payload.get("id"))

point = rest.PointStruct(
Expand Down

0 comments on commit 2683a74

Please sign in to comment.