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: 4. This default may change in a future release, so set max_batch_size explicitly if you rely on it. Some models answer less accurately when many tuples share one request; if answers look mixed up between rows, lower it.
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_sizeof 1 still fails), affected rows returnNULL.
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.
usage_limit, which tracks cumulative token quotas and rejects new requests 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.
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_sizeandrate_limitare independent:max_batch_sizecontrols tuples per request;rate_limitthrottles 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.
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. It is a soft cap: requests already sent when a quota is crossed still return, and later requests are rejected, leaving their rows NULL.
Supported fields (at least one is required):
prompt_tokens_limit: maximum cumulative input/prompt tokenscompletion_tokens_limit: maximum cumulative output/completion tokenstotal_tokens_limit: maximum cumulative total tokens (prompt + completion)
max_batch_size retries (see above).
usage_limit is omitted, Flock does not enforce cumulative token quotas.
threshold
threshold applies to typesafe models, which answer llm_filter with a probability rather than a yes or no. A probability at or above the threshold counts as true. It must be a number between 0 and 1.
There is no default: llm_filter on a typesafe model fails until a threshold is set here or inline on the model.
{'model_name': 'strict-jev', 'threshold': 0.9}. Other providers ignore it.
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:

