Repository navigation
pgvector-sql: pgvector's SQL layer - #31
Merged
Merged
Conversation
…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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
v1.data.extensions · task 3/5 · pgvector-sql
Summary
github.com/standards-lab/sqlate/postgres/pgvector: the catalog namevector, ametric table (l2, cosine, inner product → operator and
vector_*_opsopclass), and pgvector'snative forms exported to sqlint.
sqlint.tomllists the module underextensions. The check now fails ifpgvector's export is refused or one of its forms doesn't compile.
postgres:19.0-alpine, underARG PGVECTOR_VERSION. Currency watches that ARG.HNSW index for every metric.
mise run integrationnow runs both modules.postgres/pgvectorgets v0.1.0, and sqlint's Unreleased becomes v0.5.0.Core changes
The metric table, which pgvector-go builds on. Why: one source for which operator goes
with which opclass.
pgvector's native forms:
vectoronly in type positions (AS vector),vector(3);halfvecandsparsevec;USING hnswandUSING ivfflat;()(for examplecosine_distance());hnsw.*andivfflat.*settings.Why: a finding reads
"<=>" (cosine_distance, from …/postgres/pgvector), and a column namedvectorpasses.The Dockerfile fetches pgvector with
ADD https://github.com/pgvector/pgvector.git#v${PGVECTOR_VERSION}, then runsmake with_llvm=no OPTFLAGS=""andmake install with_llvm=no, and removes the build tools inthe same layer. The image grows from 312 to 317 MB. Why: the official image is built with LLVM,
and its clang isn't installed.
Currency's generic ARG check: any
ARG <NAME>_VERSIONwhoseADDnames a GitHub.git#v${…}URL is compared with the repository's highest semver tag throughgit ls-remote --tags. Why: pgvector publishes tags, not GitHub releases.The per-space proof: one untyped
vectorcolumn, with a partial index per space,USING hnsw ((embedding::vector(n)) <opclass>) WHERE space = <id>. A query that repeats thecast 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: okunder go.work, lint-context, lint-referencesmise run acceptance→==> integration: postgresok, then==> integration: postgres/pgvectorok, and the stack resets. Exit 0.mise run db:up, thendocker 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.mise run currency→ exit 0. In a copy withARG PGVECTOR_VERSION=0.8.6→compose/postgres/Dockerfile: pgvector/pgvector 0.8.6 -> 0.8.7, exit 1.… ORDER BY embedding <=> {{probe}}in a fixture that lists the moduleunder
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 usesvectoronly as a column → no finding.Decided without you
Function forms are keyed with a
()suffix (cosine_distance()), so they don't collide withthe operator forms named for the same function.
The
vectorform needs)or[afterAS vector, or a digit aftervector(, so an aliasAS vectorand a tablevector (id)pass.The pgvector module's tests copy sqlint's literal, identifier and comment stripping, rather than
importing unreleased sqlint.
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 = offwith 200 rows per space.Currency reads tags with
git ls-remote, notgh api: no auth and no pagination.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.
STANDARDS.md now names four modules and the
postgres/pgvectorsub-module.Dropped decisions now expressed in code or docs:
sqlint/v0.5.0" (this brief's Release line andsqlint's changelog carry it);
sqlint.toml.Trimmed: the module-paths and Dockerfile decisions keep only what go-database relies on.
New pending edits:
make installalso needswith_llvm=no,the catalog name is
vector, and pgvector publishes tags only;sqlate-test-tier: vet and lint the tagged suites, a CI integration job, alost Scan error in the live-test
texthelper, and the forms tests throughsqlint.Lintonce v0.5.0 is out.
Redirects and escalations
none
Merge danger: one-way door. Accepting pushes
sqlint/v0.5.0andpostgres/pgvector/v0.1.0,which make the
extensionskey,[export] reason, the extension finding format, and pgvector'sname, 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