Configure AI providers for embedding generation and completion. Use SHOW AI PROVIDERS to see all available providers and their current status.
Sets the API key for an AI provider. Optionally activates it as the current provider.
| Syntax | ai.set_api_key(<provider>, <apiKey> [, <activate>]) | ||
| Arguments | Name | Type | Description |
<provider> | STRING | Provider name (see Supported Providers) | |
<apiKey> | STRING | The API key | |
<activate> | BOOL | Optional. Whether to set this as the active provider (default: true) | |
| Return Type | BOOL | ||
By default, calling ai.set_api_key() both sets the key and activates the provider:
GQLRETURN ai.set_api_key("openai", "sk-...")
Each provider stores one API key. Calling ai.set_api_key() again for the same provider overwrites the previous key. To set keys for multiple providers without activating them, pass false as the third argument, then use ai.set_provider() to switch:
GQLRETURN ai.set_api_key("gemini", "AQ.za...", false)
Sets the active embedding provider. The provider's API key must have been set first via ai.set_api_key().
| Syntax | ai.set_provider(<provider>) | ||
| Arguments | Name | Type | Description |
<provider> | STRING | Embedding provider name (see Supported Providers) | |
| Return Type | BOOL | ||
GQLRETURN ai.set_provider("openai")
Returns the name of the current embedding provider.
| Syntax | ai.provider() | ||
| Arguments | None | ||
| Return Type | STRING | ||
GQLRETURN ai.provider()
Returns the embedding dimension of the current provider. Returns null if no embedding provider is active or the provider doesn't support embedding.
| Syntax | ai.embed_dim() | ||
| Arguments | None | ||
| Return Type | INT | ||
GQLRETURN ai.embed_dim()
Overrides the embedding model for a given provider at runtime. The override is persisted and re-activates the affected provider, so subsequent ai.embed(), ai.embed_batch(), and vector-index inserts use the new model immediately.
NOTEWatch out for dimension changes. Switching models within the same provider often changes the embedding dimension (e.g. OpenAI
text-embedding-3-smallis 1536-dim,text-embedding-3-largeis 3072-dim). When the dimension changes, GQLDB emits a warning that includes the old and new dimensions; existing vector indexes were built for the previous dimension and must be rebuilt withai.rebuild_index()or query results will silently mismatch.
| Syntax | ai.set_embedding_model(<provider>, <model>) | ||
| Arguments | Name | Type | Description |
<provider> | STRING | Provider name (see Supported Providers). | |
<model> | STRING | The new embedding model name (provider-specific identifier, e.g. "text-embedding-3-large"). | |
| Return Type | BOOL | ||
GQLRETURN ai.set_embedding_model("openai", "text-embedding-3-large") -- If the dimension changes, rebuild any vector indexes that depended on the old model: RETURN ai.rebuild_index("summary_embedding")
Sets the active completion provider. The provider's API key must have been set first via ai.set_api_key().
| Syntax | ai.set_completion_provider(<provider>) | ||
| Arguments | Name | Type | Description |
<provider> | STRING | Provider name (see Supported Providers) | |
| Return Type | BOOL | ||
GQLRETURN ai.set_completion_provider("anthropic")
Returns the name of the current completion provider.
| Syntax | ai.completion_provider() | ||
| Arguments | None | ||
| Return Type | STRING | ||
GQLRETURN ai.completion_provider()
Overrides the completion model for a given provider at runtime. The override is persisted and re-activates the affected provider, so subsequent ai.gql(), ai.explain(), and other completion calls use the new model immediately.
Use this when you want to switch between models offered by the same provider (e.g. gpt-4o vs gpt-4o-mini on OpenAI, or claude-3-5-sonnet vs claude-3-5-haiku on Anthropic) without re-running ai.set_api_key() or ai.set_completion_provider().
| Syntax | ai.set_completion_model(<provider>, <model>) | ||
| Arguments | Name | Type | Description |
<provider> | STRING | Provider name (see Supported Providers). | |
<model> | STRING | The new completion model name (provider-specific identifier, e.g. "gpt-4o", "claude-3-5-sonnet"). | |
| Return Type | BOOL | ||
GQLRETURN ai.set_completion_model("openai", "gpt-4o")