WeaviateEx.Aggregate.Metrics (WeaviateEx v0.7.4)

View Source

Helper module for building aggregate metrics.

Provides a cleaner API for specifying which metrics to compute during aggregation operations.

Usage

alias WeaviateEx.Aggregate.Metrics

# Use metrics in aggregation
Aggregate.over_all(client, "Products",
  metrics: [Metrics.count()],
  properties: [
    Metrics.number("price", sum: true, mean: true, minimum: true, maximum: true),
    Metrics.text("category", top_occurrences: 5),
    Metrics.boolean("inStock")
  ]
)

Summary

Functions

Build a boolean property metric specification.

Count metric for meta aggregation.

Build a date property metric specification.

Build an integer property metric specification.

Build a number property metric specification.

Build a text property metric specification.

Types

metric_opt()

@type metric_opt() ::
  {:count, boolean()}
  | {:sum, boolean()}
  | {:mean, boolean()}
  | {:median, boolean()}
  | {:mode, boolean()}
  | {:minimum, boolean()}
  | {:maximum, boolean()}
  | {:top_occurrences, non_neg_integer()}
  | {:percentage_true, boolean()}
  | {:percentage_false, boolean()}
  | {:total_true, boolean()}
  | {:total_false, boolean()}

Functions

boolean(property, opts \\ [])

@spec boolean(
  String.t() | atom(),
  keyword()
) :: {atom() | String.t(), list()}

Build a boolean property metric specification.

Options

  • :count - Include count (default: true)
  • :percentage_true - Include percentage of true values (default: true)
  • :percentage_false - Include percentage of false values (default: true)
  • :total_true - Include count of true values (default: true)
  • :total_false - Include count of false values (default: true)

Examples

# Get all boolean metrics
Metrics.boolean("inStock")

# Only percentages
Metrics.boolean("isActive", percentage_true: true, percentage_false: true)

count()

@spec count() :: :count

Count metric for meta aggregation.

Returns the total number of objects.

Examples

Aggregate.over_all(client, "Articles", metrics: [Metrics.count()])

date(property, opts \\ [])

@spec date(
  String.t() | atom(),
  keyword()
) :: {atom() | String.t(), list()}

Build a date property metric specification.

Options

  • :count - Include count (default: false)
  • :median - Include median date (default: false)
  • :mode - Include mode date (default: false)
  • :minimum - Include earliest date (default: false)
  • :maximum - Include latest date (default: false)

Examples

Metrics.date("createdAt", minimum: true, maximum: true)

integer(property, opts \\ [])

@spec integer(
  String.t() | atom(),
  keyword()
) :: {atom() | String.t(), list()}

Build an integer property metric specification.

Same options as number/2.

Examples

Metrics.integer("quantity", sum: true, mean: true)

number(property, opts \\ [])

@spec number(
  String.t() | atom(),
  keyword()
) :: {atom() | String.t(), list()}

Build a number property metric specification.

Options

  • :count - Include count (default: false)
  • :sum - Include sum (default: false)
  • :mean - Include mean (default: false)
  • :median - Include median (default: false)
  • :mode - Include mode (default: false)
  • :minimum - Include minimum (default: false)
  • :maximum - Include maximum (default: false)

Examples

# Get basic stats
Metrics.number("price", sum: true, mean: true, minimum: true, maximum: true)

# All stats
Metrics.number("quantity",
  count: true, sum: true, mean: true, median: true,
  mode: true, minimum: true, maximum: true
)

text(property, opts \\ [])

@spec text(
  String.t() | atom(),
  keyword()
) :: {atom() | String.t(), list(), keyword()}

Build a text property metric specification.

Options

  • :count - Include count of values (default: false)
  • :top_occurrences - Number of top values to return (default: nil)

Examples

# Get top 5 categories
Metrics.text("category", top_occurrences: 5)

# Just count
Metrics.text("title", count: true)