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

View Source

gRPC Aggregate service for aggregation queries.

This module provides high-level functions for performing aggregations on Weaviate collections using gRPC.

Usage

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

{:ok, result} = Aggregate.count(channel, "Article")
{:ok, result} = Aggregate.over_property(channel, "Article", "wordCount",
  aggregations: [:sum, :mean, :minimum, :maximum]
)

Summary

Functions

Count objects in a collection.

Execute a raw AggregateRequest.

Aggregate over a specific property.

Types

aggregate_opts()

@type aggregate_opts() :: [
  tenant: String.t(),
  filters: map(),
  group_by: String.t() | [String.t()],
  near_vector: [float()],
  near_text: String.t(),
  aggregations: [atom()],
  limit: non_neg_integer(),
  timeout: non_neg_integer()
]

Functions

count(channel, collection, opts \\ [])

@spec count(GRPC.Channel.t(), String.t(), aggregate_opts()) ::
  {:ok, struct()} | {:error, WeaviateEx.Error.t()}

Count objects in a collection.

Examples

{:ok, result} = Aggregate.count(channel, "Article")
{:ok, result} = Aggregate.count(channel, "Article", tenant: "tenant_a")

execute(channel, request, opts \\ [])

@spec execute(GRPC.Channel.t(), struct(), keyword()) ::
  {:ok, struct()} | {:error, WeaviateEx.Error.t()}

Execute a raw AggregateRequest.

Examples

request = %AggregateRequest{
  collection: "Article",
  count_by_meta: true
}
{:ok, result} = Aggregate.execute(channel, request)

group_by(channel, collection, property, opts \\ [])

@spec group_by(GRPC.Channel.t(), String.t(), String.t(), aggregate_opts()) ::
  {:ok, struct()} | {:error, WeaviateEx.Error.t()}

Aggregate with grouping.

Examples

{:ok, result} = Aggregate.group_by(channel, "Article", "category",
  aggregations: [:count]
)

over_property(channel, collection, property, opts \\ [])

@spec over_property(GRPC.Channel.t(), String.t(), String.t(), aggregate_opts()) ::
  {:ok, struct()} | {:error, WeaviateEx.Error.t()}

Aggregate over a specific property.

Options

  • :aggregations - List of aggregation types to compute
    • For numbers: :count, :sum, :mean, :median, :mode, :minimum, :maximum
    • For text: :count, :top_occurrences
    • For boolean: :count, :total_true, :total_false, :percentage_true, :percentage_false

Examples

{:ok, result} = Aggregate.over_property(channel, "Article", "wordCount",
  aggregations: [:sum, :mean, :minimum, :maximum]
)