WeaviateEx.API.Aggregate (WeaviateEx v0.7.4)
View SourceAggregation operations with gRPC support.
Provides statistical aggregation capabilities including:
- Count, sum, mean, median, mode
- Maximum, minimum
- Top occurrences for text fields
- Percentage true/false for boolean fields
- GroupBy aggregations
- Aggregation with semantic search context
Uses gRPC when available for optimal performance, falls back to GraphQL otherwise.
Summary
Functions
Aggregate results grouped by property.
Aggregate entire collection with specified metrics.
Aggregate with hybrid search constraint.
Aggregate with near_image similarity constraint.
Aggregate with near_object similarity constraint.
Aggregate with semantic text search context.
Aggregate with vector similarity search.
Aggregate with filter conditions.
Types
Functions
@spec group_by(WeaviateEx.Client.t(), collection_name(), String.t(), opts()) :: {:ok, [map()]} | {:error, WeaviateEx.Error.t()}
Aggregate results grouped by property.
Parameters
client- WeaviateEx clientcollection_name- Name of the collectionproperty- Property to group by (supports nested paths like "author.name")opts- Options (same as over_all/3)
Examples
{:ok, results} = Aggregate.group_by(client, "Article", "category",
metrics: [:count]
)
{:ok, results} = Aggregate.group_by(client, "Article", "author",
properties: [
{:views, [:mean, :sum]}
],
metrics: [:count]
)Returns
{:ok, [map()]}- List of grouped aggregation results{:error, Error.t()}- Error if aggregation fails
@spec over_all(WeaviateEx.Client.t(), collection_name(), opts()) :: {:ok, [map()]} | {:error, WeaviateEx.Error.t()}
Aggregate entire collection with specified metrics.
Parameters
client- WeaviateEx clientcollection_name- Name of the collectionopts- Options::metrics- List of meta metrics ([:count]):properties- List of {property, metrics} or {property, metrics, opts} tuples
Examples
# Count all objects
{:ok, results} = Aggregate.over_all(client, "Article", metrics: [:count])
# Aggregate numeric properties
{:ok, results} = Aggregate.over_all(client, "Product",
properties: [
{:price, [:sum, :mean, :maximum, :minimum]}
]
)
# Text property with top occurrences
{:ok, results} = Aggregate.over_all(client, "Article",
properties: [
{:category, [:topOccurrences], limit: 5}
]
)Returns
{:ok, [map()]}- List of aggregation results{:error, Error.t()}- Error if aggregation fails
@spec with_hybrid(WeaviateEx.Client.t(), collection_name(), String.t(), opts()) :: {:ok, [map()]} | {:error, WeaviateEx.Error.t()}
Aggregate with hybrid search constraint.
Combines vector similarity and keyword (BM25) search for aggregation.
Parameters
client- WeaviateEx clientcollection_name- Name of the collectionquery- Search query stringopts- Options including::alpha- Weight between vector (1.0) and keyword (0.0) search (default: 0.5):fusion_type- Fusion strategy (:ranked or :relative_score)- Plus standard aggregation options
Examples
{:ok, results} = Aggregate.with_hybrid(client, "Article",
"machine learning",
alpha: 0.7,
metrics: [:count]
)
{:ok, results} = Aggregate.with_hybrid(client, "Article",
"popular topics",
alpha: 0.5,
fusion_type: :ranked,
properties: [
{:views, [:mean, :sum]}
]
)Returns
{:ok, [map()]}- List of aggregation results{:error, Error.t()}- Error if aggregation fails
@spec with_near_image(WeaviateEx.Client.t(), collection_name(), String.t(), opts()) :: {:ok, [map()]} | {:error, WeaviateEx.Error.t()}
Aggregate with near_image similarity constraint.
Aggregates objects that are semantically similar to a given image. The image can be provided as a base64-encoded string or a URL.
Requires a multi2vec-clip or similar image-capable vectorizer.
Parameters
client- WeaviateEx clientcollection_name- Name of the collectionimage_data- Base64-encoded image string or image URLopts- Options including::certainty- Minimum certainty threshold:distance- Maximum distance threshold:target_vectors- Target named vectors for multi-vector collections- Plus standard aggregation options
Examples
# With base64 image
{:ok, results} = Aggregate.with_near_image(client, "Products",
base64_image_string,
metrics: [:count]
)
# With certainty threshold
{:ok, results} = Aggregate.with_near_image(client, "Products",
image_data,
certainty: 0.7,
metrics: [:count]
)
# Target specific named vector
{:ok, results} = Aggregate.with_near_image(client, "Products",
image_data,
target_vectors: ["image_vector"],
properties: [{:price, [:mean, :sum]}]
)Returns
{:ok, [map()]}- List of aggregation results{:error, Error.t()}- Error if aggregation fails
@spec with_near_object(WeaviateEx.Client.t(), collection_name(), String.t(), opts()) :: {:ok, [map()]} | {:error, WeaviateEx.Error.t()}
Aggregate with near_object similarity constraint.
Aggregates objects that are semantically similar to a given object.
Parameters
client- WeaviateEx clientcollection_name- Name of the collectionobject_id- UUID of the reference objectopts- Options (same as over_all/3 plus :certainty, :distance)
Examples
{:ok, results} = Aggregate.with_near_object(client, "Article",
"550e8400-e29b-41d4-a716-446655440000",
metrics: [:count],
distance: 0.3
)Returns
{:ok, [map()]}- List of aggregation results{:error, Error.t()}- Error if aggregation fails
@spec with_near_text(WeaviateEx.Client.t(), collection_name(), String.t(), opts()) :: {:ok, [map()]} | {:error, WeaviateEx.Error.t()}
Aggregate with semantic text search context.
Parameters
client- WeaviateEx clientcollection_name- Name of the collectionconcepts- Search concepts/queryopts- Options (same as over_all/3 plus :certainty, :distance)
Examples
{:ok, results} = Aggregate.with_near_text(client, "Article",
"artificial intelligence",
metrics: [:count]
)
{:ok, results} = Aggregate.with_near_text(client, "Article",
"popular topics",
certainty: 0.7,
properties: [
{:views, [:mean, :sum]}
]
)Returns
{:ok, [map()]}- List of aggregation results{:error, Error.t()}- Error if aggregation fails
@spec with_near_vector(WeaviateEx.Client.t(), collection_name(), [float()], opts()) :: {:ok, [map()]} | {:error, WeaviateEx.Error.t()}
Aggregate with vector similarity search.
Parameters
client- WeaviateEx clientcollection_name- Name of the collectionvector- Search vectoropts- Options (same as over_all/3 plus :certainty, :distance)
Examples
{:ok, results} = Aggregate.with_near_vector(client, "Article", vector,
metrics: [:count]
)Returns
{:ok, [map()]}- List of aggregation results{:error, Error.t()}- Error if aggregation fails
@spec with_where(WeaviateEx.Client.t(), collection_name(), map(), opts()) :: {:ok, [map()]} | {:error, WeaviateEx.Error.t()}
Aggregate with filter conditions.
Parameters
client- WeaviateEx clientcollection_name- Name of the collectionfilter- Filter map (GraphQL where clause format)opts- Options (same as over_all/3)
Examples
filter = %{
path: ["status"],
operator: "Equal",
valueText: "published"
}
{:ok, results} = Aggregate.with_where(client, "Article", filter,
metrics: [:count]
)Returns
{:ok, [map()]}- List of aggregation results{:error, Error.t()}- Error if aggregation fails