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

Fix #1088: handle null valued service params #1090

Merged
merged 1 commit into from
May 14, 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 @@ -23,7 +23,7 @@ public class EmbeddingProviderFactory {
@GrpcClient("embedding")
EmbeddingService embeddingService;

private interface ProviderConstructor {
interface ProviderConstructor {
EmbeddingProvider create(
EmbeddingProviderConfigStore.RequestProperties requestProperties,
String baseUrl,
Expand Down Expand Up @@ -55,6 +55,9 @@ public EmbeddingProvider getConfiguration(
Map<String, Object> vectorizeServiceParameters,
Map<String, String> authentication,
String commandName) {
if (vectorizeServiceParameters == null) {
vectorizeServiceParameters = Map.of();
}
return addService(
tenant,
authToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ public class VertexAIEmbeddingClient implements EmbeddingProvider {

private static final String PROJECT_ID = "projectId";

private Map<String, Object> vectorizeServiceParameters;

public VertexAIEmbeddingClient(
EmbeddingProviderConfigStore.RequestProperties requestProperties,
String baseUrl,
String modelName,
int dimension,
Map<String, Object> vectorizeServiceParameters) {
Map<String, Object> serviceParameters) {
this.requestProperties = requestProperties;
this.modelName = modelName;
this.vectorizeServiceParameters = vectorizeServiceParameters;
baseUrl = baseUrl.replace(PROJECT_ID, vectorizeServiceParameters.get(PROJECT_ID).toString());
String projectId =
(serviceParameters == null) ? "" : String.valueOf(serviceParameters.get(PROJECT_ID));
baseUrl = baseUrl.replace(PROJECT_ID, projectId);
embeddingProvider =
QuarkusRestClientBuilder.newBuilder()
.baseUri(URI.create(baseUrl))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public VoyageAIEmbeddingClient(
String baseUrl,
String modelName,
int dimension,
Map<String, Object> vectorizeServiceParameters) {
Map<String, Object> serviceParameters) {
this.requestProperties = requestProperties;
this.modelName = modelName;
// use configured input_type if available
requestTypeQuery = requestProperties.requestTypeQuery().orElse(null);
requestTypeIndex = requestProperties.requestTypeIndex().orElse(null);
Object v = vectorizeServiceParameters.get("autoTruncate");
Object v = (serviceParameters == null) ? null : serviceParameters.get("autoTruncate");
autoTruncate = (v instanceof Boolean) ? (Boolean) v : null;

embeddingProvider =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.stargate.sgv2.jsonapi.exception.JsonApiException;
import io.stargate.sgv2.jsonapi.service.embedding.configuration.EmbeddingProviderConfigStore;
import io.stargate.sgv2.jsonapi.service.embedding.gateway.EmbeddingGatewayClient;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -27,6 +28,29 @@ public class EmbeddingGatewayClientTest {

public static final String TESTING_COMMAND_NAME = "test_command";

// for [data-api#1088] (NPE for VoyageAI provider)
@Test
void verifyDirectConstructionWithNullServiceParameters() {
List<EmbeddingProviderFactory.ProviderConstructor> providerCtors =
Arrays.asList(
AzureOpenAIEmbeddingClient::new,
CohereEmbeddingClient::new,
HuggingFaceEmbeddingClient::new,
JinaAIEmbeddingClient::new,
MistralEmbeddingClient::new,
NvidiaEmbeddingClient::new,
OpenAIEmbeddingClient::new,
UpstageAIEmbeddingClient::new,
VertexAIEmbeddingClient::new,
VoyageAIEmbeddingClient::new);
for (EmbeddingProviderFactory.ProviderConstructor ctor : providerCtors) {
EmbeddingProviderConfigStore.RequestProperties requestProperties =
EmbeddingProviderConfigStore.RequestProperties.of(
3, 5, 5000, Optional.empty(), Optional.empty());
assertThat(ctor.create(requestProperties, "baseUrl", "modelName", 5, null)).isNotNull();
}
}

@Test
void handleValidResponse() {
EmbeddingService embeddingService = mock(EmbeddingService.class);
Expand Down