Skip to content

HSEARCH-5305 - adjust vector search max dimensions for Lucene backend #4563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

public class HibernateSearchKnnVectorsFormat extends KnnVectorsFormat {
// OpenSearch has a limit of 16000
// Elasticsearch has a limit of 4096
// We'll keep it at 4096 for now as well:
public static final int DEFAULT_MAX_DIMENSIONS = 4096;
public static final int DEFAULT_MAX_DIMENSIONS = 16000;
private static final KnnVectorsFormat DEFAULT_KNN_VECTORS_FORMAT = new HibernateSearchKnnVectorsFormat();

public static KnnVectorsFormat defaultFormat() {
Expand Down
4 changes: 4 additions & 0 deletions documentation/src/main/asciidoc/migration/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ in Hibernate Search {hibernateSearchVersion}
are backward-compatible with Hibernate Search {hibernateSearchPreviousStableVersionShort}:
no database schema update is necessary for these tables.

[[vectorsize]]
=== Vector search max dimension
For the Lucene backend, the vector search maximum dimension has been increased from 4096 to 16000. Increasing the vector size, to leverage a different, higher dimension model, implies a larger memory requirement on behalf of the JVM.

[[configuration]]
== Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ include::../components/_incubating-warning.adoc[]
The size of the stored vectors. This is a required field. This size should match the vector size of the vectors produced by
the model used to convert the data into vector representation.
It is expected to be a positive integer value. Maximum accepted value is backend-specific.
For the <<backend-lucene, Lucene backend>> the dimension must be in `[1, 4096]` range.
For the <<backend-lucene, Lucene backend>> the dimension must be in `[1, 16000]` range.
As for the <<backend-elasticsearch, Elasticsearch backend>> the range depends on the distribution.
See the link:{elasticsearchDocUrl}/dense-vector.html#dense-vector-params[Elasticsearch]/link:{openSearchDocUrl}/search-plugins/knn/approximate-knn/#get-started-with-approximate-k-nn[OpenSearch]
specific documentation to learn about the vector types of these distributions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class LuceneVectorFieldIT {
public final SearchSetupHelper setupHelper = SearchSetupHelper.create();

@ParameterizedTest
@ValueSource(ints = { -1, -1000, 4097, 10000, Integer.MAX_VALUE, Integer.MIN_VALUE })
@ValueSource(ints = { -1, -1000, 16001, Integer.MAX_VALUE, Integer.MIN_VALUE })
void assertDimension(int dimension) {
test( dimension, 5, 10, "dimension", dimension, 4096 );
test( dimension, 5, 10, "dimension", dimension, 16000 );
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
class VectorFieldIT {

private static final String INDEX_NAME = "IndexName";
private static final int BATCHES = 20;
private static final int BATCH_SIZE = 1_000;
private static final int BATCHES = 50;
private static final int BATCH_SIZE = 200;

@RegisterExtension
public StandalonePojoMappingSetupHelper setupHelper = StandalonePojoMappingSetupHelper.withSingleBackend(
Expand All @@ -78,7 +78,7 @@ static void beforeAll() {
@RetryExtension.TestWithRetry
void vectorSizeLimits_max_allowed_dimension_with_lots_of_documents() {
// with OpenSearch 2.12 it allows up to 16000 which will lead to an OOM in this particular test:
int maxDimension = Math.min( 4096, maxDimension() );
int maxDimension = Math.min( 16000, maxDimension() );
@Indexed(index = INDEX_NAME)
class IndexedEntity {
@DocumentId
Expand Down Expand Up @@ -212,7 +212,7 @@ class IndexedEntity {

private static int maxDimension() {
if ( BackendConfiguration.isLucene() ) {
return 4096;
return 16000;
}
else {
ElasticsearchVersion actualVersion = ElasticsearchTestDialect.getActualVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

public class HibernateSearchKnnVectorsFormat extends KnnVectorsFormat {
// OpenSearch has a limit of 16000
// Elasticsearch has a limit of 4096
// We'll keep it at 4096 for now as well:
public static final int DEFAULT_MAX_DIMENSIONS = 4096;
public static final int DEFAULT_MAX_DIMENSIONS = 16000;
private static final KnnVectorsFormat DEFAULT_KNN_VECTORS_FORMAT = new HibernateSearchKnnVectorsFormat();

public static KnnVectorsFormat defaultFormat() {
Expand Down