Sentinel

PostgreSQL Store

Production-ready persistence with PostgreSQL, bun ORM, and embedded migrations.

The store/postgres package provides a production-ready implementation of the composite store.Store interface using PostgreSQL with the bun ORM.

Setup

import (
    "github.com/uptrace/bun"
    "github.com/xraph/sentinel/store/postgres"
)

db := connectDB() // your *bun.DB connection
pgStore := postgres.New(db)

// Run migrations
if err := pgStore.Migrate(ctx); err != nil {
    log.Fatal(err)
}

Tables

The PostgreSQL store creates the following tables:

TableEntityKey columns
sentinel_suitesSuitesid, app_id, name, system_prompt, model, persona_ref, metadata (JSONB)
sentinel_casesCasesid, suite_id, name, input, expected, scenario_type, scorers (JSONB), tags (JSONB)
sentinel_runsRunsid, suite_id, app_id, model, state, pass_rate, avg_score, dimension_scores (JSONB)
sentinel_resultsResultsid, run_id, case_id, status, score, output, scorer_results (JSONB), run_trace (JSONB)
sentinel_baselinesBaselinesid, suite_id, run_id, name, results (JSONB), dimension_scores (JSONB), is_current
sentinel_prompt_versionsPrompt versionsid, suite_id, version, system_prompt, changelog, is_current

JSONB columns

Complex nested structures are stored as JSONB columns:

  • Case scorers and tags → scorers JSONB, tags JSONB
  • Result scorer outputs and run trace → scorer_results JSONB, run_trace JSONB
  • Dimension scores → dimension_scores JSONB
  • All entities → metadata JSONB

Composite store interface

The PostgreSQL store implements all 5 sub-interfaces:

type Store interface {
    suite.Store         // 6 methods
    testcase.Store      // 7 methods
    evalrun.Store       // 5 methods
    baseline.Store      // 5 methods
    promptversion.Store // 5 methods

    Migrate(ctx context.Context) error
    Ping(ctx context.Context) error
    Close() error
}

Embedded migrations

Migrations are embedded in the binary using embed.FS and run automatically when Migrate() is called. There are 5 migration files:

  1. 001_suites.sql — Creates sentinel_suites
  2. 002_cases.sql — Creates sentinel_cases
  3. 003_runs.sql — Creates sentinel_runs and sentinel_results
  4. 004_baselines.sql — Creates sentinel_baselines
  5. 005_prompt_versions.sql — Creates sentinel_prompt_versions

Other store backends

BackendPackageUse case
PostgreSQLstore/postgresProduction
SQLitestore/sqliteDevelopment, testing, single-machine deployments
Memorystore/memoryUnit tests, ephemeral evaluations

All three backends implement the same store.Store interface identically.

Usage with engine

eng, err := engine.New(
    engine.WithStore(pgStore),
)

On this page