The Models Management section provides guidance on how to manage and configure models for analytics and semantic analysis tasks within Flock. These tasks involve processing and analyzing text, embeddings, and other data types using pre-configured models, either system-defined or user-defined, based on specific use cases. Each database is configured with its own model management table during the initial load.

1. Model Configuration

Models are stored in a table with the following structure:

max_batch_size

max_batch_size sets the maximum number of input tuples Flock groups into a single provider request. Each request counts as one call against rate_limit and provider quotas. Default: 16.
You can also override max_batch_size inline when calling a function:

Token-limit retries

If a batch exceeds the model context window, Flock automatically retries with smaller batches instead of failing the whole query. Scalar functions (llm_complete, llm_filter, llm_embedding):
  • Flock starts from min(max_batch_size, row_count).
  • On a context-window / token-limit error, the failed batch is retried at half the size: 64 → 32 → 16 → …
  • After a successful batch, the next chunk starts again at the configured max_batch_size.
  • If a batch cannot be reduced further (batch_size of 1 still fails), affected rows return NULL.
Sync (is_async: false) retries batches sequentially. Async (is_async: true, the default) splits only the failed batch and re-queues the smaller pieces; successful batches in the same round are kept. Aggregate functions (llm_reduce, llm_rerank, llm_first, llm_last):
  • Flock shrinks the working batch by 10% on token-limit errors and retries the same rows.
  • If the batch size reaches zero, Flock raises an error instead of returning NULL.
This automatic backoff is separate from usage_limit, which tracks cumulative token quotas and fails immediately once exceeded.

batch_size (deprecated)

batch_size is a deprecated alias for max_batch_size. Existing models and inline overrides that use batch_size continue to work, but Flock logs a warning when batch_size is used. Prefer max_batch_size in new models and queries. If both are set, max_batch_size takes precedence.

is_async

is_async applies to llm_complete and llm_filter. When true (the default), all batches are queued in parallel and responses are collected in a single call. When false, batches are processed one at a time synchronously.
You can also pass is_async inline when calling a function:

rate_limit

rate_limit sets the maximum number of provider requests per minute for a Flock model, keyed by model_name. This helps avoid exceeding provider quotas on free or shared API tiers. When rate_limit is set:
  • Flock spaces outgoing provider requests so the configured requests-per-minute cap is not exceeded.
  • max_batch_size and rate_limit are independent: max_batch_size controls tuples per request; rate_limit throttles how many provider requests are sent per minute.
  • The limit applies across completions, embeddings, and transcriptions for that model.
  • Sync and async scalar execution both respect the same per-model limit.
If rate_limit is omitted, Flock does not apply request-per-minute throttling.

usage_limit

usage_limit sets cumulative token quotas for a Flock model, keyed by model_name. Like rate_limit, it is scoped per model; unlike rate_limit, which throttles how many provider requests are sent per minute, usage_limit tracks provider-reported token usage across calls and fails once a quota is exceeded. Supported fields (at least one is required):
  • prompt_tokens_limit: maximum cumulative input/prompt tokens
  • completion_tokens_limit: maximum cumulative output/completion tokens
  • total_tokens_limit: maximum cumulative total tokens (prompt + completion)
When a limit is exceeded, Flock raises a usage-limit error. This is separate from context-window overflow errors that trigger automatic max_batch_size retries (see above).
If usage_limit is omitted, Flock does not enforce cumulative token quotas.

2. Management Commands

  • Retrieve all available models
  • Retrieve details of a specific model
  • Create a new user-defined model
  • Modify an existing user-defined model
  • Remove a user-defined model

3. Global and Local Models

Model creation is database specific. If you want it to be available irrespective of the database, use the GLOBAL keyword. LOCAL is the default if not specified.

Create Models

  • Create a global model:
  • Create a local model (default if no type is specified):
  • Toggle a model’s state between global and local:
All other queries remain the same for both global and local models.

4. SQL Query Examples

Semantic Text Completion