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
+31
View File
@@ -0,0 +1,31 @@
# float[] <-> vector(4): the DDL Hibernate generates, the round trip, the failure modes
# Hibernate ORM 7.4.17.Final (on the classpath), PostgreSQL 16.15, pgvector 0.8.7, JDK 25
== Versions seen at runtime
Hibernate ORM (org.hibernate.Version): 7.4.17.Final
server: PostgreSQL 16.15 (Ubuntu 16.15-0ubuntu0.24.04.1) on x86_64-pc-linux-gnu
== Column type Hibernate created for Doc.embedding (pg_attribute)
doc.embedding : vector(4)
== Insert and read back
-- insert
insert into doc (category,embedding,title) values (?,cast(? as vector),?)
read back float[]: [0.7, 0.7, 0.0, 0.0]
same values: true
how pgvector prints it: [0.7,0.7,0,0]
== Failure: a three-element array for a vector(4) column
DataIntegrityViolationException -> PSQLException: ERROR: expected 4 dimensions, not 3
== In-place change of the float[] is detected by dirty checking
-- update sent at commit
update doc set category=?,embedding=cast(? as vector),title=? where id=?
== Half precision: SqlTypes.VECTOR_FLOAT16 maps the same float[] to halfvec
half_doc.embedding : halfvec(4)
stored (embedding::text): [0.099975586,0.19995117,0.30004883,0.7001953]
read back float[]: [0.099975586, 0.19995117, 0.30004883, 0.7001953]
== Failure: cosine distance against the zero vector
select '[0,0,0,0]'::vector <=> '[1,2,3,4]'::vector -> NaN