Hibernate Search 7.2.0.CR1 is out

Posted by    |      

Hibernate Search is a library that integrates Hibernate ORM with Apache Lucene or Elasticsearch by automatically indexing entities, enabling advanced search functionality: full-text, geospatial, aggregations and more. For more information, see Hibernate Search on hibernate.org.

We just published Hibernate Search 7.2.0.CR1, a first candidate release of the next minor version of Hibernate Search.

This version brings a new prefix predicate and a few improvements for the knn predicate, compatibility with OpenSearch 2.15, upgrades to Hibernate ORM 6.6, and addresses a few bugs.

What’s new

For a summary of all new features and improvements since 7.1, head to the dedicated page on hibernate.org.

Dependency upgrades

Hibernate ORM (HSEARCH-5217)

Hibernate Search now depends on Hibernate ORM 6.6.0.CR2.

Lucene (HSEARCH-5184)

The Lucene backend now uses Lucene 9.11.1.

OpenSearch (HSEARCH-5181)

The Elasticsearch backend now is compatible with OpenSearch 2.15 as well as with other versions that were already compatible.

Others

knn predicate updates

The OpenSearch 2.14 release introduced a way to apply score/similarity filters to a knn query. This means that previous limitations imposed on the vector search filtering when using the OpenSearch distribution of the Elasticsearch backend are now removed. It is worth mentioning that because of how this filter is implemented on the OpenSearch side, applying the similarity filter will result in ignoring the k value.

The knn predicate, besides the existing .requiredMinimumSimilarity(..) filter, now also has a score-based alternative: requiredMinimumScore(..). With knn search, similarity and score are derived one from the other, and in some scenarios, it may be simpler to use score, while in others — similarity.

To remind you how the vector search works: for vector fields to be indexed, they should be annotated with a @VectorField annotation:

@Entity
@Indexed
public class Book {

    @Id
    private Integer id;

    @VectorField(dimension = 512)
    private float[] coverImageEmbeddings;

    // Other properties ...
}

Then, searching for vector similarities is performed via a knn predicate:

float[] coverImageEmbeddingsVector = /*...*/

List<Book> hits = searchSession.search( Book.class )
.where( f ->
    f.knn( 5 ) (1)
        .field( "coverImageEmbeddings" ) (2)
        .matching( coverImageEmbeddingsVector ) (3)
        .requiredMinimumSimilarity( similarity ) (4)
).fetchHits( 20 );
1 Provide the number of similar documents to look for.
2 Specify the name of the vector field.
3 Provide a reference vector; matched documents will be the ones whose indexed vector is "most similar" to this vector.
4 Specify the minimum required similarity between the reference and indexed vectors; documents where indexed vector similarity is less than the specified similarity value will be filtered out. Alternatively, the requiredMinimumScore( score ) filter can be applied instead of the requiredMinimumSimilarity( similarity ).

See this section of the reference documentation on vector fields and the one on a knn predicate for more information.

Prefix predicate

The prefix predicate matches documents for which a given field has a value starting with a given string.

List<Book> hits = searchSession.search( Book.class )
    .where( f -> f.prefix().field( "description" )
        .matching( "rob" ) )
    .fetchHits( 20 );

See this section of the reference documentation on the prefix predicate for more information.

ValueConvert gets deprecated

The Search DSL has been using ValueConvert enum to let the user specify how the values in search queries have to be converted, be it the ones passed to the predicates/aggregations/sorts or the ones returned by projections/aggregations. Moving forward, to better support new use cases and bring better clarity on the expectations, this enum is replaced with the new one: ValueModel. At the moment ValueModel provides these options:

MAPPING

This is the default model that allows working with the types as defined on the entity side.

INDEX

This model does not apply conversion and allows working with the types as defined on the index side.

STRING

This model applies formatting and parsing allowing working with the string representation of values.

RAW

This model does not apply conversion and allows working with the types that the backend operates with on a low level.

For each deprecated method accepting the ValueConvert input, there is now an alternative that accepts ValueModel instead. Replace ValueConvert.YES with ValueModel.MAPPING and ValueConvert.NO with ValueModel.INDEX in your code where the values were set explicitly.

See this section of the reference documentation on the types of arguments passed to the DSL and on the types of projected values for more information.

Other improvements and bug fixes

  • HSEARCH-5170: Fix a potential issue when setting an association to null before removing an entity may not trigger indexing

And more. For a full list of changes since the previous releases, please see the release notes.

How to get this release

All details are available and up to date on the dedicated page on hibernate.org.

Getting started, migrating

For new applications, refer to the getting started guide:

For existing applications, Hibernate Search 7.2 is a drop-in replacement for 7.1, assuming you also upgrade the dependencies. Information about deprecated configuration and API is included in the migration guide.

Feedback, issues, ideas?

To get in touch, use the following channels:


Back to top