Files
stack/infra/images/postgresql.Dockerfile
kert 666195e3fd fix(llm): rebuild pgvector without AVX-512 so HNSW builds on Zen2 (closes #580)
Upstream Bitnami vector.so was built -march=native on an AVX-512 host;
vector_norm's EVEX AVX-512 (vextractf64x2/vcvtusi2sd) SIGILLs the Ryzen
3950X during hnsw/ivfflat index builds, crashing the shared postgres.
infra/images/postgresql.Dockerfile rebuilds pgvector -march=x86-64-v3
FROM the mirror; compose + deploy.sh build fhirworx/postgresql:pgvector.
HNSW verified on the 15852-vector pilot (~2s, index scan). Flip
[llm].build_ann_index default to true.
2026-07-17 16:09:13 -04:00

41 lines
2.0 KiB
Docker

# Rebuild pgvector without AVX-512.
#
# The upstream Bitnami image (fhirworx/postgresql:latest — PostgreSQL 18.1 on
# VMware Photon) ships a vector.so built with pgvector's default
# OPTFLAGS=-march=native on an AVX-512-capable build host. On this server's
# Ryzen 9 3950X (Zen 2, no AVX-512) the hnsw/ivfflat index BUILD path SIGILLs:
# vector_norm() executes EVEX-encoded AVX-512 (vextractf64x2 @ 0x1fe11,
# vcvtusi2sd @ 0x121d4) that the CPU rejects, which crashes the whole server
# (every backend, gitea/nessie/polaris included, drops into recovery).
# Query-time distance ops were compiled as legal AVX2, so exact search works —
# only the index build faults. Rebuilding pgvector with -march=x86-64-v3
# (AVX2/FMA/BMI2, fully supported by Zen 2) keeps SIMD while dropping every
# AVX-512 encoding. See issue #580.
ARG BASE=fhirworx/postgresql:latest
ARG PGVECTOR_VERSION=0.8.1
ARG PGVECTOR_SHA256=a9094dfb85ccdde3cbb295f1086d4c71a20db1d26bf1d6c39f07a7d164033eb4
FROM ${BASE} AS build
ARG PGVECTOR_VERSION
ARG PGVECTOR_SHA256
USER 0
# hadolint ignore=DL3041
RUN tdnf install -y gcc binutils make glibc-devel linux-api-headers tar gzip curl && \
curl -fsSL "https://github.com/pgvector/pgvector/archive/refs/tags/v${PGVECTOR_VERSION}.tar.gz" \
-o /tmp/pgvector.tar.gz && \
echo "${PGVECTOR_SHA256} /tmp/pgvector.tar.gz" | sha256sum -c - && \
tar -xzf /tmp/pgvector.tar.gz -C /tmp && \
make -C "/tmp/pgvector-${PGVECTOR_VERSION}" OPTFLAGS="-march=x86-64-v3" with_llvm=no && \
make -C "/tmp/pgvector-${PGVECTOR_VERSION}" install
FROM ${BASE}
USER 0
# Installing glibc-devel above pulled a glibc update, so the rebuilt vector.so
# links against the newer glibc; bump the runtime glibc to match (glibc is
# backward-compatible, so the existing postgres binaries keep working). This
# installs only glibc — no build tools reach the final image.
# hadolint ignore=DL3041
RUN tdnf install -y glibc && tdnf clean all
COPY --from=build /opt/bitnami/postgresql/lib/vector.so /opt/bitnami/postgresql/lib/vector.so
USER 1001