WeaviateEx.Query.GenerativeResult (WeaviateEx v0.7.4)

View Source

Result structure for generative search queries.

This struct holds the results from a combined search + generation query, including both the matched objects and their generated content.

Fields

  • :objects - List of matched objects with their properties
  • :generated - The grouped generation result (if grouped_task was used)
  • :generated_per_object - List of per-object generation results (if single_prompt was used)
  • :metadata - Optional metadata about the generative operation (token usage, etc.)

Examples

# Result with per-object generation
%GenerativeResult{
  objects: [
    %{uuid: "uuid-1", properties: %{title: "Article 1"}},
    %{uuid: "uuid-2", properties: %{title: "Article 2"}}
  ],
  generated: nil,
  generated_per_object: ["Summary of Article 1", "Summary of Article 2"]
}

# Result with grouped generation
%GenerativeResult{
  objects: [%{uuid: "uuid-1", properties: %{title: "Article 1"}}],
  generated: "Overall summary of all articles",
  generated_per_object: []
}

Summary

Functions

Creates a GenerativeResult from a gRPC SearchReply.

Checks if the result has a grouped generation.

Checks if the result has any objects.

Checks if the result has per-object generations.

Creates a new empty GenerativeResult.

Creates a GenerativeResult from parsed objects.

Returns the count of objects in the result.

Types

debug_metadata()

@type debug_metadata() :: %{optional(:full_prompt) => String.t()}

metadata()

@type metadata() :: %{
  optional(:usage) => usage_metadata(),
  optional(:debug) => debug_metadata()
}

object()

@type object() :: %{
  optional(:uuid) => String.t(),
  optional(:properties) => map(),
  optional(:vector) => [float()],
  optional(:distance) => float(),
  optional(:certainty) => float(),
  optional(:score) => float()
}

t()

@type t() :: %WeaviateEx.Query.GenerativeResult{
  generated: String.t() | nil,
  generated_per_object: [String.t()],
  metadata: metadata() | nil,
  objects: [object()]
}

usage_metadata()

@type usage_metadata() :: %{
  optional(:prompt_tokens) => integer(),
  optional(:completion_tokens) => integer(),
  optional(:total_tokens) => integer()
}

Functions

from_grpc_response(reply)

@spec from_grpc_response(map()) :: t()

Creates a GenerativeResult from a gRPC SearchReply.

Parses the gRPC response structure to extract:

  • Objects from the search results
  • Grouped generative results (if present)
  • Per-object generative results (if present)
  • Optional metadata (usage, debug info)

has_grouped_result?(generative_result)

@spec has_grouped_result?(t()) :: boolean()

Checks if the result has a grouped generation.

has_objects?(generative_result)

@spec has_objects?(t()) :: boolean()

Checks if the result has any objects.

has_single_results?(generative_result)

@spec has_single_results?(t()) :: boolean()

Checks if the result has per-object generations.

new()

@spec new() :: t()

Creates a new empty GenerativeResult.

new(objects, generated, generated_per_object)

@spec new([object()], String.t() | nil, [String.t()]) :: t()

Creates a GenerativeResult from parsed objects.

object_count(generative_result)

@spec object_count(t()) :: non_neg_integer()

Returns the count of objects in the result.