-
Notifications
You must be signed in to change notification settings - Fork 16
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
Expose source_model parameter for vector-enabled collections #1606
Conversation
src/main/java/io/stargate/sgv2/jsonapi/service/schema/collections/CollectionSchemaObject.java
Outdated
Show resolved
Hide resolved
src/main/java/io/stargate/sgv2/jsonapi/config/constants/VectorConstant.java
Outdated
Show resolved
Hide resolved
String sourceModel = vector.sourceModel(); | ||
String metric = vector.metric(); | ||
|
||
// decide sourceModel and metric value | ||
if (sourceModel != null) { | ||
if (metric == null) { | ||
// (1) sourceModel is provided but metric is not - set metric to cosine or dot_product based | ||
// on the map | ||
metric = SUPPORTED_SOURCES.get(sourceModel).getMetric(); | ||
} | ||
// (2) both sourceModel and metric are provided - do nothing | ||
} else { | ||
if (metric != null) { | ||
// (3) sourceModel is not provided but metric is - set sourceModel to 'other' | ||
sourceModel = SourceModel.OTHER.getSourceModel(); | ||
} else { | ||
// (4) both sourceModel and metric are not provided - set sourceModel to 'other' and metric | ||
// to 'cosine' | ||
sourceModel = SourceModel.OTHER.getSourceModel(); | ||
metric = SimilarityFunction.COSINE.getMetric(); | ||
} | ||
} | ||
|
||
if (service != null) { | ||
// Validate service configuration and auto populate vector dimension. | ||
vectorDimension = validateVectorize.validateService(service, vectorDimension); | ||
vector = | ||
new CreateCollectionCommand.Options.VectorSearchConfig( | ||
vectorDimension, vector.metric(), vector.vectorizeConfig()); | ||
vectorDimension, metric, sourceModel, vector.vectorizeConfig()); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to optimize the sourceModel
for service? For example, if the user only specifies openai
and text-embedding-3-small
in the service
, do we want to optimize the sourceModel
to openai-v3-small
. Currently, we will use other
as the default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/main/java/io/stargate/sgv2/jsonapi/api/configuration/CommandObjectMapperHandler.java
Outdated
Show resolved
Hide resolved
src/main/java/io/stargate/sgv2/jsonapi/api/model/command/impl/CreateCollectionCommand.java
Outdated
Show resolved
Hide resolved
src/main/java/io/stargate/sgv2/jsonapi/api/model/command/impl/CreateCollectionCommand.java
Show resolved
Hide resolved
src/main/java/io/stargate/sgv2/jsonapi/config/constants/VectorConstant.java
Outdated
Show resolved
Hide resolved
@@ -141,6 +141,8 @@ public enum ErrorCodeV1 { | |||
|
|||
VECTOR_SEARCH_INVALID_FUNCTION_NAME("Invalid vector search function name"), | |||
|
|||
VECTOR_SEARCH_INVALID_SOURCE_MODEL_NAME("Invalid vector search source model name"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure but should we use "Unrecognized" instead of "Invalid" for this (I know we use "invalid" above so maybe it's more consistent)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes...I used "invalid" because the above used it. Changed to "Unrecognized", should we change the above to "Unrecognized" as well?
if (sourceModel.isEmpty()) return OTHER; | ||
SourceModel model = SOURCE_MODELS_MAP.get(sourceModel); | ||
if (model == null) { | ||
throw ErrorCodeV1.VECTOR_SEARCH_INVALID_SOURCE_MODEL_NAME.toApiException("'%s'", sourceModel); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should then also list valid/known source model names, not just invalid/unrecognized value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. I followed the pattern in SimilarityFunction. Do we want to change it as well?
src/main/java/io/stargate/sgv2/jsonapi/service/schema/SourceModel.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, but would like some changes as per my comments. Will re-review once conflicts merged.
src/main/java/io/stargate/sgv2/jsonapi/service/schema/SourceModel.java
Outdated
Show resolved
Hide resolved
src/main/java/io/stargate/sgv2/jsonapi/service/schema/SourceModel.java
Outdated
Show resolved
Hide resolved
src/main/java/io/stargate/sgv2/jsonapi/service/schema/SourceModel.java
Outdated
Show resolved
Hide resolved
src/main/java/io/stargate/sgv2/jsonapi/config/constants/VectorConstant.java
Outdated
Show resolved
Hide resolved
src/main/java/io/stargate/sgv2/jsonapi/service/resolver/CreateCollectionCommandResolver.java
Outdated
Show resolved
Hide resolved
startsWith( | ||
"Request invalid: field 'command.options.vector.sourceModel' value \"invalidName\" not valid. Problem: sourceModel options are 'openai-v3-large', 'openai-v3-small', 'ada002', 'gecko', 'nv-qa-4', 'cohere-v3', 'bert', and 'other'.")); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One other thing to test: pass non-String value for sourceModel
(like JSON Object) and verify error handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If passing JSON Object, there will be a deserialization error from CreateCollectionCommand
. Do we want to use this error?
{
"errors": [
{
"message": "Request invalid, cannot parse as JSON: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)\n at [Source: (ByteArrayInputStream); line: 6, column: 32] (through reference chain: io.stargate.sgv2.jsonapi.api.model.command.impl.CreateCollectionCommand[\"options\"]->io.stargate.sgv2.jsonapi.api.model.command.impl.CreateCollectionCommand$Options[\"vector\"]->io.stargate.sgv2.jsonapi.api.model.command.impl.CreateCollectionCommand$Options$VectorSearchConfig[\"sourceModel\"])",
"errorCode": "INVALID_REQUEST_NOT_JSON"
}
]
}
…llection_source_model # Conflicts: # src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/TableSchemaObject.java # src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/VectorConfig.java # src/main/java/io/stargate/sgv2/jsonapi/service/schema/collections/CollectionSchemaObject.java # src/test/java/io/stargate/sgv2/jsonapi/service/embedding/operation/DataVectorizerTest.java # src/test/java/io/stargate/sgv2/jsonapi/service/embedding/operation/TestEmbeddingProvider.java
…llection_source_model
/** Key for vector function name definition in cql index. */ | ||
String VECTOR_INDEX_FUNCTION_NAME = "similarity_function"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicated with VectorConstants
. I think it's better in there, so I remove the one in here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good: two smaller suggestions, approving, you can consider whether to follow suggestions or not.
src/main/java/io/stargate/sgv2/jsonapi/service/cqldriver/executor/VectorConfig.java
Outdated
Show resolved
Hide resolved
src/main/java/io/stargate/sgv2/jsonapi/service/schema/SourceModel.java
Outdated
Show resolved
Hide resolved
…nto hazel/collection_source_model
What this PR does:
Expose source_model parameter for vector-enabled collections
Which issue(s) this PR fixes:
Fixes JiraC2-3495
Checklist