WeaviateEx.GRPC.Services.Batch (WeaviateEx v0.7.4)

View Source

gRPC Batch service for bulk operations.

This module provides high-level functions for batch insert, update, and delete operations using gRPC. Supports both unary and streaming modes.

Usage

{:ok, channel} = WeaviateEx.GRPC.Channel.connect(config)

objects = [
  %{collection: "Article", properties: %{title: "First"}},
  %{collection: "Article", properties: %{title: "Second"}}
]

{:ok, result} = Batch.insert_objects(channel, objects)

Summary

Functions

Delete multiple objects matching a filter.

Insert multiple objects in a single batch request.

Insert multiple references in a single batch request.

Parse batch result and return failure counts and errors.

Types

batch_opts()

@type batch_opts() :: [
  consistency_level: :one | :quorum | :all,
  timeout: non_neg_integer()
]

batch_ref()

@type batch_ref() :: %{
  :from_collection => String.t(),
  :from_uuid => String.t(),
  :from_property => String.t(),
  :to_uuid => String.t(),
  optional(:to_collection) => String.t(),
  optional(:tenant) => String.t()
}

object()

@type object() :: %{
  :collection => String.t(),
  :properties => map(),
  optional(:uuid) => String.t(),
  optional(:vector) => [float()],
  optional(:tenant) => String.t()
}

Functions

delete_objects(channel, collection, filter, opts \\ [])

@spec delete_objects(GRPC.Channel.t(), String.t(), map(), batch_opts()) ::
  {:ok, struct()} | {:error, WeaviateEx.Error.t()}

Delete multiple objects matching a filter.

Examples

filter = %{path: ["category"], operator: :equal, value_text: "old"}

{:ok, result} = Batch.delete_objects(channel, "Article", filter)

insert_objects(channel, objects, opts \\ [])

@spec insert_objects(GRPC.Channel.t(), [object()], batch_opts()) ::
  {:ok, struct()} | {:error, WeaviateEx.Error.t()}

Insert multiple objects in a single batch request.

Options

  • :consistency_level - Consistency level (:one, :quorum, :all)
  • :timeout - Request timeout in milliseconds (default: 90000)

Examples

objects = [
  %{collection: "Article", properties: %{"title" => "First"}},
  %{collection: "Article", properties: %{"title" => "Second"}}
]

{:ok, result} = Batch.insert_objects(channel, objects)

insert_references(channel, references, opts \\ [])

@spec insert_references(GRPC.Channel.t(), [batch_ref()], batch_opts()) ::
  {:ok, struct()} | {:error, WeaviateEx.Error.t()}

Insert multiple references in a single batch request.

Examples

refs = [
  %{from_collection: "Article", from_uuid: "uuid1", from_property: "author", to_uuid: "uuid2"},
  %{from_collection: "Article", from_uuid: "uuid3", from_property: "author", to_uuid: "uuid4"}
]

{:ok, result} = Batch.insert_references(channel, refs)

parse_result(arg1)

@spec parse_result(struct()) :: %{
  failed: non_neg_integer(),
  errors: [map()],
  took_ms: float()
}

Parse batch result and return failure counts and errors.

Note: The successful count is not directly available from the gRPC reply. Use the object count minus failed count to derive successful count.

Examples

{:ok, reply} = Batch.insert_objects(channel, objects)
%{failed: 2, errors: [...]} = Batch.parse_result(reply)