Skip to content

pgvector-sql: pgvector's SQL layer - #31

Merged
JaimeStill merged 8 commits into
mainfrom
pgvector-sql
Nov 25, 2026
Merged

JaimeStill merged 8 commits into
mainfrom
pgvector-sql

Conversation

@JaimeStill

Copy link
Copy Markdown
Contributor

v1.data.extensions · task 3/5 · pgvector-sql

Summary

  • New module github.com/standards-lab/sqlate/postgres/pgvector: the catalog name vector, a
    metric table (l2, cosine, inner product → operator and vector_*_ops opclass), and pgvector's
    native forms exported to sqlint.
  • sqlate's root sqlint.toml lists the module under extensions. The check now fails if
    pgvector's export is refused or one of its forms doesn't compile.
  • The compose image builds pgvector 0.8.7 from source on postgres:19.0-alpine, under
    ARG PGVECTOR_VERSION. Currency watches that ARG.
  • A live integration tier in the new module proves the extension stage and the per-space partial
    HNSW index for every metric. mise run integration now runs both modules.
  • Changelogs: postgres/pgvector gets v0.1.0, and sqlint's Unreleased becomes v0.5.0.

Core changes

  1. The metric table, which pgvector-go builds on. Why: one source for which operator goes
    with which opclass.

    const Extension = "vector"
    type Metric struct{ Name, Operator, OpClass string }
    var L2, Cosine, InnerProduct Metric // <->/vector_l2_ops, <=>/vector_cosine_ops, <#>/vector_ip_ops
    func Metrics() []Metric
  2. pgvector's native forms:

    • six operators, named for their functions;
    • vector only in type positions (AS vector), vector(3);
    • halfvec and sparsevec;
    • USING hnsw and USING ivfflat;
    • 15 callable functions, keyed with () (for example cosine_distance());
    • the hnsw.* and ivfflat.* settings.

    Why: a finding reads "<=>" (cosine_distance, from …/postgres/pgvector), and a column named
    vector passes.

  3. The Dockerfile fetches pgvector with
    ADD https://github.com/pgvector/pgvector.git#v${PGVECTOR_VERSION}, then runs
    make with_llvm=no OPTFLAGS="" and make install with_llvm=no, and removes the build tools in
    the same layer. The image grows from 312 to 317 MB. Why: the official image is built with LLVM,
    and its clang isn't installed.

  4. Currency's generic ARG check: any ARG <NAME>_VERSION whose ADD names a GitHub
    .git#v${…} URL is compared with the repository's highest semver tag through
    git ls-remote --tags. Why: pgvector publishes tags, not GitHub releases.

  5. The per-space proof: one untyped vector column, with a partial index per space,
    USING hnsw ((embedding::vector(n)) <opclass>) WHERE space = <id>. A query that repeats the
    cast plans an index scan, the same query without the cast doesn't, and a wrong-dimension insert
    fails.

Verify

mise run check: ✓ 4 modules (build, vet, fmt, fix, tidy, test -race, lint 0 issues),
sqlint: ok under go.work, lint-context, lint-references

  1. mise run acceptance → ==> integration: postgres ok, then ==> integration: postgres/pgvector ok, and the stack resets. Exit 0.
  2. mise run db:up, then docker compose exec -T postgres psql -U app -d app -Atc "SELECT name, default_version FROM pg_available_extensions WHERE name='vector'" → vector|0.8.7.
    Then mise run db:reset.
  3. mise run currency → exit 0. In a copy with ARG PGVECTOR_VERSION=0.8.6 →
    compose/postgres/Dockerfile: pgvector/pgvector 0.8.6 -> 0.8.7, exit 1.
  4. A standard-tier pattern … ORDER BY embedding <=> {{probe}} in a fixture that lists the module
    under extensions → "<=>" (cosine_distance, from github.com/standards-lab/sqlate/postgres/pgvector) in a standard-tier file; declare the tier native and name the port. A pattern that uses vector only as a column → no finding.

