Flock includes built-in observability for all LLM functions. You can inspect token usage, API latency, and execution time for llm_complete, llm_filter, llm_embedding, llm_reduce, llm_rerank, llm_first, and llm_last directly from SQL.

Overview

Metrics are collected at the database level and aggregated across scalar and aggregate function calls. This allows you to answer questions like:
  • How many tokens did this query use?
  • Which models and providers are being called most often?
  • How much time is spent in the LLM API vs. local execution?
All metrics are exposed as JSON via dedicated helper functions.

Core Functions

Flock registers three scalar functions for metrics:
  • flock_get_metrics() – Returns a compact JSON summary of LLM usage.
  • flock_get_debug_metrics() – Returns a more verbose JSON payload, useful for debugging.
  • flock_reset_metrics() – Resets the in-memory metrics state and returns a confirmation message.

Basic Usage

Example JSON structure (simplified):

Resetting Metrics

Use flock_reset_metrics() to clear existing metrics before a new experiment or workload:

Query-Level Workflows

Because metrics are stored at the database level, you can combine computation and inspection in the same script:
You can further parse the JSON using DuckDB’s JSON extension to build dashboards or reports.

When to Use Metrics

LLM metrics are particularly useful when you:
  • Benchmark different providers or models.
  • Tune prompts and batch sizes for cost/performance trade-offs (see Performance and cost).
  • Monitor token usage for budgeting and quota management.
  • Diagnose slow or unexpectedly expensive queries.
By combining Flock’s LLM metrics with DuckDB’s analytics capabilities, you can build fully in-database observability for your semantic workloads.