Add hibernate-vector module: pgvector similarity search with Hibernate 7.4.17.Final and Spring Data JPA 4.2.0 (float[] to vector/halfvec, cosine and L2 in HQL and Criteria, SearchResults methods, HNSW plans from auto_explain and five ways a query stops using the index, recall vs hnsw.ef_search, filtered-search row loss, Spring AI PgVectorStore comparison; PostgreSQL 16.15, pgvector 0.8.7)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b4XrpfdpsacrvqnrBM
This commit is contained in:
Claude
2026-11-26 21:04:05 +05:30
parent 4c795e8b50
commit a12a47ae74
43 changed files with 2149 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# Regenerates every file under output/. Needs JDK 25, Maven 3.9, network access to Maven Central, and a PostgreSQL with
# pgvector on 127.0.0.1:55433 (user postgres, trust auth, database vec; scripts/start-postgres.sh starts one without Docker).
# T05 and T07 read the server log (/tmp/hibvec-pg/pg.log, override with -Dpg.log=...) for auto_explain output, so the
# server has to be local and its log readable by the user running the tests.
# ./scripts/start-postgres.sh && ./scripts/run-all.sh
set -euo pipefail
cd "$(dirname "$0")/.."
mvn -B clean test
ls -1 output
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Starts a throwaway PostgreSQL 16 with pgvector 0.8.7 on 127.0.0.1:55433, without Docker. Idempotent. Run as root in a disposable sandbox.
# PostgreSQL : Ubuntu 24.04 packages postgresql-16 and postgresql-server-dev-16 (apt)
# pgvector : built from the v0.8.7 tag of https://github.com/pgvector/pgvector (the Ubuntu package is 0.6.0)
# PostgreSQL refuses to run as root, so this creates a throwaway OS user (pgj).
set -euo pipefail
B="${BASE:-/tmp/hibvec-pg}"
PGPORT="${PGPORT:-55433}"
PGBIN=/usr/lib/postgresql/16/bin
if [ ! -f /usr/share/postgresql/16/extension/vector.control ] || ! grep -q "0.8.7" /usr/share/postgresql/16/extension/vector.control; then
apt-get install -y postgresql-16 postgresql-server-dev-16 build-essential git >/dev/null
rm -rf /tmp/pgvector-src
git clone -q --depth 1 --branch v0.8.7 https://github.com/pgvector/pgvector.git /tmp/pgvector-src
make -C /tmp/pgvector-src -s && make -C /tmp/pgvector-src -s install
fi
id pgj >/dev/null 2>&1 || useradd -m pgj
mkdir -p "$B"; chown pgj "$B"
if [ ! -f "$B/data/PG_VERSION" ]; then
su pgj -c "cd /tmp && $PGBIN/initdb -D $B/data -U postgres -A trust -E UTF8 >/dev/null"
fi
su pgj -c "$PGBIN/pg_ctl -D $B/data -o '-p $PGPORT -k /tmp' -l $B/pg.log -w start" || true
psql -h 127.0.0.1 -p "$PGPORT" -U postgres -Atc "select 1 from pg_database where datname='vec'" | grep -q 1 \
|| psql -h 127.0.0.1 -p "$PGPORT" -U postgres -Atc "create database vec"
psql -h 127.0.0.1 -p "$PGPORT" -U postgres -d vec -Atc "select version()"