Models reference v7

Reference for all model-related functions and views in AIDB. For guide-style documentation, see Integrating models.

Configuration model

A model's behavior is controlled two ways, and it matters which one you use for a given setting:

  • Creation-time config — set when you call aidb.create_model(), using a provider-specific config helper (aidb.bert_config(), aidb.completions_config(), and so on). This is the model's persistent, stored configuration.
  • Call-time inference_config — an optional per-call override, built with aidb.inference_config(), passed directly to an inference function. It overrides the model's stored config for that one call only; anything you don't override falls back to the value set at creation time.

Only some inference functions accept a call-time override — the rest are fixed entirely by the model's creation-time config:

FunctionCall-time override?
aidb.generate_text(), aidb.generate_text_batch()Yes — pass aidb.inference_config() (or raw JSON) as the inference_config argument.
aidb.summarize_text(), aidb.summarize_text_aggregate()Yes — via the inference_config field of aidb.summarize_text_config().
aidb.encode_text(), aidb.encode_text_batch(), aidb.encode_image()No. Behavior is fixed by config at creation time.
aidb.rerank_text()No. Behavior is fixed by config at creation time.
aidb.perform_ocr()No — its options parameter only selects which registered model to run, not inference settings.

This asymmetry follows from what each capability needs: text generation has runtime knobs worth tuning per call (temperature, system prompt, and so on); embeddings, reranking, and OCR don't, so there's nothing to override.

Catalog views

aidb.model_providers

Lists the model providers you can pass to aidb.create_model().

ColumnTypeDescription
nametextProvider name.
descriptiontextDescription of the provider.
functionstext[]Capabilities the provider supports.
default_hosttextHost a model of this provider calls when its config sets no url. NULL for local providers.

aidb.models

Lists all models in the registry, including default and user-created models.

ColumnTypeDescription
nametextUser-defined name for the model
providertextModel provider name
optionstext[]Configured options for the model
functionstext[]Internal capability identifiers the model's provider supports (for example, aidb-openai-text-embeddings, aidb-openai-text-completion)
credentialtextName of the credential the model uses. none if the model sends no secret.

Example

SELECT * FROM aidb.models;
Output
  name  |  provider  |    options    |                         functions                         | credential
--------+------------+---------------+-----------------------------------------------------------+------------
 bert   | bert_local | {"config={}"} | {aidb-openai-text-embeddings}                             | none
 clip   | clip_local | {"config={}"} | {aidb-openai-text-image-embeddings}                       | none
 t5     | t5_local   | {"config={}"} | {aidb-openai-text-embeddings,aidb-openai-text-completion} | none
(3 rows)

Model names

A schema-qualified name, such as alice.summarizer, always names that model. A bare name, such as summarizer, resolves to a built-in model of that name first, and otherwise to the only model of that name in any schema. If two models of that name exist in different schemas, a bare name raises an error. Use the schema-qualified name instead. aidb.delete_model() resolves a bare name through search_path.

aidb.credentials

Lists the model credentials. See Model credentials.

ColumnTypeDescription
nametextCredential name.
ownertextRole that owns the credential.
endpointtextHosts the secret may be sent to, as an endpoint pattern.
sharedbooleantrue if every member of aidb_users can use the credential.
has_secretbooleantrue if the credential holds a secret.
can_usebooleantrue if the current role can use the credential.

The view never shows the secret.

Example

SELECT name, owner, endpoint, shared, has_secret, can_use FROM aidb.credentials WHERE name = 'openai_prod';
Output
    name     | owner | endpoint       | shared | has_secret | can_use
-------------+-------+----------------+--------+------------+---------
 openai_prod | alice | api.openai.com | t      | t          | t
(1 row)

Model management functions

aidb.create_model

Registers a new model in the AIDB model registry.

Parameters

ParameterTypeDefaultDescription
nameTEXTRequiredUnique name for the model.
providerTEXTRequiredProvider name (see aidb.model_providers).
configJSONB'{}'Provider-specific configuration. Build with a config helper.
credentialTEXTNULLName of the credential the model uses. If NULL and no secret is passed, the model uses none and sends no secret.
credentialsJSONB'{}'Secret for the model, {"api_key": "..."} or {"basic_auth": "..."}. Creates a credential named <schema>.<model>. See Secrets on aidb.create_model().
shareBOOLEANfalseIf true, shares the credential that credentials, credentials_env, or credentials_k8s_secret creates with every member of aidb_users.
replace_credentialsBOOLEANfalseIf true and the <schema>.<model> credential exists, replaces its secret instead of failing.
validateBOOLEANtrueIf true, probe the model at creation time to confirm it's functional. See Validation.
credentials_envTEXTNULLName of an environment variable to read the secret from. Superusers and members of aidb_admins only. See Credentials from environment variables.
credentials_k8s_secretTEXTNULLPath to a file, or a directory of files, to read the secret from. Superusers and members of aidb_admins only. See Credentials from a Kubernetes Secret.

