Models reference v7

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

Catalog views

aidb.model_providers

Lists all available model providers registered in the system.

ColumnTypeDescription
server_namenameName of the model provider
server_descriptiontextDescription of the provider
server_optionstext[]Available configuration options

aidb.models

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

ColumnTypeDescription
nametextUser-defined name for the model
providertextModel provider name
optionsjsonbConfigured options for the model

Example

SELECT * FROM aidb.models;
Output
  name  |  provider  |    options
--------+------------+---------------
 bert   | bert_local | {"config={}"}
 clip   | clip_local | {"config={}"}
 t5     | t5_local   | {"config={}"}
(3 rows)

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.
credentialsJSONB'{}'Provider credentials (for example, {"api_key": "..."}).
replace_credentialsBOOLEANfalseIf true, updates stored credentials without re-creating the model.

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"
}

Examples

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

-- With config and credentials
SELECT aidb.create_model(
    name        => 'my_t5',
    provider    => 't5_local',
    config      => '{"param1": "value1"}'::JSONB,
    credentials => '{"token": "abcd"}'::JSONB
);

-- Rotate credentials without re-creating
SELECT aidb.create_model(
    name                => 'my_openai',
    provider            => 'openai_embeddings',
    config              => aidb.embeddings_config(model => 'text-embedding-3-small'),
    credentials         => '{"api_key": "<new-key>"}'::JSONB,
    replace_credentials => true
);

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
optionsjsonbConfigured options

Example

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

aidb.delete_model

Removes a model from the registry. Does not affect pipelines or knowledge bases that reference it until they are next executed.

Parameters

ParameterTypeDescription
model_nameTEXTName of the model to delete.

Returns

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

Example

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

HCP model functions

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

aidb.list_hcp_models

Lists models currently running on the Hybrid Manager.

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

aidb.encode_text

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

Parameters

ParameterTypeDescription
model_nameTEXTName of the registered model.
textTEXTText to encode.

Returns

VECTOR — the embedding for the input text.

Example

SELECT aidb.encode_text('bert_local', '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.
textTEXT[]Array of strings to encode.

Returns

TABLE(id INT, value VECTOR) — one row per input, preserving input order via id.


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.
imageBYTEARaw image bytes.

Returns

VECTOR — the embedding for the input image.

Example

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

aidb.encode_image_batch

Encodes an array of binary images into vectors in a single call.

Parameters

ParameterTypeDescription
model_nameTEXTName of the registered model.
imagesBYTEA[]Array of raw image bytes.

Returns

TABLE(id INT, value VECTOR) — one row per input image, preserving input order via id.


aidb.decode_text

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

Parameters

ParameterTypeDefaultDescription
model_nameTEXTRequiredName of the registered model.
textTEXTRequiredText prompt or input.
inference_configJSONNULLRuntime inference settings. Use aidb.inference_config().

Returns

TEXT — the generated response.

Examples

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

-- With inference configuration
SELECT aidb.decode_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.decode_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().

Returns

TABLE(id INT, value TEXT) — one row per input prompt.

Example

SELECT * FROM aidb.decode_text_batch('t5_local', 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.decode_text(), aidb.decode_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.
thinkingBOOLEANNULLControls <think> tag handling. true/NULL retains tags; false strips them.
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.decode_text(
    'my_llama',
    'What is machine learning?',
    aidb.inference_config(temperature => 0.5, max_tokens => 150)::json
);

-- Full configuration
SELECT aidb.decode_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.decode_text(
    'my_reasoning_model',
    'Solve: 2x + 5 = 15',
    aidb.inference_config(thinking => false)::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.

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.
SELECT aidb.create_model(
    'my_embedder',
    'openai_embeddings',
    config => aidb.embeddings_config(
        model   => 'text-embedding-3-small',
        api_key => 'sk-...',
        url     => 'https://api.openai.com/v1'
    )
);

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.
thinkingBOOLEANNULL<think> tag handling.
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.
SELECT aidb.create_model(
    'my_llm',
    'openai_completions',
    config => aidb.completions_config(
        model       => 'gpt-4o',
        api_key     => 'sk-...',
        temperature => 0.2
    )
);

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'.
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.
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.
SELECT aidb.create_model('my_clip', 'clip_local',
    config => aidb.clip_config('openai/clip-vit-base-patch32'));

aidb.llama_config

For the llama_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.
SELECT aidb.create_model('my_llama', 'llama_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.
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_keyTEXTRequiredGoogle API key.
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).
SELECT aidb.create_model('my_gemini', 'gemini',
    config => aidb.gemini_config('AIza...', model => 'gemini-2.0-flash'));

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.
SELECT aidb.create_model('my_nim_clip', 'nim_clip',
    config => aidb.nim_clip_config(api_key => 'nvapi-...', model => 'nvidia/nvclip'));

aidb.nim_ocr_config

For the nim_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.
SELECT aidb.create_model('my_nim_ocr', 'nim_ocr',
    config => aidb.nim_ocr_config(api_key => 'nvapi-...'));

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.
SELECT aidb.create_model('my_reranker', 'nim_reranking',
    config => aidb.nim_reranking_config(
        api_key => 'nvapi-...',
        model   => 'nvidia/nv-rerankqa-mistral-4b-v3'
    )
);

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()).
SELECT aidb.create_model('my_or_chat', 'openrouter_chat',
    config => aidb.openrouter_chat_config(
        'anthropic/claude-3-5-haiku',
        api_key => 'sk-or-...'
    )
);

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.
SELECT aidb.create_model('my_or_embedder', 'openrouter_embeddings',
    config => aidb.openrouter_embeddings_config(
        'mistral/mistral-embed',
        api_key => 'sk-or-...'
    )
);