# The Criteria API: the same HQL functions through cb.function(...), and the float[] argument that must not be a literal # Hibernate ORM 7.4.17.Final (on the classpath), PostgreSQL 16.15, pgvector 0.8.7, JDK 25 == 1. Criteria with cb.parameter(float[].class): category = tech, top 3 query vector: [1, 0.5, 0, 0] -- generated SQL select d1_0.title,(d1_0.embedding<=>cast(? as vector)) from doc d1_0 where d1_0.category=? order by 2 fetch first ? rows only 0.0010 Spring Data repositories 0.0513 Hibernate batch inserts, long edition (same direction, 10x the length) 0.0513 Hibernate batch inserts == 2. The HQL version of the same query returns the same rows (the two tied rows may swap places) -- generated SQL select d1_0.title,(d1_0.embedding<=>cast(? as vector)) from doc d1_0 where d1_0.category=? order by (d1_0.embedding<=>cast(? as vector)) fetch first ? rows only same rows: true same nearest row: true == 3. Then cb.literal(float[]) in the SAME SessionFactory cb.literal(float[]) -> FunctionArgumentException: Parameter 1 of function 'cosine_distance()' requires a vector type, but argument is of type 'float[]' == 3b. And cb.parameter(float[].class) again, which worked in step 1 cb.parameter(float[].class) -> FunctionArgumentException: Parameter 1 of function 'cosine_distance()' requires a vector type, but argument is of type 'float[]' (the rejected literal changed the answer for later parameters in this SessionFactory) == 4. A fresh SessionFactory where cb.literal(float[]) is the first thing tried (what most people write first) cb.literal(float[]) -> FunctionArgumentException: Parameter 1 of function 'cosine_distance()' requires a vector type, but argument is of type 'float[]' cb.parameter(float[].class) -> FunctionArgumentException: Parameter 1 of function 'cosine_distance()' requires a vector type, but argument is of type 'float[]' == 5. The workaround that still works there: SqmCriteriaNodeBuilder.value(value, typeSource) -- generated SQL select (d1_0.embedding<=>cast(? as vector)) from doc d1_0 order by 1 fetch first ? rows only nearest distance: 0.0010