Pass at most one of credential, credentials, credentials_env, and credentials_k8s_secret. A model can't use a different credential later. Delete and recreate it instead.

Secrets on aidb.create_model()

Passing credentials, credentials_env, or credentials_k8s_secret creates a credential named <schema>.<model>, for example public.summarizer. It's owned by the caller, private unless share => true, and its endpoint is the host the model calls. If the model's host can't be determined, the endpoint is *.

  • The call fails if the model or the credential already exists. Pass replace_credentials => true to replace the credential's secret instead.
  • The call fails if <schema>.<model> is longer than 63 bytes. Create a credential with aidb.create_credential() and pass credential instead.

Credentials from environment variables

Pass credentials_env to read the secret from an environment variable of the Postgres server each time the model is used. Only the variable's name is stored. Only superusers and members of aidb_admins can pass it.

SELECT aidb.create_model(
    name            => 'my_openai',
    provider        => 'openai_embeddings',
    config          => aidb.embeddings_config(model => 'text-embedding-3-small'),
    credentials_env => 'AIDB_OPENAI_API_KEY'
);

The variable holds either a bare secret, used as api_key, or a JSON object such as {"basic_auth": "..."}.

The variable's name must start with the prefix set by aidb.env_var_allowed_prefix (AIDB_ by default). To limit the hosts the secret is sent to, set a variable with the same name plus _HOST, for example AIDB_OPENAI_API_KEY_HOST, to an endpoint pattern. A change to the variable takes effect after a server restart.

Credentials from a Kubernetes Secret

Pass credentials_k8s_secret to read the secret from a file each time the model is used, for example from a Kubernetes Secret mounted into the Postgres pod. Only the path is stored. Only superusers and members of aidb_admins can pass it.

SELECT aidb.create_model(
    name                   => 'my_openai',
    provider               => 'openai_embeddings',
    config                 => aidb.embeddings_config(model => 'text-embedding-3-small'),
    credentials_k8s_secret => '/var/run/secrets/aidb/openai/api-key'
);

The path can point to:

  • A file. Its content is either a bare secret, used as api_key, or a JSON object such as {"basic_auth": "..."}.
  • A directory with exactly two files named username and password. They're combined into basic_auth.
  • A directory with exactly one file, which is read like a single file.

The path must start with the prefix set by aidb.k8s_secret_allowed_path_prefix (/var/run/secrets/aidb by default).

To limit the hosts the secret is sent to, add an endpoint pattern in a file named <file>_HOST next to a secret file, or in a file named host in a secret directory. Files that end in _HOST are never read as secrets. A change to the files takes effect on the next call.

TLS configuration

To connect to HTTPS model endpoints, include a tls_config field inside config:

"tls_config": {
  "insecure_skip_verify": true,
  "ca_path": "/etc/aidb/myCA.pem"
}

A model whose credential holds a secret can't use insecure_skip_verify: true. Use ca_path for a private CA instead.

Validation

By default (validate => true), aidb.create_model() runs a minimal probe inference before the registration commits, to confirm the model is functional:

  • Local models are downloaded and loaded, and a test inference is run — so a bad model identifier or unloadable weights fail at creation time rather than on first use.
  • External models receive a small test request — so an invalid API key, wrong URL, or unreachable endpoint is caught right away.

If the probe fails, aidb.create_model() raises an error and registers nothing. Pass validate => false to skip the probe — for example, to defer a large download to first use, or to register a model before its endpoint or credentials are available. You can validate a model later with aidb.validate_model().

Examples

-- Minimal registration
SELECT aidb.create_model('my_t5', 't5_local');

-- With a credential
SELECT aidb.create_model(
    name       => 'my_openai',
    provider   => 'openai_embeddings',
    config     => aidb.embeddings_config(model => 'text-embedding-3-small'),
    credential => 'openai_prod'
);

-- With a secret, which creates the credential public.my_openai_2
SELECT aidb.create_model(
    name        => 'my_openai_2',
    provider    => 'openai_embeddings',
    config      => aidb.embeddings_config(model => 'text-embedding-3-small'),
    credentials => '{"api_key": "sk-..."}'::JSONB
);

aidb.get_model

Returns the configuration for a registered model.

Parameters

ParameterTypeDescription
model_nameTEXTName of the model to retrieve.

Returns

ColumnTypeDescription
nametextModel name
providertextProvider name
optionstext[]Configured options
credentialtextName of the credential the model uses

Example

SELECT * FROM aidb.get_model('t5');
Output
 name | provider |    options    | credential
------+----------+---------------+------------
 t5   | t5_local | {"config={}"} | none
