diff --git a/src/main/java/io/stargate/sgv2/jsonapi/config/DocumentLimitsConfig.java b/src/main/java/io/stargate/sgv2/jsonapi/config/DocumentLimitsConfig.java index 0865c1211c..941e91596e 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/config/DocumentLimitsConfig.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/config/DocumentLimitsConfig.java @@ -51,6 +51,12 @@ public interface DocumentLimitsConfig { */ int DEFAULT_MAX_STRING_LENGTH_IN_BYTES = 8_000; + /** + * Defines the maximum dimension allowed for {@code $vector} field allowed: defaults to 4096 (as + * of 1.0.0-BETA-7). + */ + int DEFAULT_MAX_VECTOR_EMBEDDING_LENGTH = 4096; + /** * @return Defines the maximum document size, defaults to {@code 1 meg} (1 million characters). */ @@ -124,12 +130,9 @@ public interface DocumentLimitsConfig { int maxArrayLength(); /** - * @return Maximum length of Vector ($vector) array JSON API allows -- NOTE: backend data store - * may limit length to a lower value; but we want to prevent handling of huge arrays before - * trying to pass them to DB. Or, conversely, if data store does not limit length, to impose - * something reasonable from JSON API perspective (for service-protection reasons). + * @return Maximum length of Vector ($vector) array allowed, defaults to {@code 4096} elements. */ @Positive - @WithDefault("16000") + @WithDefault("" + DEFAULT_MAX_VECTOR_EMBEDDING_LENGTH) int maxVectorEmbeddingLength(); } diff --git a/src/test/java/io/stargate/sgv2/jsonapi/api/v1/VectorSearchIntegrationTest.java b/src/test/java/io/stargate/sgv2/jsonapi/api/v1/VectorSearchIntegrationTest.java index b34da8ae8a..a512b32009 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/api/v1/VectorSearchIntegrationTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/api/v1/VectorSearchIntegrationTest.java @@ -9,6 +9,7 @@ import io.quarkus.test.junit.QuarkusIntegrationTest; import io.restassured.http.ContentType; import io.stargate.sgv2.jsonapi.api.v1.metrics.JsonApiMetricsConfig; +import io.stargate.sgv2.jsonapi.config.DocumentLimitsConfig; import io.stargate.sgv2.jsonapi.config.constants.HttpConstants; import io.stargate.sgv2.jsonapi.exception.ErrorCode; import io.stargate.sgv2.jsonapi.testresource.DseTestResource; @@ -29,8 +30,8 @@ public class VectorSearchIntegrationTest extends AbstractNamespaceIntegrationTes private static final String bigVectorCollectionName = "big_vector_collection"; private static final String vectorSizeTestCollectionName = "vector_size_test_collection"; - // Just has to be bigger than maximum array size - private static final int BIG_VECTOR_SIZE = 1000; + // Just has to be bigger than maximum array size (1000) + private static final int BIG_VECTOR_SIZE = 1536; @Nested @Order(1) @@ -95,6 +96,8 @@ public void happyPathBigVectorCollection() { @Test public void failForTooBigVector() { + final int maxDimension = DocumentLimitsConfig.DEFAULT_MAX_VECTOR_EMBEDDING_LENGTH; + final int tooHighDimension = maxDimension + 10; given() .header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken()) .contentType(ContentType.JSON) @@ -112,7 +115,7 @@ public void failForTooBigVector() { } } """ - .formatted(99_999)) + .formatted(tooHighDimension)) .when() .post(NamespaceResource.BASE_PATH, namespaceName) .then() @@ -122,7 +125,12 @@ public void failForTooBigVector() { .body("errors[0].errorCode", is("VECTOR_SEARCH_FIELD_TOO_BIG")) .body( "errors[0].message", - startsWith("Vector embedding field '$vector' length too big: 99999 (max 16000)")); + startsWith( + "Vector embedding field '$vector' length too big: " + + tooHighDimension + + " (max " + + maxDimension + + ")")); } }