LLM & Search Drivers
SqlAgent uses Prism PHP for LLM integration and a driver-based architecture for knowledge search. You can switch providers and drivers via environment variables without changing any code.
LLM Providers (via Prism PHP)
Section titled “LLM Providers (via Prism PHP)”SqlAgent delegates all LLM communication to Prism PHP, which provides a unified interface for many providers. Set the active provider and model using environment variables:
SQL_AGENT_LLM_PROVIDER=openaiSQL_AGENT_LLM_MODEL=gpt-4oProvider credentials (API keys, base URLs) are configured in Prism’s own config file at config/prism.php. Publish it with:
php artisan vendor:publish --tag=prism-configAvailable Providers
Section titled “Available Providers”Prism supports a wide range of providers out of the box. Here are some common options:
| Provider | SQL_AGENT_LLM_PROVIDER | Example Model |
|---|---|---|
| OpenAI | openai | gpt-4o, gpt-4o-mini |
| Anthropic | anthropic | claude-sonnet-4-20250514 |
| Ollama | ollama | llama3.1, qwen2.5 |
| Google Gemini | gemini | gemini-2.0-flash |
| Mistral | mistral | mistral-large-latest |
| xAI | xai | grok-2 |
See the Prism documentation for the full list of supported providers and their configuration.
Provider-Specific Options
Section titled “Provider-Specific Options”Use the provider_options config array to pass provider-specific options. For example, to enable thinking/reasoning mode on Ollama models:
'llm' => [ 'provider' => 'ollama', 'model' => 'qwen2.5', 'provider_options' => ['thinking' => true],],These options are passed directly to Prism’s withProviderOptions() method.
Adding a Custom Provider
Section titled “Adding a Custom Provider”Since SqlAgent uses Prism for all LLM communication, adding a new provider means adding it to Prism. See the Prism documentation for instructions on registering custom providers.
Search Drivers
Section titled “Search Drivers”Search drivers control how SqlAgent finds relevant knowledge (table metadata, business rules, query patterns) based on the user’s question. Set the active driver using SQL_AGENT_SEARCH_DRIVER.
Database
Section titled “Database”Uses your database’s native full-text search capabilities. No external services required:
SQL_AGENT_SEARCH_DRIVER=databaseThe behavior varies by database engine:
| Database | Implementation | Notes |
|---|---|---|
| MySQL | MATCH ... AGAINST | Supports natural language and boolean mode |
| PostgreSQL | to_tsvector / to_tsquery | Configurable text search language |
| SQLite | LIKE queries | Less accurate, but functional for development |
| SQL Server | CONTAINS predicates | Requires a full-text catalog to be configured |
pgvector
Section titled “pgvector”Uses PostgreSQL’s pgvector extension for semantic similarity search via vector embeddings. This provides the most accurate search results by understanding the meaning of queries rather than just matching keywords.
The pgvector driver uses a dedicated PostgreSQL connection for storing embeddings, separate from your main application database. This means you can use MySQL, SQLite, or any other database for your app and SqlAgent storage while running pgvector on a specialized PostgreSQL instance.
Installation
Section titled “Installation”The pgvector search driver requires the pgvector/pgvector Composer package, which is not installed by default:
composer require pgvector/pgvectorConfiguration
Section titled “Configuration”Add a PostgreSQL connection to config/database.php:
'connections' => [ 'pgvector' => [ 'driver' => 'pgsql', 'host' => env('PGVECTOR_HOST', '127.0.0.1'), 'port' => env('PGVECTOR_PORT', '5432'), 'database' => env('PGVECTOR_DATABASE', 'embeddings'), 'username' => env('PGVECTOR_USERNAME', 'postgres'), 'password' => env('PGVECTOR_PASSWORD', ''), ],],Set the environment variables in your .env:
SQL_AGENT_SEARCH_DRIVER=pgvectorSQL_AGENT_EMBEDDINGS_CONNECTION=pgvectorSQL_AGENT_EMBEDDINGS_PROVIDER=openaiSQL_AGENT_EMBEDDINGS_MODEL=text-embedding-3-smallSQL_AGENT_EMBEDDINGS_DIMENSIONS=1536Setting Up the Database
Section titled “Setting Up the Database”Run the setup command to publish the pgvector migration and create the embeddings table:
php artisan sql-agent:setup-pgvectorThis command will:
- Verify that
SQL_AGENT_EMBEDDINGS_CONNECTIONpoints to a PostgreSQL database - Publish the embeddings migration
- Run migrations (creates the extension, table, and HNSW index)
Then generate embeddings for any existing knowledge base records:
php artisan sql-agent:generate-embeddingsEmbeddings are automatically kept in sync when records are created or updated.