(1 row)

aidb.delete_model

Removes a model from the registry. Doesn't affect pipelines or knowledge bases that reference it until they are next executed. The model's credential isn't deleted. To delete it, use aidb.delete_credential().

Parameters

ParameterTypeDescription
model_nameTEXTName of the model to delete, either schema-qualified or a bare name found through search_path.

Returns

The name, provider, and options of the deleted model.

Example

SELECT aidb.delete_model('t5');
Output
     delete_model
---------------------------------
 (t5,t5_local,"{""config={}""}")
(1 row)

aidb.validate_model

Probes a registered model to confirm it's functional, running a minimal test inference. Called automatically by aidb.create_model() unless validate => false; you can also call it directly to recheck an existing model.

Parameters

ParameterTypeDescription
model_nameTEXTName of the model to validate.

Returns

TEXT — the model capability that was probed (for example, text embedding, language, reranking, image embedding, or OCR). Raises an error if the probe fails.

Example

SELECT aidb.validate_model('my_bert');
Output
 validate_model
----------------
 text embedding
(1 row)

Credential management functions

See Model credentials for how to use these functions.

aidb.create_credential

Creates a credential. The calling role owns it.

Parameters

ParameterTypeDefaultDescription
nameTEXTRequiredCredential name. Must not exist yet. Can't be changed later.
credentialsJSONBNULLSecret, {"api_key": "..."} or {"basic_auth": "..."}. The value must be a non-empty string.
credentials_envTEXTNULLName of an environment variable to read the secret from. Superusers and members of aidb_admins only. See Credentials from environment variables.
credentials_k8s_secretTEXTNULLPath to a file, or a directory of files, to read the secret from. Superusers and members of aidb_admins only. See Credentials from a Kubernetes Secret.
endpointTEXTRequiredHosts the secret may be sent to, as an endpoint pattern.
shareBOOLEANfalseIf true, every member of aidb_users can use the credential.

Pass at most one of credentials, credentials_env, and credentials_k8s_secret. If you pass none, the credential has no secret until you set one with aidb.update_credential().

Example

SELECT aidb.create_credential(
    name        => 'openai_prod',
    credentials => '{"api_key": "sk-..."}'::JSONB,
    endpoint    => 'api.openai.com',
    share       => true
);

aidb.update_credential

Changes a credential's secret, endpoint, or sharing. Only the owner, or a role that has the owner role's privileges, can call it. Changes take effect on the next call in every session.

Parameters

ParameterTypeDefaultDescription
nameTEXTRequiredCredential name.
credentialsJSONBNULLNew secret. '{}' removes the secret.
credentials_envTEXTNULLNew environment variable to read the secret from. Superusers and members of aidb_admins only.
credentials_k8s_secretTEXTNULLNew path to read the secret from. Superusers and members of aidb_admins only.
endpointTEXTNULLNew endpoint pattern.
shareBOOLEANNULLtrue shares the credential with every member of aidb_users. false makes it private.

Arguments that are NULL stay unchanged. Pass at most one of credentials, credentials_env, and credentials_k8s_secret.

Example

SELECT aidb.update_credential(
    'openai_prod',
    credentials => '{"api_key": "sk-new"}'::JSONB,
    endpoint    => 'api.openai.com'
);

aidb.delete_credential

Deletes a credential and its secret. Only the owner, or a role that has the owner role's privileges, can call it.

Parameters

ParameterTypeDefaultDescription
nameTEXTRequiredCredential name.
cascadeBOOLEANfalseIf true, also deletes every model that uses the credential, including models other roles created. Required if any model uses the credential.

The built-in none credential can't be deleted.

Example

SELECT aidb.delete_credential('openai_prod', cascade => true);

aidb.validate_endpoint_pattern

Checks an endpoint pattern and returns it in normalized form. Raises an error if the pattern is invalid.

Parameters

ParameterTypeDescription
patternTEXTEndpoint pattern to check.

Example

SELECT aidb.validate_endpoint_pattern('api.openai.com, .openai.azure.com');

aidb.endpoint_host

Returns the host a model of the given provider calls for the given URL. If url is NULL, returns the provider's default host.

Parameters

ParameterTypeDescription
providerTEXTProvider name.
urlTEXTURL from the model's config.

Example

SELECT aidb.endpoint_host('openai_completions', 'https://myorg.openai.azure.com/v1/chat/completions');
Output
      endpoint_host
--------------------------
 myorg.openai.azure.com
(1 row)

HCP model functions

These functions manage models running on EDB Hybrid Manager (HM).

aidb.list_hcp_models

Lists models currently running on HM.

Returns

ColumnTypeDescription
nametextModel instance name on HCP
urltextAPI endpoint URL
modeltextModel identifier

Example

