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?
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
Resetting Metrics
Useflock_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: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.

