diff --git a/pom.xml b/pom.xml index 5e15d02..16e9dec 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 com.mulesoft.connectors mule4-vectors-connector - 0.2.6-SNAPSHOT + 0.2.19-SNAPSHOT mule-extension MuleSoft Vectors Connector - Mule 4 MuleSoft Vectors Connector provides access to a broad number of external Vector Stores. diff --git a/src/main/java/org/mule/extension/vectors/internal/config/Configuration.java b/src/main/java/org/mule/extension/vectors/internal/config/Configuration.java index 2fb9752..1e85162 100644 --- a/src/main/java/org/mule/extension/vectors/internal/config/Configuration.java +++ b/src/main/java/org/mule/extension/vectors/internal/config/Configuration.java @@ -1,16 +1,19 @@ package org.mule.extension.vectors.internal.config; -import org.mule.extension.vectors.internal.helper.provider.EmbeddingModelServiceProvider; -import org.mule.extension.vectors.internal.helper.provider.VectorStoreProvider; +import org.mule.extension.vectors.internal.model.BaseModelConfiguration; import org.mule.extension.vectors.internal.operation.DocumentOperations; import org.mule.extension.vectors.internal.operation.EmbeddingOperations; +import org.mule.extension.vectors.internal.storage.BaseStorageConfiguration; +import org.mule.extension.vectors.internal.store.BaseStoreConfiguration; +import org.mule.runtime.api.meta.ExpressionSupport; import org.mule.runtime.extension.api.annotation.Alias; +import org.mule.runtime.extension.api.annotation.Expression; import org.mule.runtime.extension.api.annotation.Operations; +import org.mule.runtime.extension.api.annotation.param.Optional; import org.mule.runtime.extension.api.annotation.param.Parameter; import org.mule.runtime.extension.api.annotation.param.display.DisplayName; import org.mule.runtime.extension.api.annotation.param.display.Placement; import org.mule.runtime.extension.api.annotation.param.display.Summary; -import org.mule.runtime.extension.api.annotation.values.OfValues; /** * This class represents an extension configuration, values set in this class are commonly used across multiple @@ -25,34 +28,35 @@ public class Configuration { @DisplayName("Embedding Model Service") @Summary("The embedding model service.") @Placement(order = 1, tab = Placement.DEFAULT_TAB) - @OfValues(EmbeddingModelServiceProvider.class) - private String embeddingModelService; + private BaseModelConfiguration modelConfiguration; @Parameter @Alias("vectorStore") @DisplayName("Vector Store") @Summary("The vector store.") @Placement(order = 2, tab = Placement.DEFAULT_TAB) - @OfValues(VectorStoreProvider.class) - private String vectorStore; + @Expression(ExpressionSupport.NOT_SUPPORTED) + private BaseStoreConfiguration storeConfiguration; @Parameter - @Alias("configFilePath") - @DisplayName("Configuration File Path") - @Summary("The configuration file path.") + @Alias("storageProvider") + @DisplayName("Storage provider") + @Summary("The storage provider.") + @Optional @Placement(order = 3, tab = Placement.DEFAULT_TAB) - private String configFilePath; + private BaseStorageConfiguration storageConfiguration; - public String getEmbeddingModelService() { - return embeddingModelService; + public BaseModelConfiguration getModelConfiguration() { + return modelConfiguration; } - public String getVectorStore() { - return vectorStore; + public BaseStoreConfiguration getStoreConfiguration() { + return storeConfiguration; } - public String getConfigFilePath() { - return configFilePath; + public BaseStorageConfiguration getStorageConfiguration() { + return storageConfiguration; } + } diff --git a/src/main/java/org/mule/extension/vectors/internal/constant/Constants.java b/src/main/java/org/mule/extension/vectors/internal/constant/Constants.java index b3850a7..19b3a83 100644 --- a/src/main/java/org/mule/extension/vectors/internal/constant/Constants.java +++ b/src/main/java/org/mule/extension/vectors/internal/constant/Constants.java @@ -13,8 +13,10 @@ private Constants() {} public static final String FILE_TYPE_URL = "url"; public static final String STORAGE_TYPE_LOCAL = "Local"; - public static final String STORAGE_TYPE_S3 = "S3"; - public static final String STORAGE_TYPE_AZURE_BLOB = "AZURE_BLOB"; + public static final String STORAGE_TYPE_CLOUD = "Cloud"; + + public static final String STORAGE_PROVIDER_AWS_S3 = "S3"; + public static final String STORAGE_PROVIDER_AZURE_BLOB = "AZURE_BLOB"; public static final String EMBEDDING_MODEL_SERVICE_OPENAI = "OPENAI"; public static final String EMBEDDING_MODEL_SERVICE_AZURE_OPENAI = "AZURE_OPENAI"; diff --git a/src/main/java/org/mule/extension/vectors/internal/error/MuleVectorsErrorType.java b/src/main/java/org/mule/extension/vectors/internal/error/MuleVectorsErrorType.java index aac126d..d134ab1 100644 --- a/src/main/java/org/mule/extension/vectors/internal/error/MuleVectorsErrorType.java +++ b/src/main/java/org/mule/extension/vectors/internal/error/MuleVectorsErrorType.java @@ -7,5 +7,5 @@ */ public enum MuleVectorsErrorType implements ErrorTypeDefinition { - DOCUMENT_OPERATIONS_FAILURE, EMBEDDING_OPERATIONS_FAILURE, AI_SERVICES_FAILURE, STORE_SERVICES_FAILURE + DOCUMENT_OPERATIONS_FAILURE, EMBEDDING_OPERATIONS_FAILURE, AI_SERVICES_FAILURE, STORE_SERVICES_FAILURE, STORAGE_SERVICES_FAILURE } diff --git a/src/main/java/org/mule/extension/vectors/internal/error/provider/DocumentErrorTypeProvider.java b/src/main/java/org/mule/extension/vectors/internal/error/provider/DocumentErrorTypeProvider.java index 01684e7..4631979 100644 --- a/src/main/java/org/mule/extension/vectors/internal/error/provider/DocumentErrorTypeProvider.java +++ b/src/main/java/org/mule/extension/vectors/internal/error/provider/DocumentErrorTypeProvider.java @@ -12,12 +12,13 @@ import static java.util.Arrays.asList; import static java.util.Collections.unmodifiableSet; import static org.mule.extension.vectors.internal.error.MuleVectorsErrorType.DOCUMENT_OPERATIONS_FAILURE; +import static org.mule.extension.vectors.internal.error.MuleVectorsErrorType.STORAGE_SERVICES_FAILURE; public class DocumentErrorTypeProvider implements ErrorTypeProvider { @SuppressWarnings("rawtypes") @Override public Set getErrorTypes() { - return unmodifiableSet(new HashSet<>(asList(DOCUMENT_OPERATIONS_FAILURE))); + return unmodifiableSet(new HashSet<>(asList(DOCUMENT_OPERATIONS_FAILURE, STORAGE_SERVICES_FAILURE))); } } diff --git a/src/main/java/org/mule/extension/vectors/internal/error/provider/EmbeddingErrorTypeProvider.java b/src/main/java/org/mule/extension/vectors/internal/error/provider/EmbeddingErrorTypeProvider.java index f0d33a3..1bb360f 100644 --- a/src/main/java/org/mule/extension/vectors/internal/error/provider/EmbeddingErrorTypeProvider.java +++ b/src/main/java/org/mule/extension/vectors/internal/error/provider/EmbeddingErrorTypeProvider.java @@ -11,8 +11,7 @@ import static java.util.Arrays.asList; import static java.util.Collections.unmodifiableSet; -import static org.mule.extension.vectors.internal.error.MuleVectorsErrorType.AI_SERVICES_FAILURE; -import static org.mule.extension.vectors.internal.error.MuleVectorsErrorType.EMBEDDING_OPERATIONS_FAILURE; +import static org.mule.extension.vectors.internal.error.MuleVectorsErrorType.*; public class EmbeddingErrorTypeProvider implements ErrorTypeProvider { @@ -21,6 +20,8 @@ public class EmbeddingErrorTypeProvider implements ErrorTypeProvider { public Set getErrorTypes() { return unmodifiableSet(new HashSet<>(asList( EMBEDDING_OPERATIONS_FAILURE, - AI_SERVICES_FAILURE))); + AI_SERVICES_FAILURE, + STORE_SERVICES_FAILURE, + STORAGE_SERVICES_FAILURE))); } } diff --git a/src/main/java/org/mule/extension/vectors/internal/extension/Connector.java b/src/main/java/org/mule/extension/vectors/internal/extension/Connector.java index 0b23bfb..cd3c222 100644 --- a/src/main/java/org/mule/extension/vectors/internal/extension/Connector.java +++ b/src/main/java/org/mule/extension/vectors/internal/extension/Connector.java @@ -2,9 +2,29 @@ import org.mule.extension.vectors.internal.config.Configuration; import org.mule.extension.vectors.internal.error.MuleVectorsErrorType; +import org.mule.extension.vectors.internal.model.BaseModelConfiguration; +import org.mule.extension.vectors.internal.model.azureopenai.AzureOpenAIModelConfiguration; +import org.mule.extension.vectors.internal.model.einstein.EinsteinModelConfiguration; +import org.mule.extension.vectors.internal.model.huggingface.HuggingFaceModelConfiguration; +import org.mule.extension.vectors.internal.model.mistralai.MistralAIModelConfiguration; +import org.mule.extension.vectors.internal.model.nomic.NomicModelConfiguration; +import org.mule.extension.vectors.internal.model.openai.OpenAIModelConfiguration; +import org.mule.extension.vectors.internal.storage.BaseStorageConfiguration; +import org.mule.extension.vectors.internal.storage.azureblob.AzureBlobStorageConfiguration; +import org.mule.extension.vectors.internal.storage.s3.AWSS3StorageConfiguration; +import org.mule.extension.vectors.internal.store.BaseStoreConfiguration; +import org.mule.extension.vectors.internal.store.aisearch.AISearchStoreConfiguration; +import org.mule.extension.vectors.internal.store.chroma.ChromaStoreConfiguration; +import org.mule.extension.vectors.internal.store.elasticsearch.ElasticsearchStoreConfiguration; +import org.mule.extension.vectors.internal.store.milvus.MilvusStoreConfiguration; +import org.mule.extension.vectors.internal.store.opensearch.OpenSearchStoreConfiguration; +import org.mule.extension.vectors.internal.store.pgvector.PGVectorStoreConfiguration; +import org.mule.extension.vectors.internal.store.pinecone.PineconeStoreConfiguration; +import org.mule.extension.vectors.internal.store.qdrant.QdrantStoreConfiguration; import org.mule.runtime.api.meta.Category; import org.mule.runtime.extension.api.annotation.Extension; import org.mule.runtime.extension.api.annotation.Configurations; +import org.mule.runtime.extension.api.annotation.SubTypeMapping; import org.mule.runtime.extension.api.annotation.dsl.xml.Xml; import org.mule.runtime.extension.api.annotation.error.ErrorTypes; import org.mule.runtime.extension.api.annotation.license.RequiresEnterpriseLicense; @@ -20,6 +40,28 @@ @Xml(prefix = "ms-vectors") @Extension(name = "MuleSoft Vectors Connector", category = Category.SELECT) @Configurations(Configuration.class) +@SubTypeMapping(baseType = BaseStoreConfiguration.class, + subTypes = { + AISearchStoreConfiguration.class, + ChromaStoreConfiguration.class, + ElasticsearchStoreConfiguration.class, + MilvusStoreConfiguration.class, + OpenSearchStoreConfiguration.class, + PGVectorStoreConfiguration.class, + PineconeStoreConfiguration.class, + QdrantStoreConfiguration.class}) +@SubTypeMapping(baseType = BaseModelConfiguration.class, + subTypes = { + AzureOpenAIModelConfiguration.class, + EinsteinModelConfiguration.class, + HuggingFaceModelConfiguration.class, + MistralAIModelConfiguration.class, + NomicModelConfiguration.class, + OpenAIModelConfiguration.class}) +@SubTypeMapping(baseType = BaseStorageConfiguration.class, + subTypes = { + AWSS3StorageConfiguration.class, + AzureBlobStorageConfiguration.class}) @RequiresEnterpriseLicense(allowEvaluationLicense = true) @ErrorTypes(MuleVectorsErrorType.class) @JavaVersionSupport({JAVA_8, JAVA_11, JAVA_17}) diff --git a/src/main/java/org/mule/extension/vectors/internal/helper/provider/EmbeddingModelNameProvider.java b/src/main/java/org/mule/extension/vectors/internal/helper/provider/EmbeddingModelNameProvider.java index a4b9e61..38fefe0 100644 --- a/src/main/java/org/mule/extension/vectors/internal/helper/provider/EmbeddingModelNameProvider.java +++ b/src/main/java/org/mule/extension/vectors/internal/helper/provider/EmbeddingModelNameProvider.java @@ -50,7 +50,7 @@ public class EmbeddingModelNameProvider implements ValueProvider { @Override public Set resolve() throws ValueResolvingException { - String embeddingModelService = configuration.getEmbeddingModelService(); + String embeddingModelService = configuration.getModelConfiguration().getEmbeddingModelService(); switch (embeddingModelService) { case Constants.EMBEDDING_MODEL_SERVICE_OPENAI: return VALUES_FOR_OPENAI; diff --git a/src/main/java/org/mule/extension/vectors/internal/helper/provider/EmbeddingModelServiceProvider.java b/src/main/java/org/mule/extension/vectors/internal/helper/provider/EmbeddingModelServiceProvider.java deleted file mode 100644 index 19adeca..0000000 --- a/src/main/java/org/mule/extension/vectors/internal/helper/provider/EmbeddingModelServiceProvider.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.mule.extension.vectors.internal.helper.provider; - -import java.util.Set; - -import org.mule.extension.vectors.internal.constant.Constants; -import org.mule.runtime.api.value.Value; -import org.mule.runtime.extension.api.values.ValueBuilder; -import org.mule.runtime.extension.api.values.ValueProvider; -import org.mule.runtime.extension.api.values.ValueResolvingException; - -public class EmbeddingModelServiceProvider implements ValueProvider { - - @Override - public Set resolve() throws ValueResolvingException { - - return ValueBuilder.getValuesFor( - Constants.EMBEDDING_MODEL_SERVICE_OPENAI, - Constants.EMBEDDING_MODEL_SERVICE_MISTRAL_AI, - Constants.EMBEDDING_MODEL_SERVICE_NOMIC, - Constants.EMBEDDING_MODEL_SERVICE_HUGGING_FACE, - Constants.EMBEDDING_MODEL_SERVICE_AZURE_OPENAI, - Constants.EMBEDDING_MODEL_SERVICE_EINSTEIN); -} - -} diff --git a/src/main/java/org/mule/extension/vectors/internal/helper/provider/StorageTypeProvider.java b/src/main/java/org/mule/extension/vectors/internal/helper/provider/StorageTypeProvider.java index 7c49d24..2c5b26b 100644 --- a/src/main/java/org/mule/extension/vectors/internal/helper/provider/StorageTypeProvider.java +++ b/src/main/java/org/mule/extension/vectors/internal/helper/provider/StorageTypeProvider.java @@ -16,8 +16,7 @@ public Set resolve() throws ValueResolvingException { return ValueBuilder.getValuesFor( Constants.STORAGE_TYPE_LOCAL, - Constants.STORAGE_TYPE_S3, - Constants.STORAGE_TYPE_AZURE_BLOB); + Constants.STORAGE_TYPE_CLOUD); } } diff --git a/src/main/java/org/mule/extension/vectors/internal/helper/provider/VectorStoreProvider.java b/src/main/java/org/mule/extension/vectors/internal/helper/provider/VectorStoreProvider.java deleted file mode 100644 index 381cfe8..0000000 --- a/src/main/java/org/mule/extension/vectors/internal/helper/provider/VectorStoreProvider.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.mule.extension.vectors.internal.helper.provider; - -import org.mule.extension.vectors.internal.constant.Constants; -import org.mule.runtime.api.value.Value; -import org.mule.runtime.extension.api.values.ValueBuilder; -import org.mule.runtime.extension.api.values.ValueProvider; -import org.mule.runtime.extension.api.values.ValueResolvingException; - -import java.util.Set; - -public class VectorStoreProvider implements ValueProvider { - - @Override - public Set resolve() throws ValueResolvingException { - - return ValueBuilder.getValuesFor( - Constants.VECTOR_STORE_PGVECTOR, - Constants.VECTOR_STORE_ELASTICSEARCH, - Constants.VECTOR_STORE_OPENSEARCH, - Constants.VECTOR_STORE_MILVUS, - Constants.VECTOR_STORE_CHROMA, - Constants.VECTOR_STORE_PINECONE, - Constants.VECTOR_STORE_AI_SEARCH, - Constants.VECTOR_STORE_OPENSEARCH, - Constants.VECTOR_STORE_QDRANT - ); // MuleChainVectorsConstants.VECTOR_STORE_NEO4J - } - -} diff --git a/src/main/java/org/mule/extension/vectors/internal/model/BaseModel.java b/src/main/java/org/mule/extension/vectors/internal/model/BaseModel.java index 171890d..d039826 100644 --- a/src/main/java/org/mule/extension/vectors/internal/model/BaseModel.java +++ b/src/main/java/org/mule/extension/vectors/internal/model/BaseModel.java @@ -61,8 +61,8 @@ public BaseModel build() { BaseModel baseModel; - LOGGER.debug("Embedding Model Service: " + configuration.getEmbeddingModelService()); - switch (configuration.getEmbeddingModelService()) { + LOGGER.debug("Embedding Model Service: " + configuration.getModelConfiguration().getEmbeddingModelService()); + switch (configuration.getModelConfiguration().getEmbeddingModelService()) { case Constants.EMBEDDING_MODEL_SERVICE_AZURE_OPENAI: baseModel = new AzureOpenAIModel(configuration, embeddingModelParameters); @@ -90,7 +90,7 @@ public BaseModel build() { default: throw new ModuleException( - String.format("Error while initializing embedding model service. \"%s\" is not supported.", configuration.getEmbeddingModelService()), + String.format("Error while initializing embedding model service. \"%s\" is not supported.", configuration.getModelConfiguration().getEmbeddingModelService()), MuleVectorsErrorType.AI_SERVICES_FAILURE); } return baseModel; diff --git a/src/main/java/org/mule/extension/vectors/internal/model/BaseModelConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/model/BaseModelConfiguration.java new file mode 100644 index 0000000..db5ad7c --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/model/BaseModelConfiguration.java @@ -0,0 +1,6 @@ +package org.mule.extension.vectors.internal.model; + +public interface BaseModelConfiguration { + + String getEmbeddingModelService(); +} diff --git a/src/main/java/org/mule/extension/vectors/internal/model/azureopenai/AzureOpenAIModel.java b/src/main/java/org/mule/extension/vectors/internal/model/azureopenai/AzureOpenAIModel.java index 069d97f..e6e34ef 100644 --- a/src/main/java/org/mule/extension/vectors/internal/model/azureopenai/AzureOpenAIModel.java +++ b/src/main/java/org/mule/extension/vectors/internal/model/azureopenai/AzureOpenAIModel.java @@ -12,17 +12,16 @@ public class AzureOpenAIModel extends BaseModel { - private final String apiKey; private final String endpoint; + private final String apiKey; public AzureOpenAIModel(Configuration configuration, EmbeddingModelParameters embeddingModelParameters) { super(configuration,embeddingModelParameters); - JSONObject config = readConfigFile(configuration.getConfigFilePath()); - assert config != null; - JSONObject modelConfig = config.getJSONObject(Constants.EMBEDDING_MODEL_SERVICE_AZURE_OPENAI); - this.apiKey = modelConfig.getString("AZURE_OPENAI_KEY"); - this.endpoint = modelConfig.getString("AZURE_OPENAI_ENDPOINT"); + + AzureOpenAIModelConfiguration azureOpenAIModelConfiguration = (AzureOpenAIModelConfiguration) configuration.getModelConfiguration(); + this.endpoint = azureOpenAIModelConfiguration.getEndpoint(); + this.apiKey = azureOpenAIModelConfiguration.getApiKey(); } public EmbeddingModel buildEmbeddingModel() { diff --git a/src/main/java/org/mule/extension/vectors/internal/model/azureopenai/AzureOpenAIModelConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/model/azureopenai/AzureOpenAIModelConfiguration.java new file mode 100644 index 0000000..058fe22 --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/model/azureopenai/AzureOpenAIModelConfiguration.java @@ -0,0 +1,41 @@ +package org.mule.extension.vectors.internal.model.azureopenai; + +import org.mule.extension.vectors.internal.constant.Constants; +import org.mule.extension.vectors.internal.model.BaseModelConfiguration; +import org.mule.extension.vectors.internal.store.BaseStoreConfiguration; +import org.mule.runtime.api.meta.ExpressionSupport; +import org.mule.runtime.extension.api.annotation.Alias; +import org.mule.runtime.extension.api.annotation.Expression; +import org.mule.runtime.extension.api.annotation.param.Parameter; +import org.mule.runtime.extension.api.annotation.param.display.DisplayName; +import org.mule.runtime.extension.api.annotation.param.display.Password; +import org.mule.runtime.extension.api.annotation.param.display.Placement; + +@Alias("azureOpenAI") +@DisplayName("Azure OpenAI") +public class AzureOpenAIModelConfiguration implements BaseModelConfiguration { + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 1) + private String endpoint; + + @Parameter + @Password + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 2) + private String apiKey; + + @Override + public String getEmbeddingModelService() { + return Constants.EMBEDDING_MODEL_SERVICE_AZURE_OPENAI; + } + + public String getEndpoint() { + return endpoint; + } + + public String getApiKey() { + return apiKey; + } +} diff --git a/src/main/java/org/mule/extension/vectors/internal/model/einstein/EinsteinEmbeddingModel.java b/src/main/java/org/mule/extension/vectors/internal/model/einstein/EinsteinEmbeddingModel.java index e90fe5f..c7968eb 100644 --- a/src/main/java/org/mule/extension/vectors/internal/model/einstein/EinsteinEmbeddingModel.java +++ b/src/main/java/org/mule/extension/vectors/internal/model/einstein/EinsteinEmbeddingModel.java @@ -41,17 +41,17 @@ public class EinsteinEmbeddingModel extends DimensionAwareEmbeddingModel { * Private constructor used by the builder pattern. * Initializes the embedding model with Salesforce credentials and model configuration. * - * @param salesforceOrg The Salesforce organization identifier + * @param salesforceOrgUrl The Salesforce organization identifier * @param clientId OAuth client ID for authentication * @param clientSecret OAuth client secret for authentication * @param modelName Name of the Einstein embedding model to use * @param dimensions Number of dimensions for the embeddings */ - private EinsteinEmbeddingModel(String salesforceOrg, String clientId, String clientSecret, String modelName, Integer dimensions) { + private EinsteinEmbeddingModel(String salesforceOrgUrl, String clientId, String clientSecret, String modelName, Integer dimensions) { // Default to SFDC text embedding model if none specified this.modelName = Utils.getOrDefault(modelName, Constants.EMBEDDING_MODEL_NAME_SFDC_TEXT_EMBEDDING_ADA_002); this.dimensions = dimensions; - this.accessToken = getAccessToken(salesforceOrg, clientId, clientSecret); + this.accessToken = getAccessToken(salesforceOrgUrl, clientId, clientSecret); } /** @@ -299,7 +299,7 @@ public static EinsteinEmbeddingModel.EinsteinEmbeddingModelBuilder builder() { * Implements the Builder pattern for constructing EinsteinEmbeddingModel instances. */ public static class EinsteinEmbeddingModelBuilder { - private String salesforceOrg; + private String salesforceOrgUrl; private String clientId; private String clientSecret; private String modelName; @@ -310,8 +310,8 @@ public static class EinsteinEmbeddingModelBuilder { public EinsteinEmbeddingModelBuilder() { } - public EinsteinEmbeddingModel.EinsteinEmbeddingModelBuilder salesforceOrg(String salesforceOrg) { - this.salesforceOrg = salesforceOrg; + public EinsteinEmbeddingModel.EinsteinEmbeddingModelBuilder salesforceOrgUrl(String salesforceOrg) { + this.salesforceOrgUrl = salesforceOrg; return this; } @@ -346,7 +346,7 @@ public EinsteinEmbeddingModel.EinsteinEmbeddingModelBuilder dimensions(Integer d * @return A new EinsteinEmbeddingModel configured with the builder's parameters */ public EinsteinEmbeddingModel build() { - return new EinsteinEmbeddingModel(this.salesforceOrg, this.clientId, this.clientSecret, this.modelName, this.dimensions); + return new EinsteinEmbeddingModel(this.salesforceOrgUrl, this.clientId, this.clientSecret, this.modelName, this.dimensions); } } } diff --git a/src/main/java/org/mule/extension/vectors/internal/model/einstein/EinsteinModel.java b/src/main/java/org/mule/extension/vectors/internal/model/einstein/EinsteinModel.java index 73c371c..adf34c1 100644 --- a/src/main/java/org/mule/extension/vectors/internal/model/einstein/EinsteinModel.java +++ b/src/main/java/org/mule/extension/vectors/internal/model/einstein/EinsteinModel.java @@ -1,21 +1,17 @@ package org.mule.extension.vectors.internal.model.einstein; import dev.langchain4j.model.embedding.EmbeddingModel; -import org.json.JSONObject; import org.mule.extension.vectors.internal.config.Configuration; -import org.mule.extension.vectors.internal.constant.Constants; import org.mule.extension.vectors.internal.helper.parameter.EmbeddingModelParameters; import org.mule.extension.vectors.internal.model.BaseModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.mule.extension.vectors.internal.util.JsonUtils.readConfigFile; - public class EinsteinModel extends BaseModel { private static final Logger LOGGER = LoggerFactory.getLogger(EinsteinModel.class); - private final String salesforceOrg; + private final String salesforceOrgUrl; private final String clientId; private final String clientSecret; private final String modelName; @@ -23,19 +19,18 @@ public class EinsteinModel extends BaseModel { public EinsteinModel(Configuration configuration, EmbeddingModelParameters embeddingModelParameters) { super(configuration,embeddingModelParameters); - JSONObject config = readConfigFile(configuration.getConfigFilePath()); - assert config != null; - JSONObject modelConfig = config.getJSONObject(Constants.EMBEDDING_MODEL_SERVICE_EINSTEIN); - this.salesforceOrg = modelConfig.getString("EINSTEIN_SFDC_ORG_URL");; - this.clientId = modelConfig.getString("EINSTEIN_CLIENT_ID");; - this.clientSecret = modelConfig.getString("EINSTEIN_CLIENT_SECRET");; + + EinsteinModelConfiguration einsteinModelConfiguration = (EinsteinModelConfiguration) configuration.getModelConfiguration(); + this.salesforceOrgUrl = einsteinModelConfiguration.getSalesforceOrgUrl(); + this.clientId = einsteinModelConfiguration.getClientId(); + this.clientSecret = einsteinModelConfiguration.getClientSecret(); this.modelName = embeddingModelParameters.getEmbeddingModelName(); } public EmbeddingModel buildEmbeddingModel() { return EinsteinEmbeddingModel.builder() - .salesforceOrg(salesforceOrg) + .salesforceOrgUrl(salesforceOrgUrl) .clientId(clientId) .clientSecret(clientSecret) .modelName(modelName) diff --git a/src/main/java/org/mule/extension/vectors/internal/model/einstein/EinsteinModelConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/model/einstein/EinsteinModelConfiguration.java new file mode 100644 index 0000000..43f8b2f --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/model/einstein/EinsteinModelConfiguration.java @@ -0,0 +1,54 @@ +package org.mule.extension.vectors.internal.model.einstein; + +import org.mule.extension.vectors.internal.constant.Constants; +import org.mule.extension.vectors.internal.model.BaseModelConfiguration; +import org.mule.extension.vectors.internal.store.BaseStoreConfiguration; +import org.mule.runtime.api.meta.ExpressionSupport; +import org.mule.runtime.extension.api.annotation.Alias; +import org.mule.runtime.extension.api.annotation.Expression; +import org.mule.runtime.extension.api.annotation.param.Parameter; +import org.mule.runtime.extension.api.annotation.param.display.DisplayName; +import org.mule.runtime.extension.api.annotation.param.display.Password; +import org.mule.runtime.extension.api.annotation.param.display.Placement; +import org.mule.runtime.extension.api.annotation.param.display.Summary; + +@Alias("einstein") +@DisplayName("Einstein") +public class EinsteinModelConfiguration implements BaseModelConfiguration { + + @Parameter + @Alias("salesforceOrgUrl") + @DisplayName("Salesforce Org URL") + @Summary("The salesforce org base URL.") + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 1) + private String salesforceOrgUrl; + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 2) + private String clientId; + + @Parameter + @Password + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 3) + private String clientSecret; + + @Override + public String getEmbeddingModelService() { + return Constants.EMBEDDING_MODEL_SERVICE_EINSTEIN; + } + + public String getSalesforceOrgUrl() { + return salesforceOrgUrl; + } + + public String getClientId() { + return clientId; + } + + public String getClientSecret() { + return clientSecret; + } +} diff --git a/src/main/java/org/mule/extension/vectors/internal/model/huggingface/HuggingFaceModel.java b/src/main/java/org/mule/extension/vectors/internal/model/huggingface/HuggingFaceModel.java index fccb774..22bc031 100644 --- a/src/main/java/org/mule/extension/vectors/internal/model/huggingface/HuggingFaceModel.java +++ b/src/main/java/org/mule/extension/vectors/internal/model/huggingface/HuggingFaceModel.java @@ -16,10 +16,9 @@ public class HuggingFaceModel extends BaseModel { public HuggingFaceModel(Configuration configuration, EmbeddingModelParameters embeddingModelParameters) { super(configuration,embeddingModelParameters); - JSONObject config = readConfigFile(configuration.getConfigFilePath()); - assert config != null; - JSONObject modelConfig = config.getJSONObject("HUGGING_FACE"); - this.apiKey = modelConfig.getString("HUGGING_FACE_API_KEY"); + + HuggingFaceModelConfiguration huggingFaceModelConfiguration =(HuggingFaceModelConfiguration) configuration.getModelConfiguration(); + this.apiKey = huggingFaceModelConfiguration.getApiKey(); } public EmbeddingModel buildEmbeddingModel() { diff --git a/src/main/java/org/mule/extension/vectors/internal/model/huggingface/HuggingFaceModelConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/model/huggingface/HuggingFaceModelConfiguration.java new file mode 100644 index 0000000..dbc5a94 --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/model/huggingface/HuggingFaceModelConfiguration.java @@ -0,0 +1,31 @@ +package org.mule.extension.vectors.internal.model.huggingface; + +import org.mule.extension.vectors.internal.constant.Constants; +import org.mule.extension.vectors.internal.model.BaseModelConfiguration; +import org.mule.runtime.api.meta.ExpressionSupport; +import org.mule.runtime.extension.api.annotation.Alias; +import org.mule.runtime.extension.api.annotation.Expression; +import org.mule.runtime.extension.api.annotation.param.Parameter; +import org.mule.runtime.extension.api.annotation.param.display.DisplayName; +import org.mule.runtime.extension.api.annotation.param.display.Password; +import org.mule.runtime.extension.api.annotation.param.display.Placement; + +@Alias("huggingFace") +@DisplayName("Hugging Face") +public class HuggingFaceModelConfiguration implements BaseModelConfiguration { + + @Parameter + @Password + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 1) + private String apiKey; + + @Override + public String getEmbeddingModelService() { + return Constants.EMBEDDING_MODEL_SERVICE_HUGGING_FACE; + } + + public String getApiKey() { + return apiKey; + } +} diff --git a/src/main/java/org/mule/extension/vectors/internal/model/mistralai/MistralAIModel.java b/src/main/java/org/mule/extension/vectors/internal/model/mistralai/MistralAIModel.java index d76b3f6..c7307f5 100644 --- a/src/main/java/org/mule/extension/vectors/internal/model/mistralai/MistralAIModel.java +++ b/src/main/java/org/mule/extension/vectors/internal/model/mistralai/MistralAIModel.java @@ -16,10 +16,9 @@ public class MistralAIModel extends BaseModel { public MistralAIModel(Configuration configuration, EmbeddingModelParameters embeddingModelParameters) { super(configuration,embeddingModelParameters); - JSONObject config = readConfigFile(configuration.getConfigFilePath()); - assert config != null; - JSONObject modelConfig = config.getJSONObject("MISTRAL_AI"); - this.apiKey = modelConfig.getString("MISTRAL_AI_API_KEY"); + + MistralAIModelConfiguration mistralAIModelConfiguration = (MistralAIModelConfiguration) configuration.getModelConfiguration(); + this.apiKey = mistralAIModelConfiguration.getApiKey(); } public EmbeddingModel buildEmbeddingModel() { diff --git a/src/main/java/org/mule/extension/vectors/internal/model/mistralai/MistralAIModelConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/model/mistralai/MistralAIModelConfiguration.java new file mode 100644 index 0000000..db9552e --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/model/mistralai/MistralAIModelConfiguration.java @@ -0,0 +1,31 @@ +package org.mule.extension.vectors.internal.model.mistralai; + +import org.mule.extension.vectors.internal.constant.Constants; +import org.mule.extension.vectors.internal.model.BaseModelConfiguration; +import org.mule.runtime.api.meta.ExpressionSupport; +import org.mule.runtime.extension.api.annotation.Alias; +import org.mule.runtime.extension.api.annotation.Expression; +import org.mule.runtime.extension.api.annotation.param.Parameter; +import org.mule.runtime.extension.api.annotation.param.display.DisplayName; +import org.mule.runtime.extension.api.annotation.param.display.Password; +import org.mule.runtime.extension.api.annotation.param.display.Placement; + +@Alias("mistralAI") +@DisplayName("Mistral AI") +public class MistralAIModelConfiguration implements BaseModelConfiguration { + + @Parameter + @Password + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 1) + private String apiKey; + + @Override + public String getEmbeddingModelService() { + return Constants.EMBEDDING_MODEL_SERVICE_MISTRAL_AI; + } + + public String getApiKey() { + return apiKey; + } +} diff --git a/src/main/java/org/mule/extension/vectors/internal/model/nomic/NomicModel.java b/src/main/java/org/mule/extension/vectors/internal/model/nomic/NomicModel.java index 1ef5443..0873868 100644 --- a/src/main/java/org/mule/extension/vectors/internal/model/nomic/NomicModel.java +++ b/src/main/java/org/mule/extension/vectors/internal/model/nomic/NomicModel.java @@ -16,10 +16,9 @@ public class NomicModel extends BaseModel { public NomicModel(Configuration configuration, EmbeddingModelParameters embeddingModelParameters) { super(configuration,embeddingModelParameters); - JSONObject config = readConfigFile(configuration.getConfigFilePath()); - assert config != null; - JSONObject modelConfig = config.getJSONObject("NOMIC"); - this.apiKey = modelConfig.getString("NOMIC_API_KEY"); + + NomicModelConfiguration nomicModelConfiguration =(NomicModelConfiguration) configuration.getModelConfiguration(); + this.apiKey = nomicModelConfiguration.getApiKey(); } public EmbeddingModel buildEmbeddingModel() { diff --git a/src/main/java/org/mule/extension/vectors/internal/model/nomic/NomicModelConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/model/nomic/NomicModelConfiguration.java new file mode 100644 index 0000000..b006d3c --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/model/nomic/NomicModelConfiguration.java @@ -0,0 +1,31 @@ +package org.mule.extension.vectors.internal.model.nomic; + +import org.mule.extension.vectors.internal.constant.Constants; +import org.mule.extension.vectors.internal.model.BaseModelConfiguration; +import org.mule.runtime.api.meta.ExpressionSupport; +import org.mule.runtime.extension.api.annotation.Alias; +import org.mule.runtime.extension.api.annotation.Expression; +import org.mule.runtime.extension.api.annotation.param.Parameter; +import org.mule.runtime.extension.api.annotation.param.display.DisplayName; +import org.mule.runtime.extension.api.annotation.param.display.Password; +import org.mule.runtime.extension.api.annotation.param.display.Placement; + +@Alias("nomic") +@DisplayName("Nomic") +public class NomicModelConfiguration implements BaseModelConfiguration { + + @Parameter + @Password + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 1) + private String apiKey; + + @Override + public String getEmbeddingModelService() { + return Constants.EMBEDDING_MODEL_SERVICE_NOMIC; + } + + public String getApiKey() { + return apiKey; + } +} diff --git a/src/main/java/org/mule/extension/vectors/internal/model/openai/OpenAIModel.java b/src/main/java/org/mule/extension/vectors/internal/model/openai/OpenAIModel.java index c3b470c..c28bde9 100644 --- a/src/main/java/org/mule/extension/vectors/internal/model/openai/OpenAIModel.java +++ b/src/main/java/org/mule/extension/vectors/internal/model/openai/OpenAIModel.java @@ -16,10 +16,9 @@ public class OpenAIModel extends BaseModel { public OpenAIModel(Configuration configuration, EmbeddingModelParameters embeddingModelParameters) { super(configuration,embeddingModelParameters); - JSONObject config = readConfigFile(configuration.getConfigFilePath()); - assert config != null; - JSONObject modelConfig = config.getJSONObject("OPENAI"); - this.apiKey = modelConfig.getString("OPENAI_API_KEY"); + + OpenAIModelConfiguration openAIModelConfiguration = (OpenAIModelConfiguration) configuration.getModelConfiguration(); + this.apiKey = openAIModelConfiguration.getApiKey(); } public EmbeddingModel buildEmbeddingModel() { diff --git a/src/main/java/org/mule/extension/vectors/internal/model/openai/OpenAIModelConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/model/openai/OpenAIModelConfiguration.java new file mode 100644 index 0000000..38a1d62 --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/model/openai/OpenAIModelConfiguration.java @@ -0,0 +1,31 @@ +package org.mule.extension.vectors.internal.model.openai; + +import org.mule.extension.vectors.internal.constant.Constants; +import org.mule.extension.vectors.internal.model.BaseModelConfiguration; +import org.mule.runtime.api.meta.ExpressionSupport; +import org.mule.runtime.extension.api.annotation.Alias; +import org.mule.runtime.extension.api.annotation.Expression; +import org.mule.runtime.extension.api.annotation.param.Parameter; +import org.mule.runtime.extension.api.annotation.param.display.DisplayName; +import org.mule.runtime.extension.api.annotation.param.display.Password; +import org.mule.runtime.extension.api.annotation.param.display.Placement; + +@Alias("openAI") +@DisplayName("OpenAI") +public class OpenAIModelConfiguration implements BaseModelConfiguration { + + @Parameter + @Password + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 1) + private String apiKey; + + @Override + public String getEmbeddingModelService() { + return Constants.EMBEDDING_MODEL_SERVICE_OPENAI; + } + + public String getApiKey() { + return apiKey; + } +} diff --git a/src/main/java/org/mule/extension/vectors/internal/operation/EmbeddingOperations.java b/src/main/java/org/mule/extension/vectors/internal/operation/EmbeddingOperations.java index f34d81d..4787197 100644 --- a/src/main/java/org/mule/extension/vectors/internal/operation/EmbeddingOperations.java +++ b/src/main/java/org/mule/extension/vectors/internal/operation/EmbeddingOperations.java @@ -199,7 +199,7 @@ public class EmbeddingOperations { try { EmbeddingOperationValidator.validateOperationType( - Constants.EMBEDDING_OPERATION_TYPE_STORE_METADATA,configuration.getVectorStore()); + Constants.EMBEDDING_OPERATION_TYPE_STORE_METADATA,configuration.getStoreConfiguration().getVectorStore()); BaseModel baseModel = BaseModel.builder() .configuration(configuration) @@ -279,7 +279,7 @@ public class EmbeddingOperations { try { EmbeddingOperationValidator.validateOperationType( - Constants.EMBEDDING_OPERATION_TYPE_STORE_METADATA,configuration.getVectorStore()); + Constants.EMBEDDING_OPERATION_TYPE_STORE_METADATA,configuration.getStoreConfiguration().getVectorStore()); BaseModel baseModel = BaseModel.builder() .configuration(configuration) @@ -451,7 +451,7 @@ public class EmbeddingOperations { try { EmbeddingOperationValidator.validateOperationType( - Constants.EMBEDDING_OPERATION_TYPE_FILTER_BY_METADATA,configuration.getVectorStore()); + Constants.EMBEDDING_OPERATION_TYPE_FILTER_BY_METADATA,configuration.getStoreConfiguration().getVectorStore()); int maximumResults = (int) maxResults; if (minScore == null) { //|| minScore == 0) { @@ -570,9 +570,9 @@ public class EmbeddingOperations { try { EmbeddingOperationValidator.validateOperationType( - Constants.EMBEDDING_OPERATION_TYPE_QUERY_ALL,configuration.getVectorStore()); + Constants.EMBEDDING_OPERATION_TYPE_QUERY_ALL,configuration.getStoreConfiguration().getVectorStore()); EmbeddingOperationValidator.validateOperationType( - Constants.EMBEDDING_OPERATION_TYPE_FILTER_BY_METADATA,configuration.getVectorStore()); + Constants.EMBEDDING_OPERATION_TYPE_FILTER_BY_METADATA,configuration.getStoreConfiguration().getVectorStore()); BaseStore baseStore = BaseStore.builder() .storeName(storeName) @@ -616,9 +616,9 @@ public class EmbeddingOperations { try { EmbeddingOperationValidator.validateOperationType( - Constants.EMBEDDING_OPERATION_TYPE_REMOVE_EMBEDDINGS,configuration.getVectorStore()); + Constants.EMBEDDING_OPERATION_TYPE_REMOVE_EMBEDDINGS,configuration.getStoreConfiguration().getVectorStore()); EmbeddingOperationValidator.validateOperationType( - Constants.EMBEDDING_OPERATION_TYPE_FILTER_BY_METADATA,configuration.getVectorStore()); + Constants.EMBEDDING_OPERATION_TYPE_FILTER_BY_METADATA,configuration.getStoreConfiguration().getVectorStore()); BaseModel baseModel = BaseModel.builder() .configuration(configuration) diff --git a/src/main/java/org/mule/extension/vectors/internal/storage/BaseStorage.java b/src/main/java/org/mule/extension/vectors/internal/storage/BaseStorage.java index c3da0fc..a2e015f 100644 --- a/src/main/java/org/mule/extension/vectors/internal/storage/BaseStorage.java +++ b/src/main/java/org/mule/extension/vectors/internal/storage/BaseStorage.java @@ -6,9 +6,11 @@ import dev.langchain4j.data.document.parser.apache.tika.ApacheTikaDocumentParser; import org.mule.extension.vectors.internal.config.Configuration; import org.mule.extension.vectors.internal.constant.Constants; +import org.mule.extension.vectors.internal.error.MuleVectorsErrorType; import org.mule.extension.vectors.internal.storage.azureblob.AzureBlobStorage; import org.mule.extension.vectors.internal.storage.local.LocalStorage; import org.mule.extension.vectors.internal.storage.s3.AWSS3Storage; +import org.mule.runtime.extension.api.exception.ModuleException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -104,26 +106,57 @@ public BaseStorage build() { BaseStorage baseStorage; - LOGGER.debug("Storage Type: " + storageType); - switch (storageType) { + try { - case Constants.STORAGE_TYPE_LOCAL: + LOGGER.debug("Storage Type: " + storageType); + switch (storageType) { - baseStorage = new LocalStorage(configuration, contextPath, fileType); - break; - case Constants.STORAGE_TYPE_S3: + case Constants.STORAGE_TYPE_LOCAL: - baseStorage = new AWSS3Storage(configuration, contextPath, fileType); - break; + baseStorage = new LocalStorage(configuration, contextPath, fileType); + break; - case Constants.STORAGE_TYPE_AZURE_BLOB: + case Constants.STORAGE_TYPE_CLOUD: - baseStorage = new AzureBlobStorage(configuration, contextPath, fileType); - break; + LOGGER.debug("Storage Provider: " + configuration.getStorageConfiguration().getStorageProvider()); + switch (configuration.getStorageConfiguration().getStorageProvider()) { - default: - //throw new IllegalOperationException("Unsupported Vector Store: " + configuration.getVectorStore()); - baseStorage = null; + case Constants.STORAGE_PROVIDER_AWS_S3: + + baseStorage = new AWSS3Storage(configuration, contextPath, fileType); + break; + + case Constants.STORAGE_PROVIDER_AZURE_BLOB: + + baseStorage = new AzureBlobStorage(configuration, contextPath, fileType); + break; + + default: + + throw new ModuleException( + String.format("Error while initializing storage. Provider \"%s\" is not supported.", + configuration.getStorageConfiguration().getStorageProvider()), + MuleVectorsErrorType.STORAGE_SERVICES_FAILURE); + + } + break; + + default: + + throw new ModuleException( + String.format("Error while initializing storage. Type \"%s\" is not supported.", storageType), + MuleVectorsErrorType.STORAGE_SERVICES_FAILURE); + } + } catch (ModuleException e) { + + throw e; + + } catch (Exception e) { + + throw new ModuleException( + String.format("Error while initializing storage type \"%s\".", storageType), + MuleVectorsErrorType.STORAGE_SERVICES_FAILURE, + e); } return baseStorage; } diff --git a/src/main/java/org/mule/extension/vectors/internal/storage/BaseStorageConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/storage/BaseStorageConfiguration.java new file mode 100644 index 0000000..e9d9d72 --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/storage/BaseStorageConfiguration.java @@ -0,0 +1,6 @@ +package org.mule.extension.vectors.internal.storage; + +public interface BaseStorageConfiguration { + + String getStorageProvider(); +} diff --git a/src/main/java/org/mule/extension/vectors/internal/storage/azureblob/AzureBlobStorage.java b/src/main/java/org/mule/extension/vectors/internal/storage/azureblob/AzureBlobStorage.java index e96a8b5..2c9f29b 100644 --- a/src/main/java/org/mule/extension/vectors/internal/storage/azureblob/AzureBlobStorage.java +++ b/src/main/java/org/mule/extension/vectors/internal/storage/azureblob/AzureBlobStorage.java @@ -73,11 +73,10 @@ private Iterator getBlobIterator() { public AzureBlobStorage(Configuration configuration, String contextPath, String fileType) { super(configuration, contextPath, fileType); - JSONObject config = JsonUtils.readConfigFile(configuration.getConfigFilePath()); - assert config != null; - JSONObject storageConfig = config.getJSONObject("AZURE_BLOB"); - this.azureName = storageConfig.getString("AZURE_BLOB_ACCOUNT_NAME"); - this.azureKey = storageConfig.getString("AZURE_BLOB_ACCOUNT_KEY"); + + AzureBlobStorageConfiguration azureBlobStorageDocumentLoader = (AzureBlobStorageConfiguration) configuration.getStorageConfiguration(); + this.azureName = azureBlobStorageDocumentLoader.getAzureName(); + this.azureKey = azureBlobStorageDocumentLoader.getAzureKey(); } @Override diff --git a/src/main/java/org/mule/extension/vectors/internal/storage/azureblob/AzureBlobStorageConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/storage/azureblob/AzureBlobStorageConfiguration.java new file mode 100644 index 0000000..468d01b --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/storage/azureblob/AzureBlobStorageConfiguration.java @@ -0,0 +1,37 @@ +package org.mule.extension.vectors.internal.storage.azureblob; + +import org.mule.extension.vectors.internal.constant.Constants; +import org.mule.extension.vectors.internal.storage.BaseStorageConfiguration; +import org.mule.runtime.api.meta.ExpressionSupport; +import org.mule.runtime.extension.api.annotation.Alias; +import org.mule.runtime.extension.api.annotation.Expression; +import org.mule.runtime.extension.api.annotation.param.Parameter; +import org.mule.runtime.extension.api.annotation.param.display.DisplayName; +import org.mule.runtime.extension.api.annotation.param.display.Password; +import org.mule.runtime.extension.api.annotation.param.display.Placement; + +@Alias("azureBlob") +@DisplayName("Azure Blob") +public class AzureBlobStorageConfiguration implements BaseStorageConfiguration { + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 1) + private String azureName; + + @Parameter + @Password + @Placement(order = 2) + private String azureKey; + + @Override + public String getStorageProvider() { return Constants.STORAGE_PROVIDER_AZURE_BLOB; } + + public String getAzureName() { + return azureName; + } + + public String getAzureKey() { + return azureKey; + } +} diff --git a/src/main/java/org/mule/extension/vectors/internal/storage/s3/AWSS3Storage.java b/src/main/java/org/mule/extension/vectors/internal/storage/s3/AWSS3Storage.java index c0c3df8..f14fa9e 100644 --- a/src/main/java/org/mule/extension/vectors/internal/storage/s3/AWSS3Storage.java +++ b/src/main/java/org/mule/extension/vectors/internal/storage/s3/AWSS3Storage.java @@ -97,12 +97,12 @@ private Iterator getS3ObjectIterator() { public AWSS3Storage(Configuration configuration, String contextPath, String fileType) { super(configuration, contextPath, fileType); - JSONObject config = JsonUtils.readConfigFile(configuration.getConfigFilePath()); - assert config != null; - JSONObject storageConfig = config.getJSONObject("S3"); - this.awsAccessKeyId = storageConfig.getString("AWS_ACCESS_KEY_ID"); - this.awsSecretAccessKey = storageConfig.getString("AWS_SECRET_ACCESS_KEY"); - this.awsRegion = storageConfig.getString("AWS_DEFAULT_REGION"); + + AWSS3StorageConfiguration awsS3StorageConfiguration = (AWSS3StorageConfiguration) configuration.getStorageConfiguration(); + + this.awsAccessKeyId = awsS3StorageConfiguration.getAwsAccessKeyId(); + this.awsSecretAccessKey = awsS3StorageConfiguration.getAwsSecretAccessKey(); + this.awsRegion = awsS3StorageConfiguration.getAwsRegion(); } @Override diff --git a/src/main/java/org/mule/extension/vectors/internal/storage/s3/AWSS3StorageConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/storage/s3/AWSS3StorageConfiguration.java new file mode 100644 index 0000000..684b215 --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/storage/s3/AWSS3StorageConfiguration.java @@ -0,0 +1,48 @@ +package org.mule.extension.vectors.internal.storage.s3; + +import org.mule.extension.vectors.internal.constant.Constants; +import org.mule.extension.vectors.internal.storage.BaseStorageConfiguration; +import org.mule.runtime.api.meta.ExpressionSupport; +import org.mule.runtime.extension.api.annotation.Alias; +import org.mule.runtime.extension.api.annotation.Expression; +import org.mule.runtime.extension.api.annotation.param.Parameter; +import org.mule.runtime.extension.api.annotation.param.display.DisplayName; +import org.mule.runtime.extension.api.annotation.param.display.Password; +import org.mule.runtime.extension.api.annotation.param.display.Placement; + +@Alias("awsS3") +@DisplayName("AWS S3") +public class AWSS3StorageConfiguration implements BaseStorageConfiguration { + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 1) + private String awsRegion; + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 2) + private String awsAccessKeyId; + + @Parameter + @Password + @Placement(order = 3) + private String awsSecretAccessKey; + + @Override + public String getStorageProvider() { + return Constants.STORAGE_PROVIDER_AWS_S3; + } + + public String getAwsRegion() { + return awsRegion; + } + + public String getAwsAccessKeyId() { + return awsAccessKeyId; + } + + public String getAwsSecretAccessKey() { + return awsSecretAccessKey; + } +} diff --git a/src/main/java/org/mule/extension/vectors/internal/store/BaseStore.java b/src/main/java/org/mule/extension/vectors/internal/store/BaseStore.java index 3fa4469..c6069ed 100644 --- a/src/main/java/org/mule/extension/vectors/internal/store/BaseStore.java +++ b/src/main/java/org/mule/extension/vectors/internal/store/BaseStore.java @@ -258,7 +258,7 @@ public BaseStore build() { BaseStore baseStore; - switch (configuration.getVectorStore()) { + switch (configuration.getStoreConfiguration().getVectorStore()) { case Constants.VECTOR_STORE_MILVUS: @@ -302,7 +302,7 @@ public BaseStore build() { default: throw new ModuleException( - String.format("Error while initializing embedding store. \"%s\" not supported.", configuration.getVectorStore()), + String.format("Error while initializing embedding store. \"%s\" not supported.", configuration.getStoreConfiguration().getVectorStore()), MuleVectorsErrorType.STORE_SERVICES_FAILURE); } return baseStore; diff --git a/src/main/java/org/mule/extension/vectors/internal/store/BaseStoreConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/store/BaseStoreConfiguration.java new file mode 100644 index 0000000..7d175e4 --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/store/BaseStoreConfiguration.java @@ -0,0 +1,6 @@ +package org.mule.extension.vectors.internal.store; + +public interface BaseStoreConfiguration { + + String getVectorStore(); +} diff --git a/src/main/java/org/mule/extension/vectors/internal/store/aisearch/AISearchStore.java b/src/main/java/org/mule/extension/vectors/internal/store/aisearch/AISearchStore.java index 63b00d5..18b559c 100644 --- a/src/main/java/org/mule/extension/vectors/internal/store/aisearch/AISearchStore.java +++ b/src/main/java/org/mule/extension/vectors/internal/store/aisearch/AISearchStore.java @@ -23,17 +23,16 @@ public class AISearchStore extends BaseStore { private static final String API_VERSION = "2024-07-01"; - private String apiKey; - private String url; + private final String apiKey; + private final String url; public AISearchStore(String storeName, Configuration configuration, QueryParameters queryParams, int dimension) { super(storeName, configuration, queryParams, dimension); - JSONObject config = readConfigFile(configuration.getConfigFilePath()); - JSONObject vectorStoreConfig = config.getJSONObject(Constants.VECTOR_STORE_AI_SEARCH); - this.apiKey = vectorStoreConfig.getString("AI_SEARCH_KEY"); - this.url = vectorStoreConfig.getString("AI_SEARCH_URL"); + AISearchStoreConfiguration aiSearchStoreConfiguration = (AISearchStoreConfiguration) configuration.getStoreConfiguration(); + this.url = aiSearchStoreConfiguration.getUrl(); + this.apiKey = aiSearchStoreConfiguration.getApiKey(); } public EmbeddingStore buildEmbeddingStore() { diff --git a/src/main/java/org/mule/extension/vectors/internal/store/aisearch/AISearchStoreConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/store/aisearch/AISearchStoreConfiguration.java new file mode 100644 index 0000000..83a75a1 --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/store/aisearch/AISearchStoreConfiguration.java @@ -0,0 +1,42 @@ +package org.mule.extension.vectors.internal.store.aisearch; + +import org.mule.extension.vectors.internal.constant.Constants; +import org.mule.extension.vectors.internal.store.BaseStoreConfiguration; +import org.mule.runtime.api.meta.ExpressionSupport; +import org.mule.runtime.extension.api.annotation.Alias; +import org.mule.runtime.extension.api.annotation.Expression; +import org.mule.runtime.extension.api.annotation.param.Parameter; +import org.mule.runtime.extension.api.annotation.param.display.DisplayName; +import org.mule.runtime.extension.api.annotation.param.display.Password; +import org.mule.runtime.extension.api.annotation.param.display.Placement; + +import javax.annotation.processing.SupportedOptions; + +@Alias("aiSearch") +@DisplayName("AI Search") +public class AISearchStoreConfiguration implements BaseStoreConfiguration { + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 1) + private String url; + + @Parameter + @Password + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 2) + private String apiKey; + + @Override + public String getVectorStore() { + return Constants.VECTOR_STORE_AI_SEARCH; + } + + public String getUrl() { + return url; + } + + public String getApiKey() { + return apiKey; + } +} diff --git a/src/main/java/org/mule/extension/vectors/internal/store/chroma/ChromaStore.java b/src/main/java/org/mule/extension/vectors/internal/store/chroma/ChromaStore.java index 9d67d70..6e91602 100644 --- a/src/main/java/org/mule/extension/vectors/internal/store/chroma/ChromaStore.java +++ b/src/main/java/org/mule/extension/vectors/internal/store/chroma/ChromaStore.java @@ -9,6 +9,7 @@ import org.mule.extension.vectors.internal.constant.Constants; import org.mule.extension.vectors.internal.helper.parameter.QueryParameters; import org.mule.extension.vectors.internal.store.BaseStore; +import org.mule.extension.vectors.internal.store.aisearch.AISearchStoreConfiguration; import org.mule.extension.vectors.internal.util.JsonUtils; import java.io.BufferedReader; @@ -24,7 +25,7 @@ */ public class ChromaStore extends BaseStore { - private String url; + private final String url; /** @@ -38,9 +39,8 @@ public ChromaStore(String storeName, Configuration configuration, QueryParameter super(storeName, configuration, queryParams, dimension); - JSONObject config = JsonUtils.readConfigFile(configuration.getConfigFilePath()); - JSONObject vectorStoreConfig = config.getJSONObject(Constants.VECTOR_STORE_CHROMA); - this.url = vectorStoreConfig.getString("CHROMA_URL"); + ChromaStoreConfiguration chromaStoreConfiguration = (ChromaStoreConfiguration) configuration.getStoreConfiguration(); + this.url = chromaStoreConfiguration.getUrl(); } public EmbeddingStore buildEmbeddingStore() { diff --git a/src/main/java/org/mule/extension/vectors/internal/store/chroma/ChromaStoreConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/store/chroma/ChromaStoreConfiguration.java new file mode 100644 index 0000000..54aafae --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/store/chroma/ChromaStoreConfiguration.java @@ -0,0 +1,29 @@ +package org.mule.extension.vectors.internal.store.chroma; + +import org.mule.extension.vectors.internal.constant.Constants; +import org.mule.extension.vectors.internal.store.BaseStoreConfiguration; +import org.mule.runtime.api.meta.ExpressionSupport; +import org.mule.runtime.extension.api.annotation.Alias; +import org.mule.runtime.extension.api.annotation.Expression; +import org.mule.runtime.extension.api.annotation.param.Parameter; +import org.mule.runtime.extension.api.annotation.param.display.DisplayName; +import org.mule.runtime.extension.api.annotation.param.display.Placement; + +@Alias("chroma") +@DisplayName("Chroma") +public class ChromaStoreConfiguration implements BaseStoreConfiguration { + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 1) + private String url; + + @Override + public String getVectorStore() { + return Constants.VECTOR_STORE_CHROMA; + } + + public String getUrl() { + return url; + } +} diff --git a/src/main/java/org/mule/extension/vectors/internal/store/elasticsearch/ElasticsearchStore.java b/src/main/java/org/mule/extension/vectors/internal/store/elasticsearch/ElasticsearchStore.java index bcdf656..416e2f5 100644 --- a/src/main/java/org/mule/extension/vectors/internal/store/elasticsearch/ElasticsearchStore.java +++ b/src/main/java/org/mule/extension/vectors/internal/store/elasticsearch/ElasticsearchStore.java @@ -2,6 +2,7 @@ import dev.langchain4j.data.segment.TextSegment; import dev.langchain4j.store.embedding.EmbeddingStore; +import dev.langchain4j.store.embedding.elasticsearch.ElasticsearchConfiguration; import dev.langchain4j.store.embedding.elasticsearch.ElasticsearchEmbeddingStore; import org.json.JSONObject; import org.mule.extension.vectors.internal.config.Configuration; @@ -12,19 +13,18 @@ public class ElasticsearchStore extends BaseStore { - private String url; - private String userName; - private String password; + private final String url; + private final String userName; + private final String password; public ElasticsearchStore(String storeName, Configuration configuration, QueryParameters queryParams, int dimension) { super(storeName, configuration, queryParams, dimension); - JSONObject config = JsonUtils.readConfigFile(configuration.getConfigFilePath()); - JSONObject vectorStoreConfig = config.getJSONObject(Constants.VECTOR_STORE_ELASTICSEARCH); - this.url = vectorStoreConfig.getString("ELASTICSEARCH_URL"); - this.userName = vectorStoreConfig.getString("ELASTICSEARCH_USER"); - this.password = vectorStoreConfig.getString("ELASTICSEARCH_PASSWORD"); + ElasticsearchStoreConfiguration elasticsearchStoreConfiguration = (ElasticsearchStoreConfiguration) configuration.getStoreConfiguration(); + this.url = elasticsearchStoreConfiguration.getUrl(); + this.userName = elasticsearchStoreConfiguration.getUserName(); + this.password = elasticsearchStoreConfiguration.getPassword(); } public EmbeddingStore buildEmbeddingStore() { diff --git a/src/main/java/org/mule/extension/vectors/internal/store/elasticsearch/ElasticsearchStoreConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/store/elasticsearch/ElasticsearchStoreConfiguration.java new file mode 100644 index 0000000..1ae7311 --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/store/elasticsearch/ElasticsearchStoreConfiguration.java @@ -0,0 +1,49 @@ +package org.mule.extension.vectors.internal.store.elasticsearch; + +import org.mule.extension.vectors.internal.constant.Constants; +import org.mule.extension.vectors.internal.store.BaseStoreConfiguration; +import org.mule.runtime.api.meta.ExpressionSupport; +import org.mule.runtime.extension.api.annotation.Alias; +import org.mule.runtime.extension.api.annotation.Expression; +import org.mule.runtime.extension.api.annotation.param.Parameter; +import org.mule.runtime.extension.api.annotation.param.display.DisplayName; +import org.mule.runtime.extension.api.annotation.param.display.Password; +import org.mule.runtime.extension.api.annotation.param.display.Placement; + +@Alias("elasticsearch") +@DisplayName("Elasticsearch") +public class ElasticsearchStoreConfiguration implements BaseStoreConfiguration { + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 1) + private String url; + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 2) + private String userName; + + @Parameter + @Password + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 3) + private String password; + + @Override + public String getVectorStore() { + return Constants.VECTOR_STORE_ELASTICSEARCH; + } + + public String getUrl() { + return url; + } + + public String getUserName() { + return userName; + } + + public String getPassword() { + return password; + } +} diff --git a/src/main/java/org/mule/extension/vectors/internal/store/milvus/MilvusStore.java b/src/main/java/org/mule/extension/vectors/internal/store/milvus/MilvusStore.java index a436a9f..a0a52a1 100644 --- a/src/main/java/org/mule/extension/vectors/internal/store/milvus/MilvusStore.java +++ b/src/main/java/org/mule/extension/vectors/internal/store/milvus/MilvusStore.java @@ -26,15 +26,14 @@ public class MilvusStore extends BaseStore { - private String uri; + private final String uri; public MilvusStore(String storeName, Configuration configuration, QueryParameters queryParams, int dimension) { super(storeName, configuration, queryParams, dimension); - JSONObject config = readConfigFile(configuration.getConfigFilePath()); - JSONObject vectorStoreConfig = config.getJSONObject(Constants.VECTOR_STORE_MILVUS); - this.uri = vectorStoreConfig.getString("MILVUS_URL"); + MilvusStoreConfiguration milvusStoreConfiguration = (MilvusStoreConfiguration) configuration.getStoreConfiguration(); + this.uri = milvusStoreConfiguration.getUrl(); } public EmbeddingStore buildEmbeddingStore() { diff --git a/src/main/java/org/mule/extension/vectors/internal/store/milvus/MilvusStoreConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/store/milvus/MilvusStoreConfiguration.java new file mode 100644 index 0000000..39927c5 --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/store/milvus/MilvusStoreConfiguration.java @@ -0,0 +1,29 @@ +package org.mule.extension.vectors.internal.store.milvus; + +import org.mule.extension.vectors.internal.constant.Constants; +import org.mule.extension.vectors.internal.store.BaseStoreConfiguration; +import org.mule.runtime.api.meta.ExpressionSupport; +import org.mule.runtime.extension.api.annotation.Alias; +import org.mule.runtime.extension.api.annotation.Expression; +import org.mule.runtime.extension.api.annotation.param.Parameter; +import org.mule.runtime.extension.api.annotation.param.display.DisplayName; +import org.mule.runtime.extension.api.annotation.param.display.Placement; + +@Alias("milvus") +@DisplayName("Milvus") +public class MilvusStoreConfiguration implements BaseStoreConfiguration { + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 1) + private String url; + + @Override + public String getVectorStore() { + return Constants.VECTOR_STORE_MILVUS; + } + + public String getUrl() { + return url; + } +} diff --git a/src/main/java/org/mule/extension/vectors/internal/store/opensearch/OpenSearchStore.java b/src/main/java/org/mule/extension/vectors/internal/store/opensearch/OpenSearchStore.java index 3915cc7..267d025 100644 --- a/src/main/java/org/mule/extension/vectors/internal/store/opensearch/OpenSearchStore.java +++ b/src/main/java/org/mule/extension/vectors/internal/store/opensearch/OpenSearchStore.java @@ -12,19 +12,18 @@ public class OpenSearchStore extends BaseStore { - private String url; - private String userName; - private String password; + private final String url; + private final String userName; + private final String password; public OpenSearchStore(String storeName, Configuration configuration, QueryParameters queryParams, int dimension) { super(storeName, configuration, queryParams, dimension); - JSONObject config = JsonUtils.readConfigFile(configuration.getConfigFilePath()); - JSONObject vectorStoreConfig = config.getJSONObject(Constants.VECTOR_STORE_OPENSEARCH); - this.url = vectorStoreConfig.getString("OPENSEARCH_URL"); - this.userName = vectorStoreConfig.getString("OPENSEARCH_USER"); - this.password = vectorStoreConfig.getString("OPENSEARCH_PASSWORD"); + OpenSearchStoreConfiguration openSearchStoreConfiguration = (OpenSearchStoreConfiguration) configuration.getStoreConfiguration(); + this.url = openSearchStoreConfiguration.getUrl(); + this.userName = openSearchStoreConfiguration.getUserName(); + this.password = openSearchStoreConfiguration.getPassword(); } public EmbeddingStore buildEmbeddingStore() { diff --git a/src/main/java/org/mule/extension/vectors/internal/store/opensearch/OpenSearchStoreConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/store/opensearch/OpenSearchStoreConfiguration.java new file mode 100644 index 0000000..4a5b2af --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/store/opensearch/OpenSearchStoreConfiguration.java @@ -0,0 +1,49 @@ +package org.mule.extension.vectors.internal.store.opensearch; + +import org.mule.extension.vectors.internal.constant.Constants; +import org.mule.extension.vectors.internal.store.BaseStoreConfiguration; +import org.mule.runtime.api.meta.ExpressionSupport; +import org.mule.runtime.extension.api.annotation.Alias; +import org.mule.runtime.extension.api.annotation.Expression; +import org.mule.runtime.extension.api.annotation.param.Parameter; +import org.mule.runtime.extension.api.annotation.param.display.DisplayName; +import org.mule.runtime.extension.api.annotation.param.display.Password; +import org.mule.runtime.extension.api.annotation.param.display.Placement; + +@Alias("openSearch") +@DisplayName("OpenSearch") +public class OpenSearchStoreConfiguration implements BaseStoreConfiguration { + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 1) + private String url; + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 2) + private String userName; + + @Parameter + @Password + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 3) + private String password; + + @Override + public String getVectorStore() { + return Constants.VECTOR_STORE_OPENSEARCH; + } + + public String getUrl() { + return url; + } + + public String getUserName() { + return userName; + } + + public String getPassword() { + return password; + } +} diff --git a/src/main/java/org/mule/extension/vectors/internal/store/pgvector/PGVectorStore.java b/src/main/java/org/mule/extension/vectors/internal/store/pgvector/PGVectorStore.java index 89ff1c4..e766ce3 100644 --- a/src/main/java/org/mule/extension/vectors/internal/store/pgvector/PGVectorStore.java +++ b/src/main/java/org/mule/extension/vectors/internal/store/pgvector/PGVectorStore.java @@ -48,13 +48,12 @@ public PGVectorStore(String storeName, Configuration configuration, QueryParamet super(storeName, configuration, queryParams, dimension); - JSONObject config = readConfigFile(configuration.getConfigFilePath()); - JSONObject vectorStoreConfig = config.getJSONObject(Constants.VECTOR_STORE_PGVECTOR); - this.host = vectorStoreConfig.getString("POSTGRES_HOST"); - this.port = vectorStoreConfig.getInt("POSTGRES_PORT"); - this.database = vectorStoreConfig.getString("POSTGRES_DATABASE"); - this.userName = vectorStoreConfig.getString("POSTGRES_USER"); - this.password = vectorStoreConfig.getString("POSTGRES_PASSWORD"); + PGVectorStoreConfiguration pgVectorStoreConfiguration = (PGVectorStoreConfiguration)configuration.getStoreConfiguration(); + this.host = pgVectorStoreConfiguration.getHost(); + this.port = pgVectorStoreConfiguration.getPort(); + this.database = pgVectorStoreConfiguration.getDatabase(); + this.userName = pgVectorStoreConfiguration.getUserName(); + this.password = pgVectorStoreConfiguration.getPassword(); } public EmbeddingStore buildEmbeddingStore() { diff --git a/src/main/java/org/mule/extension/vectors/internal/store/pgvector/PGVectorStoreConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/store/pgvector/PGVectorStoreConfiguration.java new file mode 100644 index 0000000..64cdcae --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/store/pgvector/PGVectorStoreConfiguration.java @@ -0,0 +1,67 @@ +package org.mule.extension.vectors.internal.store.pgvector; + +import org.mule.extension.vectors.internal.constant.Constants; +import org.mule.extension.vectors.internal.store.BaseStoreConfiguration; +import org.mule.runtime.api.meta.ExpressionSupport; +import org.mule.runtime.extension.api.annotation.Alias; +import org.mule.runtime.extension.api.annotation.Expression; +import org.mule.runtime.extension.api.annotation.param.Parameter; +import org.mule.runtime.extension.api.annotation.param.display.DisplayName; +import org.mule.runtime.extension.api.annotation.param.display.Password; +import org.mule.runtime.extension.api.annotation.param.display.Placement; + +@Alias("pgVector") +@DisplayName("PGVector") +public class PGVectorStoreConfiguration implements BaseStoreConfiguration { + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 1) + private String host; + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 2) + private int port; + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 3) + private String database; + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 4) + private String userName; + + @Parameter + @Password + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 5) + private String password; + + @Override + public String getVectorStore() { + return Constants.VECTOR_STORE_PGVECTOR; + } + + public String getHost() { + return host; + } + + public int getPort() { + return port; + } + + public String getDatabase() { + return database; + } + + public String getUserName() { + return userName; + } + + public String getPassword() { + return password; + } +} diff --git a/src/main/java/org/mule/extension/vectors/internal/store/pinecone/PineconeStore.java b/src/main/java/org/mule/extension/vectors/internal/store/pinecone/PineconeStore.java index 9fa2768..b13bd84 100644 --- a/src/main/java/org/mule/extension/vectors/internal/store/pinecone/PineconeStore.java +++ b/src/main/java/org/mule/extension/vectors/internal/store/pinecone/PineconeStore.java @@ -21,11 +21,10 @@ public PineconeStore(String storeName, Configuration configuration, QueryParamet super(storeName, configuration, queryParams, dimension); - JSONObject config = JsonUtils.readConfigFile(configuration.getConfigFilePath()); - JSONObject vectorStoreConfig = config.getJSONObject(Constants.VECTOR_STORE_PINECONE); - this.apiKey = vectorStoreConfig.getString("PINECONE_APIKEY"); - this.cloud = vectorStoreConfig.getString("PINECONE_SERVERLESS_CLOUD"); - this.region = vectorStoreConfig.getString("PINECONE_SERVERLESS_REGION"); + PineconeStoreConfiguration pineconeStoreConfiguration = (PineconeStoreConfiguration) configuration.getStoreConfiguration(); + this.apiKey = pineconeStoreConfiguration.getApiKey(); + this.cloud = pineconeStoreConfiguration.getCloud(); + this.region = pineconeStoreConfiguration.getRegion(); } public EmbeddingStore buildEmbeddingStore() { diff --git a/src/main/java/org/mule/extension/vectors/internal/store/pinecone/PineconeStoreConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/store/pinecone/PineconeStoreConfiguration.java new file mode 100644 index 0000000..b1f6e5b --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/store/pinecone/PineconeStoreConfiguration.java @@ -0,0 +1,49 @@ +package org.mule.extension.vectors.internal.store.pinecone; + +import org.mule.extension.vectors.internal.constant.Constants; +import org.mule.extension.vectors.internal.store.BaseStoreConfiguration; +import org.mule.runtime.api.meta.ExpressionSupport; +import org.mule.runtime.extension.api.annotation.Alias; +import org.mule.runtime.extension.api.annotation.Expression; +import org.mule.runtime.extension.api.annotation.param.Parameter; +import org.mule.runtime.extension.api.annotation.param.display.DisplayName; +import org.mule.runtime.extension.api.annotation.param.display.Password; +import org.mule.runtime.extension.api.annotation.param.display.Placement; + +@Alias("pinecone") +@DisplayName("Pinecone") +public class PineconeStoreConfiguration implements BaseStoreConfiguration { + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 1) + private String cloud; + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 2) + private String region; + + @Parameter + @Password + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 3) + private String apiKey; + + @Override + public String getVectorStore() { + return Constants.VECTOR_STORE_PINECONE; + } + + public String getCloud() { + return cloud; + } + + public String getRegion() { + return region; + } + + public String getApiKey() { + return apiKey; + } +} diff --git a/src/main/java/org/mule/extension/vectors/internal/store/qdrant/QdrantStore.java b/src/main/java/org/mule/extension/vectors/internal/store/qdrant/QdrantStore.java index 55ee92e..35bcb37 100644 --- a/src/main/java/org/mule/extension/vectors/internal/store/qdrant/QdrantStore.java +++ b/src/main/java/org/mule/extension/vectors/internal/store/qdrant/QdrantStore.java @@ -35,14 +35,13 @@ public QdrantStore(String storeName, Configuration configuration, QueryParameter try { - JSONObject config = JsonUtils.readConfigFile(configuration.getConfigFilePath()); - JSONObject vectorStoreConfig = config.getJSONObject(Constants.VECTOR_STORE_QDRANT); - String host = vectorStoreConfig.getString("QDRANT_HOST"); - String apiKey = vectorStoreConfig.getString("QDRANT_API_KEY"); - int port = vectorStoreConfig.getInt("QDRANT_GRPC_PORT"); - boolean useTls = vectorStoreConfig.getBoolean("QDRANT_USE_TLS"); + QdrantStoreConfiguration qdrantStoreConfiguration = (QdrantStoreConfiguration)configuration.getStoreConfiguration(); + String host = qdrantStoreConfiguration.getHost(); + String apiKey = qdrantStoreConfiguration.getApiKey(); + int port = qdrantStoreConfiguration.getGprcPort(); + boolean useTls = qdrantStoreConfiguration.isUseTLS(); this.client = new QdrantClient(QdrantGrpcClient.newBuilder(host, port, useTls).withApiKey(apiKey).build()); - this.payloadTextKey = vectorStoreConfig.getString("QDRANT_TEXT_KEY"); + this.payloadTextKey = qdrantStoreConfiguration.getTextSegmentKey(); if (!this.client.collectionExistsAsync(this.storeName).get() && dimension > 0) { this.client.createCollectionAsync(storeName, @@ -53,7 +52,7 @@ public QdrantStore(String storeName, Configuration configuration, QueryParameter } catch (Exception e) { throw new ModuleException( - String.format("Error while initializing embedding store \"%s\".", configuration.getVectorStore()), + String.format("Error while initializing embedding store \"%s\".", configuration.getStoreConfiguration().getVectorStore()), MuleVectorsErrorType.STORE_SERVICES_FAILURE); } } diff --git a/src/main/java/org/mule/extension/vectors/internal/store/qdrant/QdrantStoreConfiguration.java b/src/main/java/org/mule/extension/vectors/internal/store/qdrant/QdrantStoreConfiguration.java new file mode 100644 index 0000000..8fc47f6 --- /dev/null +++ b/src/main/java/org/mule/extension/vectors/internal/store/qdrant/QdrantStoreConfiguration.java @@ -0,0 +1,70 @@ +package org.mule.extension.vectors.internal.store.qdrant; + +import org.mule.extension.vectors.internal.constant.Constants; +import org.mule.extension.vectors.internal.store.BaseStoreConfiguration; +import org.mule.runtime.api.meta.ExpressionSupport; +import org.mule.runtime.extension.api.annotation.Alias; +import org.mule.runtime.extension.api.annotation.Expression; +import org.mule.runtime.extension.api.annotation.param.Parameter; +import org.mule.runtime.extension.api.annotation.param.display.DisplayName; +import org.mule.runtime.extension.api.annotation.param.display.Password; +import org.mule.runtime.extension.api.annotation.param.display.Placement; + +@Alias("qdrant") +@DisplayName("Qdrant") +public class QdrantStoreConfiguration implements BaseStoreConfiguration { + + private final String vectorStore = Constants.VECTOR_STORE_OPENSEARCH; + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 1) + private String host; + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @DisplayName("GPRC Port") + @Placement(order = 2) + private int gprcPort; + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 3) + private boolean useTLS; + + @Parameter + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 4) + private String textSegmentKey; + + @Parameter + @Password + @Expression(ExpressionSupport.SUPPORTED) + @Placement(order = 5) + private String apiKey; + + @Override + public String getVectorStore() { + return Constants.VECTOR_STORE_QDRANT; + } + + public String getHost() { + return host; + } + + public int getGprcPort() { + return gprcPort; + } + + public boolean isUseTLS() { + return useTLS; + } + + public String getTextSegmentKey() { + return textSegmentKey; + } + + public String getApiKey() { + return apiKey; + } +}