SELECT * FROM aidb.list_hcp_models();
Output
             name              |                         url                          |            model
-------------------------------+------------------------------------------------------+------------------------------
 llama-3-1-8b-instruct-1xgpu   | http://llama-3-1-8b-predictor.default.svc.local      | meta/llama-3.1-8b-instruct
(1 row)

aidb.create_hcp_model

Registers an HCP-hosted model by referencing its running instance name.

Parameters

ParameterTypeDescription
nameTEXTUser-defined name for the model in AIDB.
hcp_model_nameTEXTName of the model instance running on HCP.

aidb.sync_hcp_models

Synchronizes the AIDB model registry with models currently running on HCP. Creates entries for new HCP models and deletes entries for models no longer running there.

Returns

ColumnTypeDescription
statustextcreated, deleted, unchanged, or skipped
modeltextName of the synchronized model

Inference functions

Note

aidb.generate_text() and aidb.generate_text_batch() were previously named aidb.decode_text() and aidb.decode_text_batch(). The old names still work but are deprecated and will be removed in a future version — use the new names in new code.

aidb.encode_text

Encodes a single text string into a vector using the specified model.

Parameters

ParameterTypeDescription
model_nameTEXTName of the registered model.
inputTEXTText to encode.

Returns

real[] — the embedding for the input text. Cast to vector to use with pgvector operators.

Example

SELECT aidb.encode_text('bert', 'The quick brown fox');

aidb.encode_text_batch

Encodes an array of text strings into vectors in a single call.

Parameters

ParameterTypeDescription
model_nameTEXTName of the registered model.
inputTEXT[]Array of strings to encode.

Returns

SETOF real[] — one row per input, in input order. The result column is named encode_text_batch.

Example

SELECT * FROM aidb.encode_text_batch('bert', ARRAY['The quick brown fox', 'Lorem ipsum dolor sit amet']);

aidb.encode_image

Encodes a binary image into a vector using a multimodal model (for example, CLIP).

Parameters

ParameterTypeDescription
model_nameTEXTName of the registered model.
inputBYTEARaw image bytes.

Returns

real[] — the embedding for the input image. Cast to vector to use with pgvector operators.

Example

SELECT aidb.encode_image('clip', pg_read_binary_file('/tmp/photo.jpg')::BYTEA);

aidb.generate_text

Generates a text response from a prompt using the specified model.

Parameters

ParameterTypeDefaultDescription
model_nameTEXTRequiredName of the registered model.
inputTEXTRequiredText prompt or input.
inference_configJSONNULLRuntime inference settings. Use aidb.inference_config(). Cast the result to json.

Returns

TEXT — the generated response.

Examples

-- Basic usage
SELECT aidb.generate_text('t5', 'translate to French: Hello, world.');

-- With inference configuration
SELECT aidb.generate_text(
    'my_llama',
    'Explain quantum computing in one sentence.',
    aidb.inference_config(
        system_prompt => 'Be concise and factual.',
        temperature   => 0.7,
        max_tokens    => 100
    )::json
);

aidb.generate_text_batch

Generates text responses for an array of prompts in a single call.

Parameters

ParameterTypeDefaultDescription
model_nameTEXTRequiredName of the registered model.
inputTEXT[]RequiredArray of text prompts.
inference_configJSONNULLRuntime inference settings. Use aidb.inference_config(). Cast the result to json.

Returns

SETOF TEXT — one row per input prompt, in input order. The result column is named generate_text_batch.

Example

SELECT aidb.generate_text_batch('t5', ARRAY[
    'translate to German: hello',
    'translate to German: goodbye'
]);

aidb.rerank_text

Scores and ranks a set of text inputs against a query using a reranking model.

Parameters

ParameterTypeDefaultDescription
model_nameTEXTRequiredName of a registered reranking model.
queryTEXTRequiredThe query to rank inputs against.
inputTEXT[][]Array of candidate texts to rank.

Returns

ColumnTypeDescription
texttextThe candidate text
logit_scoredouble precisionRelevance score (higher = more relevant)
idintOriginal index of the text in the input array

Example

SELECT * FROM aidb.rerank_text(
    'my_reranker',
    'How do I configure AIDB?',
    ARRAY[
        'AIDB requires shared_preload_libraries.',
        'Postgres supports JSON natively.',
        'Run CREATE EXTENSION aidb CASCADE to install.'
    ]
) ORDER BY logit_score DESC;

Inference configuration helper

aidb.inference_config

Builds a JSONB configuration object for runtime inference settings. Pass the result (cast to json) to aidb.generate_text(), aidb.generate_text_batch(), or use it with aidb.summarize_text_config().

All parameters are optional — omit any you don't need.

Parameters

