-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add vectorize config to tables (#1489)
Co-authored-by: Tatu Saloranta <tatu.saloranta@datastax.com>
- Loading branch information
1 parent
9eaa25a
commit 3f70a10
Showing
13 changed files
with
1,166 additions
and
920 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/main/java/io/stargate/sgv2/jsonapi/api/model/command/impl/VectorizeConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package io.stargate.sgv2.jsonapi.api.model.command.impl; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import io.stargate.sgv2.jsonapi.exception.ErrorCodeV1; | ||
import io.stargate.sgv2.jsonapi.service.embedding.configuration.ProviderConstants; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.*; | ||
import java.util.*; | ||
import javax.annotation.Nullable; | ||
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; | ||
import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
|
||
public record VectorizeConfig( | ||
@NotNull | ||
@Schema( | ||
description = "Registered Embedding service provider", | ||
type = SchemaType.STRING, | ||
implementation = String.class) | ||
@JsonProperty("provider") | ||
String provider, | ||
@Schema( | ||
description = "Registered Embedding service model", | ||
type = SchemaType.STRING, | ||
implementation = String.class) | ||
@JsonProperty("modelName") | ||
String modelName, | ||
@Valid | ||
@Nullable | ||
@Schema( | ||
description = "Authentication config for chosen embedding service", | ||
type = SchemaType.OBJECT) | ||
@JsonProperty("authentication") | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
Map<String, String> authentication, | ||
@Nullable | ||
@Schema( | ||
description = | ||
"Optional parameters that match the messageTemplate provided for the provider", | ||
type = SchemaType.OBJECT) | ||
@JsonProperty("parameters") | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
Map<String, Object> parameters) { | ||
|
||
public VectorizeConfig( | ||
String provider, | ||
String modelName, | ||
Map<String, String> authentication, | ||
Map<String, Object> parameters) { | ||
this.provider = provider; | ||
// HuggingfaceDedicated does not need user to specify model explicitly | ||
// If user specifies modelName other than endpoint-defined-model, will error out | ||
// By default, huggingfaceDedicated provider use endpoint-defined-model as placeholder | ||
if (provider.equals(ProviderConstants.HUGGINGFACE_DEDICATED)) { | ||
if (modelName != null | ||
&& !modelName.equals(ProviderConstants.HUGGINGFACE_DEDICATED_DEFINED_MODEL)) { | ||
throw ErrorCodeV1.INVALID_CREATE_COLLECTION_OPTIONS.toApiException( | ||
"'modelName' is not needed for provider %s explicitly, only '%s' is accepted", | ||
ProviderConstants.HUGGINGFACE_DEDICATED, | ||
ProviderConstants.HUGGINGFACE_DEDICATED_DEFINED_MODEL); | ||
} | ||
this.modelName = ProviderConstants.HUGGINGFACE_DEDICATED_DEFINED_MODEL; | ||
} else { | ||
this.modelName = modelName; | ||
} | ||
if (authentication != null && !authentication.isEmpty()) { | ||
Map<String, String> updatedAuth = new HashMap<>(); | ||
for (Map.Entry<String, String> userAuth : authentication.entrySet()) { | ||
// Determine the full credential name based on the sharedKeyValue pair | ||
// If the sharedKeyValue does not contain a dot (e.g. myKey) or the part after the dot | ||
// does not match the key (e.g. myKey.test), append the key to the sharedKeyValue with | ||
// a dot (e.g. myKey.providerKey or myKey.test.providerKey). Otherwise, use the | ||
// sharedKeyValue (e.g. myKey.providerKey) as is. | ||
String sharedKeyValue = userAuth.getValue(); | ||
String credentialName = | ||
sharedKeyValue.lastIndexOf('.') <= 0 | ||
|| !sharedKeyValue | ||
.substring(sharedKeyValue.lastIndexOf('.') + 1) | ||
.equals(userAuth.getKey()) | ||
? sharedKeyValue + "." + userAuth.getKey() | ||
: sharedKeyValue; | ||
updatedAuth.put(userAuth.getKey(), credentialName); | ||
} | ||
this.authentication = updatedAuth; | ||
} else { | ||
this.authentication = authentication; | ||
} | ||
this.parameters = parameters; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.