WeaviateEx.Iterator (WeaviateEx v0.7.4)

View Source

Collection iterator for cursor-based pagination.

Provides a way to iterate through all objects in a collection using cursor-based pagination, which is more efficient than offset-based pagination for large collections.

Examples

# Create iterator
iterator = Iterator.new(client, "Article",
  return_properties: ["title", "content"],
  batch_size: 100
)

# Use as Elixir Stream
Iterator.stream(iterator)
|> Stream.take(1000)
|> Enum.to_list()

# Manual iteration
{:ok, {objects, next_iterator}} = Iterator.next_batch(iterator)

Summary

Functions

Build the GraphQL query for the current iterator state.

Create a new iterator for a collection.

Fetch the next batch of objects.

Create a lazy stream from the iterator.

Update the cursor for the next page.

Types

reference_spec()

@type reference_spec() :: String.t() | {String.t(), [String.t()]}

t()

@type t() :: %WeaviateEx.Iterator{
  batch_size: pos_integer(),
  client: WeaviateEx.Client.t(),
  collection: String.t(),
  cursor: String.t() | nil,
  filter: map() | nil,
  include_vector: boolean(),
  return_properties: [String.t()],
  return_references: [reference_spec()],
  tenant: String.t() | nil
}

Functions

build_query(iterator)

@spec build_query(t()) :: String.t()

Build the GraphQL query for the current iterator state.

new(client, collection, opts \\ [])

@spec new(WeaviateEx.Client.t(), String.t(), keyword()) :: t()

Create a new iterator for a collection.

Options

  • :batch_size - Number of objects per batch (default: 100)
  • :return_properties - Properties to return (default: all)
  • :return_references - References to return with optional nested properties
  • :include_vector - Include vector in response (default: false)
  • :after - Start cursor (for resuming iteration)
  • :filter - Filter to apply to objects
  • :tenant - Tenant name for multi-tenant collections

Reference Format

References can be specified as:

  • Simple: ["hasAuthor", "hasCategory"] - returns all properties
  • With properties: [{"hasAuthor", ["name", "email"]}] - returns specific properties

Examples

Iterator.new(client, "Article", batch_size: 50)
Iterator.new(client, "Article", return_properties: ["title"])
Iterator.new(client, "Article", return_references: ["hasAuthor"])
Iterator.new(client, "Article", return_references: [{"hasAuthor", ["name"]}])

next_batch(iterator)

@spec next_batch(t()) :: {:ok, {[map()], t() | nil}} | {:error, term()}

Fetch the next batch of objects.

Returns {:ok, {objects, next_iterator}} where next_iterator can be used to fetch the next batch.

Examples

{:ok, {objects, next_iter}} = Iterator.next_batch(iterator)

stream(iterator)

@spec stream(t()) :: Enumerable.t()

Create a lazy stream from the iterator.

Returns an Elixir Stream that fetches objects on demand.

Examples

Iterator.new(client, "Article")
|> Iterator.stream()
|> Stream.take(500)
|> Enum.to_list()

with_cursor(iterator, cursor)

@spec with_cursor(t(), String.t() | nil) :: t()

Update the cursor for the next page.