ParameterTypeDefaultDescription
system_promptTEXTNULLSystem prompt prepended to the request. Not supported by T5 models.
temperatureDOUBLE PRECISIONNULLSampling temperature. 0.0 is deterministic; higher values increase variety.
max_tokensINTEGERNULLMaximum tokens to generate.
top_pDOUBLE PRECISIONNULLNucleus sampling threshold.
seedBIGINTNULLRandom seed for reproducible outputs.
repeat_penaltyREALNULLPenalty for repeating tokens. 1.0 = no penalty. Not supported by NIM or OpenAI.
repeat_last_nINTEGERNULLNumber of recent tokens considered for repeat_penalty. Not supported by NIM or OpenAI.
thinkingBOOLEANNULLfalse turns model reasoning off and removes <think> blocks from the output. true turns reasoning on. NULL leaves the model's default. Supported by llamacpp_generate, anthropic_messages, openai_responses, and OpenAI-compatible chat completion providers.
extra_argsJSONBNULLAdditional provider-specific arguments passed directly to the API.

Returns

JSONB — cast to ::json before passing to inference functions.

Examples

-- With temperature and token limit
SELECT aidb.generate_text(
    'my_llama',
    'What is machine learning?',
    aidb.inference_config(temperature => 0.5, max_tokens => 150)::json
);

-- Full configuration
SELECT aidb.generate_text(
    'my_llama',
    'Explain relativity.',
    aidb.inference_config(
        system_prompt  => 'You are a physics professor. Be precise.',
        temperature    => 0.3,
        max_tokens     => 200,
        top_p          => 0.9,
        seed           => 42,
        repeat_penalty => 1.1
    )::json
);

-- Hide reasoning tags from a thinking model
SELECT aidb.generate_text(
    'my_reasoning_model',
    'Solve: 2x + 5 = 15',
    aidb.inference_config(thinking => false)::json
);

Tool calling and structured output

Three more inference settings exist but aren't exposed as named parameters of aidb.inference_config() — build them as raw JSON instead, merged with the helper's output using || if you also need other settings. Only llamacpp_generate, openai_responses (+ openai_responses_azure), and anthropic_messages (+ anthropic_messages_azure/anthropic_messages_bedrock) honor these; every other provider rejects them.

FieldTypeDescription
toolsJSONB arrayOpenAI-compatible tools array — function definitions the model can call.
tool_choiceJSONBOpenAI-compatible tool_choice: the string "auto", "required", or "none", or {"type": "function", "function": {"name": "..."}} to force a specific tool.
response_formatJSONBStructured output. {"type": "json_schema", "json_schema": {"schema": {...}}} constrains the response to a JSON schema. Mutually exclusive with tools/tool_choice on openai_responses and anthropic_messages (and their variants).
Note

openai_responses and anthropic_messages (and their Azure/Bedrock variants) map these to each API's native tools/tool_choice request fields and parse real tool-call responses back — see OpenAI Responses API and Anthropic Messages API. Every other remote provider (openai_completions, gemini, nim_completions, and so on) rejects tools/tool_choice/response_format outright — this rejection only applies to direct calls like aidb.generate_text(). Any of those providers (except t5_local) can still back an AI agent; the agent framework falls back to simulating tool calls by describing them in the prompt and parsing the model's reply, rather than using these three fields.

-- Tool calling
SELECT aidb.generate_text(
    'my_llamacpp_chat',
    'What is the weather in Paris?',
    (aidb.inference_config(temperature => 0.2) || jsonb_build_object(
        'tools', jsonb_build_array(
            jsonb_build_object(
                'type', 'function',
                'function', jsonb_build_object(
                    'name', 'get_weather',
                    'description', 'Get current weather for a city',
                    'parameters', jsonb_build_object(
                        'type', 'object',
                        'properties', jsonb_build_object('city', jsonb_build_object('type', 'string')),
                        'required', jsonb_build_array('city')
                    )
                )
            )
        ),
        'tool_choice', 'auto'
    ))::json
);

-- Structured output
SELECT aidb.generate_text(
    'my_llamacpp_chat',
    'Extract the city from: I live in Paris.',
    jsonb_build_object(
        'response_format', jsonb_build_object(
            'type', 'json_schema',
            'json_schema', jsonb_build_object(
                'schema', jsonb_build_object(
                    'type', 'object',
                    'properties', jsonb_build_object('city', jsonb_build_object('type', 'string')),
                    'required', jsonb_build_array('city')
                )
            )
        )
    )::json
);

Model config helpers

These functions return a JSONB configuration object for the config parameter of aidb.create_model(). Each helper corresponds to a specific model provider.

Several helpers accept api_key and basic_auth parameters. Don't use them: aidb.create_model() rejects a config that contains either key. Pass the secret through create_model()'s credentials argument instead.

