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:
@@ -0,0 +1,22 @@
|
||||
# Spring AI 2.1.0 PgVectorStore on the same database (hash-based stand-in embeddings, 32 dimensions)
|
||||
# Hibernate ORM 7.4.17.Final (on the classpath), PostgreSQL 16.15, pgvector 0.8.7, JDK 25
|
||||
|
||||
== 1. What the store created by itself
|
||||
id uuid
|
||||
content text
|
||||
metadata json
|
||||
embedding vector(32)
|
||||
CREATE INDEX spring_ai_vector_index ON public.vector_store USING hnsw (embedding vector_cosine_ops)
|
||||
CREATE UNIQUE INDEX vector_store_pkey ON public.vector_store USING btree (id)
|
||||
|
||||
== 2. similaritySearch(query = 'vector search with Hibernate and Spring Data', topK = 3)
|
||||
0.5241 IN Spring Data JPA can run vector search methods that return SearchResults
|
||||
0.5051 IN Hibernate maps float arrays to pgvector columns with hibernate-vector
|
||||
0.5040 US Sourdough starter needs flour water and patience
|
||||
|
||||
== 3. The same search with filterExpression("country == 'US'")
|
||||
0.5040 US Sourdough starter needs flour water and patience
|
||||
0.1336 US HNSW indexes in PostgreSQL trade recall for speed
|
||||
|
||||
== 4. The SQL PostgreSQL ran for the filtered search (auto_explain)
|
||||
SELECT *, embedding <=> $1 AS distance FROM public.vector_store WHERE embedding <=> $2 < $3 AND metadata::jsonb @@ '$."country" == "US"'::jsonpath ORDER BY distance LIMIT $4
|
||||
Reference in New Issue
Block a user