Skip to content

Commit e38e33e

Browse files
Use Weaviate built-in client batching
1 parent 66729e7 commit e38e33e

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

engine/clients/weaviate/upload.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,20 @@ def init_client(cls, host, distance, connection_params, upload_params):
2424
def upload_batch(
2525
cls, ids: List[int], vectors: List[list], metadata: List[Optional[dict]]
2626
):
27-
try:
27+
# Weaviate introduced the batch_size, so it can handle built-in client's
28+
# multi-threading. That should make the upload faster.
29+
cls.client.batch.configure(
30+
batch_size=100,
31+
timeout_retries=3,
32+
)
33+
34+
with cls.client.batch as batch:
2835
for id_, vector, data_object in zip(ids, vectors, metadata):
29-
cls.client.batch.add_data_object(
36+
batch.add_data_object(
3037
data_object=data_object or {},
3138
class_name=WEAVIATE_CLASS_NAME,
3239
uuid=uuid.UUID(int=id_).hex,
3340
vector=vector,
3441
)
3542

36-
cls.client.batch.create_objects()
37-
except Exception as e:
38-
# It crashed unpredicsibly, so we probably need to do "try again thing"
39-
# Issue to monitor: https://github.com/semi-technologies/weaviate/issues/2066
40-
time.sleep(1)
41-
for id_, vector, data_object in zip(ids, vectors, metadata):
42-
cls.client.batch.add_data_object(
43-
data_object=data_object or {},
44-
class_name=WEAVIATE_CLASS_NAME,
45-
uuid=uuid.UUID(int=id_).hex,
46-
vector=vector,
47-
)
48-
49-
cls.client.batch.create_objects()
43+
batch.create_objects()

0 commit comments

Comments
 (0)