For the local providers bert_local, clip_local, t5_local, and llama_instruct_local, the config key that names the Hugging Face repository is hf_model. The helpers below write it under the old name model, which these providers still accept with a deprecation warning. To avoid the warning, build the config with jsonb_build_object('hf_model', ...) instead of the helper.

aidb.embeddings_config

For openai_embeddings and any OpenAI-compatible embeddings endpoint.

ParameterTypeDefaultDescription
modelTEXTRequiredModel identifier.
api_keyTEXTNULLAPI key.
urlTEXTNULLEndpoint URL override.
basic_authTEXTNULLBasic auth (user:password).
max_concurrent_requestsINTEGERNULLMax concurrent requests.
max_batch_sizeINTEGERNULLMax inputs per batch.
input_typeTEXTNULLInput type hint (provider-specific).
input_type_queryTEXTNULLQuery input type hint (provider-specific).
tls_configJSONBNULLTLS configuration.
is_hcp_modelBOOLEANNULLtrue if model runs on HCP.

Example

SELECT aidb.create_model(
    'my_embedder',
    'openai_embeddings',
    config      => aidb.embeddings_config(
        model => 'text-embedding-3-small',
        url   => 'https://api.openai.com/v1'
    ),
    credentials => '{"api_key": "sk-..."}'::JSONB
);

aidb.completions_config

For openai_completions and any OpenAI-compatible completions endpoint.

ParameterTypeDefaultDescription
modelTEXTRequiredModel identifier.
api_keyTEXTNULLAPI key.
urlTEXTNULLEndpoint URL override.
basic_authTEXTNULLBasic auth (user:password).
system_promptTEXTNULLDefault system prompt.
temperatureDOUBLE PRECISIONNULLSampling temperature.
top_pDOUBLE PRECISIONNULLNucleus sampling threshold.
seedBIGINTNULLRandom seed.
thinkingBOOLEANNULLfalse turns model reasoning off; true turns it on; NULL leaves the model's default.
max_tokensJSONBNULLMax tokens config (use aidb.max_tokens_config()).
max_concurrent_requestsINTEGERNULLMax concurrent requests.
extra_argsJSONBNULLAdditional provider-specific arguments.
is_hcp_modelBOOLEANNULLtrue if model runs on HCP.

Example

SELECT aidb.create_model(
    'my_llm',
    'openai_completions',
    config      => aidb.completions_config(
        model       => 'gpt-4o',
        temperature => 0.2
    ),
    credentials => '{"api_key": "sk-..."}'::JSONB
);
Note

For agentic use with reliable, native tool calling on OpenAI models, use openai_responses instead — see Tool calling and structured output for how the two providers differ, and Agents for building an agent around either one.


aidb.max_tokens_config

Builds the max_tokens object for use with aidb.completions_config().

ParameterTypeDefaultDescription
sizeINTEGERRequiredMaximum tokens to generate.
formatTEXTNULLFormat: 'default', 'legacy', or 'both'.

Example

SELECT aidb.completions_config(
    model      => 'gpt-4o',
    max_tokens => aidb.max_tokens_config(size => 1024, format => 'default')
);

aidb.bert_config

For the bert_local provider.

ParameterTypeDefaultDescription
modelTEXTRequiredHuggingFace model identifier.
revisionTEXTNULLModel revision or branch.
cache_dirTEXTNULLLocal cache directory.

Example

SELECT aidb.create_model('my_bert', 'bert_local',
    config => aidb.bert_config('sentence-transformers/all-MiniLM-L6-v2'));

aidb.clip_config

For the clip_local provider.

ParameterTypeDefaultDescription
modelTEXTRequiredHuggingFace model identifier.
revisionTEXTNULLModel revision or branch.
cache_dirTEXTNULLLocal cache directory.
image_sizeINTEGERNULLInput image size in pixels.

Example

SELECT aidb.create_model('my_clip', 'clip_local',
    config => aidb.clip_config('openai/clip-vit-base-patch32'));

aidb.llama_config

For the llama_instruct_local provider.

ParameterTypeDefaultDescription
modelTEXTRequiredModel identifier or HuggingFace path.
revisionTEXTNULLModel revision.
cache_dirTEXTNULLLocal cache directory.
model_pathTEXTNULLExplicit local path to model weights (overrides model).
system_promptTEXTNULLDefault system prompt.
temperatureDOUBLE PRECISIONNULLSampling temperature.
top_pDOUBLE PRECISIONNULLNucleus sampling threshold.
seedBIGINTNULLRandom seed.
sample_lenINTEGERNULLMax tokens to generate.
repeat_penaltyREALNULLRepetition penalty.
repeat_last_nINTEGERNULLTokens considered for repetition penalty.
use_flash_attentionBOOLEANNULLEnable flash attention.
use_kv_cacheBOOLEANNULLEnable KV cache.

