Skip to content

Artisan Commands

Run the initial setup: publishes the configuration file, runs migrations, and creates the knowledge directory structure.

Terminal window
php artisan sql-agent:install
php artisan sql-agent:install --force # Overwrite existing files

Set up pgvector support. This command publishes the embeddings migration and runs it to create the extension, table, and index on your pgvector connection.

Requires the pgvector/pgvector package:

Terminal window
composer require pgvector/pgvector
php artisan sql-agent:setup-pgvector

The command will:

  1. Verify that the pgvector/pgvector package is installed
  2. Verify that SQL_AGENT_EMBEDDINGS_CONNECTION is set and points to a PostgreSQL database
  3. Skip if the sql_agent_embeddings table already exists
  4. Publish the pgvector embeddings migration
  5. Ask to run migrations (which creates the extension, table, and HNSW index)

Import knowledge files from disk into the database. Required after creating or changing knowledge files.

Terminal window
php artisan sql-agent:load-knowledge
OptionDescription
--recreateDrop and recreate all knowledge before loading
--tablesLoad only table metadata
--rulesLoad only business rules
--queriesLoad only query patterns
--path=<path>Load from a custom directory instead of the configured path

Run evaluation tests to measure the agent’s accuracy against known test cases.

Terminal window
php artisan sql-agent:eval
OptionDescription
--category=<cat>Filter by category (basic, aggregation, complex, etc.)
--llm-graderUse an LLM to semantically grade responses
--golden-sqlCompare results against golden SQL output
--connection=<conn>Use a specific database connection
--detailedShow detailed output for failed tests
--jsonOutput results as JSON
--html=<path>Generate an HTML report at the given path
--seedSeed test cases before running

Export learnings to a JSON file for backup or sharing across environments.

Terminal window
php artisan sql-agent:export-learnings
php artisan sql-agent:export-learnings output.json
php artisan sql-agent:export-learnings --category=type_error

Available categories: type_error, schema_fix, query_pattern, data_quality, business_logic.

Import learnings from a previously exported JSON file.

Terminal window
php artisan sql-agent:import-learnings learnings.json
php artisan sql-agent:import-learnings learnings.json --force # Include duplicates

Remove old or duplicate learnings to keep the knowledge base clean.

Terminal window
php artisan sql-agent:prune-learnings
OptionDescription
--days=90Remove learnings older than N days (default: config value)
--duplicatesOnly remove duplicate learnings
--include-usedAlso remove learnings that have been referenced
--dry-runPreview what would be removed without deleting

Generate vector embeddings for existing knowledge base records. Required when switching to the pgvector search driver or after bulk-importing data.

Terminal window
php artisan sql-agent:generate-embeddings
php artisan sql-agent:generate-embeddings --model=query_patterns
php artisan sql-agent:generate-embeddings --force --batch-size=100
OptionDescription
--model=<name>Only generate for a specific model (query_patterns or learnings)
--forceRegenerate embeddings even if they already exist
--batch-size=50Number of records to process per batch (default: 50)

Purge SqlAgent data from the database by truncating the selected tables.

Terminal window
php artisan sql-agent:purge
OptionDescription
--conversationsOnly purge conversations and messages
--learningsOnly purge learnings
--knowledgeOnly purge knowledge (table metadata, business rules, query patterns)
--allPurge everything (default when no options specified)
--forceSkip the confirmation prompt

When --all is used (or no options are specified), evaluation test cases are also purged.