The llm_reduce function in Flock consolidates multiple rows of text-based results into a single output. It is used in SQL queries with the GROUP BY clause to combine multiple values into a summary or reduced form.

Modalities

Text

Aggregate tabular text columns across a group.

Image

Summarize visual themes across a group with type: 'image'.

Voice

Summarize spoken content with type: 'audio' and transcription_model (OpenAI / Azure).

1. Usage Examples

1.1. Example without GROUP BY

Summarize all product descriptions into one single result:
Description: This example aggregates all product descriptions into one summary. The llm_reduce function processes the product_description column for each row, consolidating the values into a single summarized output.

1.2. Example with GROUP BY

Group the products by category and summarize their descriptions into one for each category:
Description: This query groups the products by category (e.g., electronics, clothing) and summarizes all product descriptions within each category into a single consolidated summary.

1.3. Using a Named Prompt with GROUP BY

Leverage a reusable named prompt for summarization, grouped by category:
Description: This example uses a pre-configured named prompt (summarizer) with version 1 to summarize product descriptions. The results are grouped by category, with one summary per category.

1.4. Advanced Example with Multiple Columns and GROUP BY

Summarize product details by category, using both the product name and description:
Description: In this advanced example, the query summarizes both the product_name and product_description columns for products in the “Electronics” category, generating a detailed summary for that category.

2. Input Parameters

2.1 Model Configuration

  • Parameter: model_name and secret_name

2.1.1 Model Selection

  • Description: Specifies the model used for text generation.
  • Example:

2.1.2 Model Selection with Secret

  • Description: Specifies the model along with the secret name to be used for authentication when accessing the model.
  • Example:

2.2. Prompt Configuration

Two types of prompts can be used:
  1. Inline Prompt
    • Directly provides the prompt in the query.
    • Example:
  2. Named Prompt
    • Refers to a pre-configured prompt by name.
    • Example:
  3. Named Prompt with Version
    • Refers to a specific version of a pre-configured prompt.
    • Example:

2.3. Context Columns Configuration

  • Key: context_columns array.
  • Purpose: Maps table columns to provide input data for the model. Each column can have three properties:
    • data: The SQL column data (required)
    • name: Custom name for the column to be referenced in the prompt (optional)
    • type: Data type — "tabular" (default), "image", or "audio" (audio requires transcription_model)
  • Example:

3. Output

  • Column Type: JSON.
  • Behavior: Consolidates multiple rows into a single model response per group. Without a schema the JSON typically holds free-form summary text; with a JSON schema in model_parameters the response matches that shape (OpenAI response_format, Ollama format, or Anthropic output_format / tool-use). Use LOAD JSON to extract fields.
Free-form example: aggregating product descriptions might return a single summary string such as “A variety of products including running shoes, wireless headphones, and smart watches…”. Structured example: