Skip to content
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

Lower limit for max-$vector dimension to highest backend supports (4,096) from earlier (16,000) #775

Merged
merged 2 commits into from
Jan 8, 2024
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 @@ -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).
*/
Expand Down Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -112,7 +115,7 @@ public void failForTooBigVector() {
}
}
"""
.formatted(99_999))
.formatted(tooHighDimension))
.when()
.post(NamespaceResource.BASE_PATH, namespaceName)
.then()
Expand All @@ -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
+ ")"));
}
}

Expand Down