Example

SELECT aidb.create_model('my_llama', 'llama_instruct_local',
    config => aidb.llama_config(
        'meta-llama/Llama-3.2-3B-Instruct',
        temperature => 0.5
    )
);

aidb.t5_config

For the t5_local provider.

ParameterTypeDefaultDescription
modelTEXTRequiredModel identifier or HuggingFace path.
revisionTEXTNULLModel revision.
model_pathTEXTNULLExplicit local path to model weights.
cache_dirTEXTNULLLocal cache directory.
temperatureDOUBLE PRECISIONNULLSampling temperature.
top_pDOUBLE PRECISIONNULLNucleus sampling threshold.
seedBIGINTNULLRandom seed.
max_tokensINTEGERNULLMax tokens to generate.
repeat_penaltyREALNULLRepetition penalty.
repeat_last_nINTEGERNULLTokens considered for repetition penalty.

Example

SELECT aidb.create_model('my_t5', 't5_local',
    config => aidb.t5_config('google/flan-t5-base'));

aidb.gemini_config

For the gemini provider.

ParameterTypeDefaultDescription
api_keyTEXTRequiredPass NULL. Supply the key through create_model()'s credentials argument.
modelTEXTNULLGemini model identifier (for example, gemini-2.0-flash).
urlTEXTNULLAPI endpoint override.
max_concurrent_requestsINTEGERNULLMax concurrent requests.
thinking_budgetINTEGERNULLExtended thinking token budget (Gemini 2.x only).

Example

SELECT aidb.create_model('my_gemini', 'gemini',
    config      => aidb.gemini_config(api_key => NULL, model => 'gemini-2.0-flash'),
    credentials => '{"api_key": "AIza..."}'::JSONB);
Note

aidb.gemini_config()'s first parameter is api_key and has no default. Pass NULL for it and supply the real key through create_model()'s credentials argument. aidb.create_model() rejects a config that contains api_key.


aidb.nim_clip_config

For the nim_clip provider (NVIDIA NIM multimodal embeddings).

ParameterTypeDefaultDescription
api_keyTEXTNULLNIM API key.
modelTEXTNULLNIM CLIP model identifier.
urlTEXTNULLNIM endpoint URL override.
basic_authTEXTNULLBasic auth credentials.
is_hcp_modelBOOLEANNULLtrue if model runs on HCP.

Example

SELECT aidb.create_model('my_nim_clip', 'nim_clip',
    config      => aidb.nim_clip_config(model => 'nvidia/nvclip'),
    credentials => '{"api_key": "nvapi-..."}'::JSONB);

aidb.nim_ocr_config

For the nim_paddle_ocr provider (NVIDIA NIM OCR).

ParameterTypeDefaultDescription
api_keyTEXTNULLNIM API key.
modelTEXTNULLNIM OCR model identifier.
urlTEXTNULLNIM endpoint URL override.
basic_authTEXTNULLBasic auth credentials.
is_hcp_modelBOOLEANNULLtrue if model runs on HCP.

Example

SELECT aidb.create_model('my_nim_ocr', 'nim_paddle_ocr',
    config      => aidb.nim_ocr_config(),
    credentials => '{"api_key": "nvapi-..."}'::JSONB);

aidb.nim_reranking_config

For the nim_reranking provider.

ParameterTypeDefaultDescription
api_keyTEXTNULLNIM API key.
modelTEXTNULLNIM reranking model identifier.
urlTEXTNULLNIM endpoint URL override.
basic_authTEXTNULLBasic auth credentials.
is_hcp_modelBOOLEANNULLtrue if model runs on HCP.

Example

SELECT aidb.create_model('my_reranker', 'nim_reranking',
    config      => aidb.nim_reranking_config(model => 'nvidia/nv-rerankqa-mistral-4b-v3'),
    credentials => '{"api_key": "nvapi-..."}'::JSONB
);

aidb.openrouter_chat_config

For the openrouter_chat provider.

ParameterTypeDefaultDescription
modelTEXTRequiredOpenRouter model identifier.
api_keyTEXTNULLOpenRouter API key.
urlTEXTNULLAPI endpoint override.
max_concurrent_requestsINTEGERNULLMax concurrent requests.
max_tokensJSONBNULLMax tokens config (use aidb.max_tokens_config()).

Example

SELECT aidb.create_model('my_or_chat', 'openrouter_chat',
    config      => aidb.openrouter_chat_config('anthropic/claude-3-5-haiku'),
    credentials => '{"api_key": "sk-or-..."}'::JSONB
);

aidb.openrouter_embeddings_config

For the openrouter_embeddings provider.

