How to Use Local AI Models with DBX's AI SQL Assistant: Ollama & OpenAI-Compatible Setup
Yes, DBX's AI SQL Assistant fully supports local AI models via Ollama and any OpenAI-compatible API endpoint, automatically rewriting endpoints to the chat completion URL and disabling API-key authentication for local deployments.
The t8y2/dbx repository provides a privacy-first database explorer with an integrated AI SQL Assistant that can run entirely on your local machine. By implementing an OpenAI-compatible interface, DBX allows you to use local AI models with DBX's AI SQL Assistant through Ollama or other self-hosted servers, ensuring sensitive database schemas and queries never leave your environment.
How Local AI Integration Works in DBX
DBX uses a dual-layer architecture to handle AI provider configuration. The system determines which provider to use from the AI settings stored in the desktop application, then processes requests through a core Rust module that handles endpoint resolution and HTTP client construction.
OpenAI-Compatible API Foundation
At the core of DBX's local AI support is the OpenAI chat-completion schema implementation found in crates/dbx-core/src/ai.rs. This module validates configurations, resolves endpoints, and builds the HTTP client for all providers. Because DBX treats local endpoints as OpenAI-compatible, you can point the assistant at any self-hosted server—including vLLM, LMStudio, or custom implementations—by providing the appropriate URL in the settings.
Ollama-Specific Endpoint Transformation
When the provider is set to ollama, DBX automatically applies specific transformations in crates/dbx-core/src/ai.rs:
- Endpoint Rewriting: The base URL (e.g.,
http://localhost:11434/v1) is automatically rewritten to the chat completion endpoint (/v1/chat/completions) - Authentication Disabled: The
requiresApiKeyflag is set tofalse, allowing requests without API keys since Ollama does not require authentication for local access - Safety Checks Maintained: All returned SQL still passes through DBX's built-in safety validation before execution
Setting Up Ollama for DBX's AI SQL Assistant
Configure your local Ollama instance in four steps:
- Install Ollama and pull your preferred model (e.g.,
llama3.1) - Add the AI provider in DBX's Settings → AI SQL Assistant UI pointing to
http://localhost:11434/v1 - Select the Ollama provider from the dropdown—DBX automatically detects the localhost endpoint and sets
requiresApiKey: false - Use the assistant normally—your prompts route to the local model, and the returned SQL undergoes DBX's standard safety checks before injection into the editor
The default configuration stored in apps/desktop/src/stores/settingsStore.ts provides built-in presets for Ollama, automatically selecting the correct provider when it detects localhost:11434 in the endpoint URL.
Configuring Alternative Local Models (vLLM, LMStudio)
For local AI servers other than Ollama, use the OpenAI-compatible provider entry:
- Enter your self-hosted server URL (e.g.,
http://localhost:8000/v1for vLLM) - Specify the model name as defined by your local server
- Provide an API key if your local server requires authentication (most local deployments do not)
No code changes are required; DBX's normalization logic in apps/desktop/src/stores/settingsStore.ts handles the configuration formatting automatically.
Technical Deep Dive: Configuration and Normalization
Frontend Store Logic in settingsStore.ts
The frontend store located at apps/desktop/src/stores/settingsStore.ts defines the built-in AI provider presets, including the Ollama defaults. This TypeScript module exports a normalizeAiConfig function that ensures user-supplied configurations conform to the expected schema before transmission to the Rust core.
When you save an Ollama configuration, the store automatically sets:
{
"provider": "ollama",
"endpoint": "http://localhost:11434/v1",
"model": "llama3.1",
"apiStyle": "completions",
"requiresApiKey": false
}
Core Rust Implementation in ai.rs
The Rust module at crates/dbx-core/src/ai.rs contains the provider-agnostic HTTP client logic. For Ollama endpoints, this module performs the final URL transformation to append /chat/completions to the base path, ensuring compatibility with the OpenAI API specification while maintaining the local privacy benefits.
Practical Code Examples
Normalizing a Local AI Configuration
Use the store's normalization routine to prepare your config exactly as DBX processes it internally:
import { normalizeAiConfig } from '@/stores/settingsStore';
const rawConfig = {
provider: 'ollama',
endpoint: 'http://localhost:11434/v1',
model: 'llama3.1',
};
const cfg = normalizeAiConfig(rawConfig);
// cfg.endpoint → "http://localhost:11434/v1/chat/completions"
This transformation matches the logic found in crates/dbx-core/src/ai.rs that routes requests to the correct chat completion endpoint.
Sending Queries to Your Local Model
Once configured, invoke the assistant from the desktop UI:
await dbxAiClient.ask({
prompt: "Show me the top 10 customers by revenue last month",
model: cfg.model, // "llama3.1"
endpoint: cfg.endpoint, // "http://localhost:11434/v1/chat/completions"
});
The response is parsed, safety-checked against DBX's query validation rules, and injected into the SQL editor as executable code.
Summary
- DBX's AI SQL Assistant supports local AI models through any OpenAI-compatible API endpoint, with first-class support for Ollama as documented in
docs/public/llms.txtand the projectREADME.md. - Automatic Configuration: When using Ollama, DBX automatically rewrites endpoints to
/v1/chat/completionsand disables API-key requirements via logic incrates/dbx-core/src/ai.rs. - Frontend Integration: The
apps/desktop/src/stores/settingsStore.tsmodule provides presets and normalization for local providers. - Security: All generated SQL undergoes DBX's built-in safety checks regardless of whether the model is local or cloud-hosted.
- Flexibility: You can switch between cloud providers (Claude, OpenAI) and local models (Ollama, vLLM, LMStudio) without code changes by adjusting the Settings UI configuration.
Frequently Asked Questions
Does DBX's AI SQL Assistant support models other than Ollama?
Yes. While Ollama receives special handling for endpoint normalization, DBX supports any local model server implementing the OpenAI chat-completion schema. This includes vLLM, LMStudio, LocalAI, and custom HTTP servers. Configure these through the "OpenAI-compatible" provider entry with your local URL.
Is an API key required for local AI models in DBX?
No. When you select the Ollama provider or configure a localhost endpoint, DBX automatically sets requiresApiKey: false in the configuration. The core Rust logic in crates/dbx-core/src/ai.rs skips authentication headers for these endpoints, though you can manually specify a key if your local server requires custom authentication.
Can I switch between cloud and local AI models in DBX?
Yes. DBX stores multiple AI provider configurations in the desktop app settings. You can create entries for both cloud providers (OpenAI, Anthropic) and local models (Ollama), then switch between them using the provider selector in the AI SQL Assistant interface without restarting the application.
Where does DBX store the AI provider configuration?
Configuration persists in the desktop application's internal store managed by apps/desktop/src/stores/settingsStore.ts. This includes provider type, endpoint URLs, model names, and authentication requirements. The store normalizes these settings before passing them to the Rust core (crates/dbx-core/src/ai.rs) for request execution.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →