WeaviateEx.Query.Generate (WeaviateEx v0.7.4)
View SourceGenerative search query builder.
Combines vector/keyword search with generative AI to produce both search results and AI-generated content in a single query.
Features
- All search types: near_text, near_vector, near_object, bm25, hybrid
- Single prompt: Generate content for each object individually
- Grouped task: Generate content from all results together
- Full filter, limit, offset support
Examples
# Vector search with per-object generation
Generate.new("Article")
|> Generate.near_text("machine learning")
|> Generate.single_prompt("Summarize this article: {title}")
|> Generate.limit(5)
|> Generate.execute(client)
# BM25 search with grouped generation
Generate.new("Article")
|> Generate.bm25("elixir")
|> Generate.grouped_task("Write a summary of these articles", properties: ["title", "content"])
|> Generate.execute(client)
# Hybrid search with both single and grouped prompts
Generate.new("Article")
|> Generate.hybrid("AI research", alpha: 0.7)
|> Generate.single_prompt("Key point: {title}")
|> Generate.grouped_task("Overall theme")
|> Generate.return_properties(["title", "content"])
|> Generate.execute(client)
Summary
Functions
Sets additional metadata fields to return.
Adds BM25 keyword search to the query.
Executes the generative query against Weaviate.
Sets the grouped task for generation across all results.
Adds hybrid search to the query.
Sets the maximum number of results to return.
Adds near_object search to the query.
Adds near_text search to the query.
Adds near_vector search to the query.
Creates a new generative query builder for a collection.
Sets the number of results to skip.
Parses an API response into a GenerativeResult struct.
Sets the properties to return from the search.
Sets the single prompt for per-object generation.
Sets the tenant for multi-tenant collections.
Converts the builder to a GraphQL query string.
Validates the query builder has required fields.
Sets a filter condition for the query.
Types
@type search_type() :: :near_text | :near_vector | :near_object | :bm25 | :hybrid
@type t() :: %WeaviateEx.Query.Generate{ additional: [String.t()] | nil, collection: String.t(), grouped_properties: [String.t()] | nil, grouped_task: String.t() | nil, limit: pos_integer() | nil, offset: non_neg_integer() | nil, return_properties: [String.t()] | nil, search_opts: keyword(), search_query: term(), search_type: search_type() | nil, single_prompt: String.t() | nil, tenant: String.t() | nil, where: map() | nil }
Functions
Sets additional metadata fields to return.
Examples
Generate.additional(builder, ["distance", "certainty", "vector"])
Adds BM25 keyword search to the query.
Options
:properties- Properties to search in:operator- BM25 operator (:and or :or)
Examples
Generate.bm25(builder, "elixir programming", properties: ["title", "content"])
@spec execute(t(), WeaviateEx.Client.t()) :: {:ok, WeaviateEx.Query.GenerativeResult.t()} | {:error, term()}
Executes the generative query against Weaviate.
Examples
{:ok, result} = Generate.execute(builder, client)
Sets the grouped task for generation across all results.
Options
:properties- Properties to include in the context for generation
Examples
Generate.grouped_task(builder, "Summarize all articles")
Generate.grouped_task(builder, "Write a report", properties: ["title", "content"])
Adds hybrid search to the query.
Options
:alpha- Weight between vector (1.0) and keyword (0.0) search:fusion_type- Fusion algorithm (:ranked or :relative_score):properties- Properties to search for BM25 component
Examples
Generate.hybrid(builder, "machine learning", alpha: 0.7)
@spec limit(t(), pos_integer()) :: t()
Sets the maximum number of results to return.
Examples
Generate.limit(builder, 10)
Adds near_object search to the query.
Options
:certainty- Minimum certainty threshold (0.0 to 1.0):distance- Maximum distance threshold
Examples
Generate.near_object(builder, "uuid-123", certainty: 0.85)
Adds near_text search to the query.
Options
:certainty- Minimum certainty threshold (0.0 to 1.0):distance- Maximum distance threshold:move_to- Concepts to move towards:move_away- Concepts to move away from
Examples
Generate.near_text(builder, "machine learning", certainty: 0.8)
Adds near_vector search to the query.
Options
:certainty- Minimum certainty threshold (0.0 to 1.0):distance- Maximum distance threshold:target_vectors- Target named vectors
Examples
Generate.near_vector(builder, [0.1, 0.2, 0.3], certainty: 0.9)
Creates a new generative query builder for a collection.
Examples
builder = Generate.new("Article")
@spec offset(t(), non_neg_integer()) :: t()
Sets the number of results to skip.
Examples
Generate.offset(builder, 20)
@spec parse_response(map(), String.t()) :: WeaviateEx.Query.GenerativeResult.t()
Parses an API response into a GenerativeResult struct.
Sets the properties to return from the search.
Examples
Generate.return_properties(builder, ["title", "content", "author"])
Sets the single prompt for per-object generation.
The prompt can include property placeholders like {title} that will
be replaced with actual property values for each object.
Examples
Generate.single_prompt(builder, "Summarize: {title}")
Generate.single_prompt(builder, "Write about {title} and its {category}")
Sets the tenant for multi-tenant collections.
Examples
Generate.tenant(builder, "tenant-a")
Converts the builder to a GraphQL query string.
Validates the query builder has required fields.
A valid generative query must have:
- A search type (near_text, near_vector, etc.)
- At least one prompt (single_prompt or grouped_task)
Sets a filter condition for the query.
Examples
Generate.where(builder, %{path: ["status"], operator: "Equal", valueText: "published"})