ParameterTypeDefaultDescription
modelTEXTRequiredOpenRouter embeddings model identifier.
api_keyTEXTNULLOpenRouter API key.
urlTEXTNULLAPI endpoint override.
max_concurrent_requestsINTEGERNULLMax concurrent requests.
max_batch_sizeINTEGERNULLMax inputs per batch.

Example

SELECT aidb.create_model('my_or_embedder', 'openrouter_embeddings',
    config      => aidb.openrouter_embeddings_config('mistral/mistral-embed'),
    credentials => '{"api_key": "sk-or-..."}'::JSONB
);

aidb.openai_responses_config

For the openai_responses and openai_responses_azure providers.

ParameterTypeDefaultDescription
modelTEXTRequiredModel identifier (for example, gpt-5.1).
api_keyTEXTNULLAPI key for authentication.
basic_authTEXTNULLBasic auth credentials (user:password).
urlTEXTNULLAPI endpoint URL. Defaults to OpenAI's Responses endpoint for openai_responses; required for openai_responses_azure (no universal default — use your resource's endpoint).
max_concurrent_requestsINTEGER25Maximum concurrent requests to the endpoint.
system_promptTEXTNULLDefault system prompt, sent via the Responses API's native instructions field.
temperatureDOUBLE PRECISIONNULLSampling temperature.
max_output_tokensINTEGERNULLMaximum tokens to generate.
top_pDOUBLE PRECISIONNULLNucleus sampling threshold.
extra_argsJSONBNULLAdditional provider-specific arguments passed directly to the API.

Examples

-- OpenAI
SELECT aidb.create_model(
    'my_gpt',
    'openai_responses',
    config      => aidb.openai_responses_config(model => 'gpt-5.1'),
    credentials => '{"api_key": "sk-..."}'::JSONB
);

-- Azure AI Foundry
SELECT aidb.create_model(
    'my_gpt_azure',
    'openai_responses_azure',
    config      => aidb.openai_responses_config(
        model => 'gpt-5.1',
        url   => 'https://<resource>.openai.azure.com/openai/v1/responses'
    ),
    credentials => '{"api_key": "..."}'::JSONB
);

This provider natively supports the tools, tool_choice, and response_format fields described in Tool calling and structured output.


aidb.anthropic_messages_config

For the anthropic_messages, anthropic_messages_azure, and anthropic_messages_bedrock providers.

ParameterTypeDefaultDescription
modelTEXTRequiredModel identifier (for example, claude-opus-4-6, or a Bedrock model ID for the Bedrock variant).
api_keyTEXTNULLAPI key for authentication. For anthropic_messages_bedrock, this is a Bedrock API key (bearer token), not an AWS SigV4 credential.
basic_authTEXTNULLBasic auth credentials (user:password).
urlTEXTNULLAPI endpoint URL. Defaults to api.anthropic.com for anthropic_messages. Required for anthropic_messages_azure (your resource's Messages endpoint) and anthropic_messages_bedrock (the regional bedrock-runtime base endpoint — the model ID is appended automatically).
max_concurrent_requestsINTEGER25Maximum concurrent requests to the endpoint.
system_promptTEXTNULLDefault system prompt, sent via the Messages API's native system field.
temperatureDOUBLE PRECISIONNULLSampling temperature.
max_tokensINTEGER4096Maximum tokens to generate. Anthropic's Messages API requires this field; AIDB defaults it when omitted.
top_pDOUBLE PRECISIONNULLNucleus sampling threshold.
extra_argsJSONBNULLAdditional provider-specific arguments passed directly to the API.

Examples

-- Anthropic direct
SELECT aidb.create_model(
    'my_claude',
    'anthropic_messages',
    config      => aidb.anthropic_messages_config(model => 'claude-opus-4-6'),
    credentials => '{"api_key": "sk-ant-..."}'::JSONB
);

-- Azure AI Foundry
SELECT aidb.create_model(
    'my_claude_azure',
    'anthropic_messages_azure',
    config      => aidb.anthropic_messages_config(
        model => 'claude-opus-4-6',
        url   => 'https://<resource>.services.ai.azure.com/anthropic/v1/messages'
    ),
    credentials => '{"api_key": "..."}'::JSONB
);

-- AWS Bedrock
SELECT aidb.create_model(
    'my_claude_bedrock',
    'anthropic_messages_bedrock',
    config      => aidb.anthropic_messages_config(
        model => 'anthropic.claude-opus-4-6-v1:0',
        url   => 'https://bedrock-runtime.us-east-1.amazonaws.com'
    ),
    credentials => '{"api_key": "..."}'::JSONB
);

This provider natively supports the tools, tool_choice, and response_format fields described in Tool calling and structured output. Anthropic's Messages API has no native structured-output field, so response_format is implemented as a forced call to a synthetic tool — functionally equivalent, but it means response_format and tools/tool_choice can't be used in the same call.