WeaviateEx.Iterator (WeaviateEx v0.7.4)
View SourceCollection 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
@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 the GraphQL query for the current iterator state.
@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"]}])
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)
@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()
Update the cursor for the next page.