WeaviateEx.Batch.FixedSize (WeaviateEx v0.7.4)
View SourceFixed-size batch processor for Weaviate batch operations.
Collects objects into a buffer and splits them into fixed-size batches for sending to Weaviate.
Examples
# Create a batcher with batch size of 100
batcher = FixedSize.new(batch_size: 100)
# Add objects
batcher =
batcher
|> FixedSize.add_object("Article", %{title: "Article 1"})
|> FixedSize.add_object("Article", %{title: "Article 2"})
# Get batches for sending
batches = FixedSize.get_batches(batcher)
# Send each batch
Enum.each(batches, fn batch ->
WeaviateEx.Batch.create_objects(client, batch)
end)
Summary
Functions
Add an object to the batch buffer.
Add a reference to the batch buffer.
Get the number of objects currently in the buffer.
Clear the object buffer.
Get batches of objects from the buffer.
Get batches of references from the buffer.
Create a new fixed-size batcher.
Check if the buffer has reached the batch size threshold.
Get the number of references currently in the buffer.
Types
@type t() :: %WeaviateEx.Batch.FixedSize{ batch_size: pos_integer(), concurrent_requests: pos_integer(), objects_buffer: [batch_object()], references_buffer: [map()] }
Functions
Add an object to the batch buffer.
UUID is auto-generated if not provided.
Options
:uuid- Custom UUID for the object (auto-generated if not provided):vector- Custom vector for the object:tenant- Tenant name for multi-tenant collections
Examples
# Auto-generate UUID
batcher
|> FixedSize.add_object("Article", %{title: "Test"})
# With explicit UUID
batcher
|> FixedSize.add_object("Article", %{title: "Test 2"}, uuid: "custom-uuid")
# Deterministic UUID from value
uuid = WeaviateEx.Types.UUID.from_string("Article", "unique-id")
batcher
|> FixedSize.add_object("Article", %{title: "Test"}, uuid: uuid)
@spec add_reference( t(), String.t(), String.t(), String.t(), String.t() | [map()], keyword() ) :: t()
Add a reference to the batch buffer.
Supports both single-target and multi-target references.
Single Target
batcher
|> FixedSize.add_reference("Article", "uuid-1", "hasAuthor", "uuid-2")Multi-Target References
batcher
|> FixedSize.add_reference("Article", "uuid-1", "relatedTo", [
%{collection: "Article", uuid: "related-uuid-1"},
%{collection: "Video", uuid: "video-uuid-1"}
])Options
:tenant- Tenant name for multi-tenant collections
@spec buffer_size(t()) :: non_neg_integer()
Get the number of objects currently in the buffer.
Clear the object buffer.
@spec get_batches(t()) :: [[batch_object()]]
Get batches of objects from the buffer.
Returns a list of batches, each containing up to batch_size objects.
The buffer order is preserved (first added = first in batch).
Get batches of references from the buffer.
Create a new fixed-size batcher.
Options
:batch_size- Number of objects per batch (default: 100):concurrent_requests- Number of concurrent requests (default: 2)
Examples
FixedSize.new()
FixedSize.new(batch_size: 50, concurrent_requests: 4)
Check if the buffer has reached the batch size threshold.
@spec reference_buffer_size(t()) :: non_neg_integer()
Get the number of references currently in the buffer.