WeaviateEx.Query.GroupBy (WeaviateEx v0.7.4)
View SourceGroup search results by property values.
GroupBy clusters results based on a property path, returning groups with their objects. This is useful for organizing search results by category, type, or other grouping criteria.
Examples
# Group by category
group_by = GroupBy.new("category")
# Group by nested property
group_by = GroupBy.new(["metadata", "type"])
# With custom limits
group_by = GroupBy.new("category",
objects_per_group: 3,
number_of_groups: 10
)
# Use in query
Query.get("Article")
|> Query.near_text("machine learning")
|> Query.group_by(group_by)
|> Query.execute(client)
Summary
Functions
Create a new group by configuration.
Convert group by configuration to GraphQL format.
Convert group by configuration to map format (for gRPC).
Validate group by configuration.
Types
@type t() :: %WeaviateEx.Query.GroupBy{ number_of_groups: pos_integer(), objects_per_group: pos_integer(), path: String.t() | [String.t()] }
Functions
Create a new group by configuration.
Parameters
path- The property path to group by. Can be a string for simple properties or a list for nested properties.opts- Options::objects_per_group- Maximum objects per group (default: 10):number_of_groups- Maximum number of groups to return (default: 10)
Examples
# Simple property
GroupBy.new("category")
# Nested property path
GroupBy.new(["metadata", "type"])
# With limits
GroupBy.new("category", objects_per_group: 5, number_of_groups: 20)
Convert group by configuration to GraphQL format.
Examples
group_by = GroupBy.new("category", objects_per_group: 3, number_of_groups: 5)
GroupBy.to_graphql(group_by)
# => "{path: ["category"], objectsPerGroup: 3, groups: 5}"
Convert group by configuration to map format (for gRPC).
Examples
group_by = GroupBy.new("category", objects_per_group: 5)
GroupBy.to_map(group_by)
# => %{path: ["category"], objects_per_group: 5, number_of_groups: 10}
Validate group by configuration.
Examples
iex> GroupBy.valid?(GroupBy.new("category"))
true
iex> GroupBy.valid?(%GroupBy{path: nil})
false
iex> GroupBy.valid?(%GroupBy{path: "cat", objects_per_group: 0})
false