Decided without you

  1. Function forms are keyed with a () suffix (cosine_distance()), so they don't collide with
    the operator forms named for the same function.

  2. The vector form needs ) or [ after AS vector, or a digit after vector(, so an alias
    AS vector and a table vector (id) pass.

  3. The pgvector module's tests copy sqlint's literal, identifier and comment stripping, rather than
    importing unreleased sqlint.

  4. The live proof reads the expected version from pg_available_extensions, not a literal 0.8.7.
    The plan assertion uses SET LOCAL enable_seqscan = off with 200 rows per space.

  5. Currency reads tags with git ls-remote, not gh api: no auth and no pagination.

  6. The standards review deleted a test that compared a constant to itself, and added the
    changelog's "Requires" line: sqlate v0.8.0 and sqlate/postgres v0.9.0, needed by the
    integration tier only.

  7. STANDARDS.md now names four modules and the postgres/pgvector sub-module.

  8. Dropped decisions now expressed in code or docs:

    • "sqlint stays unreleased; pgvector-sql adds sqlint/v0.5.0" (this brief's Release line and
      sqlint's changelog carry it);
    • pgvector's catalog name and metric table;
    • type forms only in type positions;
    • forms unit-tested by parsing sqlint.toml.

    Trimmed: the module-paths and Dockerfile decisions keep only what go-database relies on.

  9. New pending edits:

    • corrections to the coordinator's extensions note: make install also needs with_llvm=no,
      the catalog name is vector, and pgvector publishes tags only;
    • a backlog goal, sqlate-test-tier: vet and lint the tagged suites, a CI integration job, a
      lost Scan error in the live-test text helper, and the forms tests through sqlint.Lint
      once v0.5.0 is out.

Redirects and escalations

none

Merge danger: one-way door. Accepting pushes sqlint/v0.5.0 and postgres/pgvector/v0.1.0,
which make the extensions key, [export] reason, the extension finding format, and pgvector's
name, metric table and forms public. Blast radius: sqlate, and consumers of those two modules.
sqlate's merge waits on CI, and each tag waits on CI green on main.

Needs you: none

…t listing

Adds github.com/standards-lab/sqlate/postgres/pgvector (standard library only;
BurntSushi/toml v1.6.0 for tests): Extension = "vector", the Metric struct
(Name, Operator, OpClass), the vars L2, Cosine, InnerProduct, and Metrics(),
which returns a fresh slice in that order.

Its sqlint.toml exports pgvector's native forms. Operators keep pgvector's
function names (l2_distance, cosine_distance, ...); the functions that share
those names are keyed with a "()" suffix ("cosine_distance()"), and every
function form carries it for uniformity. Settings are keyed "hnsw.*" and
"ivfflat.*". The vector type form matches a cast's "AS vector" before ")" or
"[" and "vector(" followed by a dimension digit, so an alias "AS vector" and a
table "vector (id)" pass. All forms are case-insensitive, as unquoted SQL is.

Unit tests parse the module's own sqlint.toml, compile each form as sqlint
does (regexp.Compile, no added flags), strip literals, quoted identifiers and
comments as sqlint does, and require each positive sample to match its form
alone and no portable statement to match any.

The root sqlint.toml lists the module under extensions as a test-only listing;
go.work and GO_MODULES include it. sqlint's Unreleased becomes v0.5.0, and the
module's changelog records v0.1.0, both dated 2026-11-24. The guide gains the
module's section, its metric table and forms, and why the root lists it.
- compose/postgres/Dockerfile stays FROM postgres:19.0-alpine and builds
  pgvector from source: ARG PGVECTOR_VERSION=0.8.7, fetched by ADD from
  pgvector's git repository at v${PGVECTOR_VERSION}, built with
  with_llvm=no (make and make install) and OPTFLAGS="" (make), with the
  build-base virtual package and the source removed in the same layer.
  The image grows from 312 MB to 317 MB and offers vector 0.8.7.
- scripts/currency.sh gains a generic Dockerfile ARG check: an
  ARG <NAME>_VERSION=<v> whose ADD line fetches
  https://github.com/<owner>/<repo>.git#v${<NAME>_VERSION} is compared
  with the repository's highest vX.Y.Z tag. Tags are read with
  git ls-remote --tags --refs (no pagination, no auth, no releases);
  pre-release tags are ignored by the pattern; no matching tag or a
  failed lookup fails currency.
- The guide: README's Development paragraph names both pins and what
  currency compares; docs/features.md gains "An image with pgvector",
  with the canonical Dockerfile a consumer copies, the reasons for the
  build flags, and the currency ARG check. The currency task's
  description and the script header name the ARG check.
…the per-space recipe

- postgres/pgvector gains an integration tier behind the integration build
  tag, on SQLATE_DSN and pgtest. extension_live_test.go: a declaration of
  pgvector.Extension through pgtest.MigratedWith installs vector at the
  image's default version (read from pg_available_extensions, not
  hard-coded); Extensions reports it current and Verify passes; a removal
  is refused with an *ExtensionError over sqlate.ErrDependentObjects while
  a vector(3) column depends on it, and succeeds once a set migration
  drops the column. The pending case is left to postgres's hstore proof.
- space_live_test.go builds one space per metric from pgvector.Metrics()
  (space i+1, dimension i+3) over one untyped vector column, each with a
  partial HNSW index over embedding::vector(n) with the metric's opclass
  WHERE space = id, and 200 seeded rows per space. Each step is its own
  migration. The plan assertion runs EXPLAIN in a transaction under
  SET LOCAL enable_seqscan = off: the cast query names "Index Scan using
  <its index>", the uncast query names none of the space indexes, and an
  insert of n+1 dimensions fails with "expected n dimensions".
- go.mod requires sqlate/postgres v0.9.0 and sqlate v0.8.0, resolved from
  the proxy with GOWORK=off.
- mise run integration loops over postgres and postgres/pgvector, so
  acceptance covers both.
- The guide: README's module bullet notes the tests take postgres for
  pgtest, the integration line names both modules, and a paragraph says
  the tier covers two modules and runs on a developer's machine, not CI.
  docs/features.md gains "A space per dimension on one column" (the
  recipe, its repeated cast, its dimension check) and "The integration
  tier" in the pgvector section.
… values (tests-and-docs: a test that can fail)

The extension's catalog name and each metric's operator and opclass are
proved against the image by the integration tier.
…ates its requirements (tests-and-docs, release-and-ci)
@JaimeStill
JaimeStill merged commit 43ace29 into main Nov 25, 2026
1 check passed
@JaimeStill
JaimeStill deleted the pgvector-sql branch November 25, 2026 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant