Skip to content

Commit

Permalink
Remove redundant parameter legitimacy checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
misselvexu committed Nov 19, 2024
1 parent 2e107b9 commit e29c321
Showing 1 changed file with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class PgVectorEmbeddingStoreAutoConfiguration {
@ConditionalOnMissingBean
@ConditionalOnBean(DataSource.class)
@ConditionalOnProperty(prefix = PgVectorDataSourceProperties.PREFIX, name = "enabled", havingValue = "false")
public PgVectorEmbeddingStore pgVectorEmbeddingStore(DataSource dataSource, PgVectorEmbeddingStoreProperties properties,
public PgVectorEmbeddingStore pgVectorEmbeddingStoreWithExistingDataSource(DataSource dataSource, PgVectorEmbeddingStoreProperties properties,
@Nullable EmbeddingModel embeddingModel) {
// Check if the context's data source is a Postgres datasource
ensureTrue(isPostgresqlDataSource(dataSource), "The DataSource in Spring Context is not a Postgres datasource, you need to manually specify the Postgres datasource configuration via 'langchain4j.pgvector.datasource'.");
Expand All @@ -53,21 +53,16 @@ public PgVectorEmbeddingStore pgVectorEmbeddingStore(DataSource dataSource, PgVe
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = PgVectorDataSourceProperties.PREFIX, name = "enabled", havingValue = "true")
public PgVectorEmbeddingStore pgVectorEmbeddingStore(PgVectorEmbeddingStoreProperties properties, PgVectorDataSourceProperties dataSourceProperties,
public PgVectorEmbeddingStore pgVectorEmbeddingStoreWithCustomDataSource(PgVectorEmbeddingStoreProperties properties, PgVectorDataSourceProperties dataSourceProperties,
@Nullable EmbeddingModel embeddingModel) {
Integer dimension = Optional.ofNullable(properties.getDimension()).orElseGet(() -> embeddingModel == null ? null : embeddingModel.dimension());
String host = ensureNotBlank(dataSourceProperties.getHost(), "langchain4j.pgvector.datasource.host");
Integer port = ensureGreaterThanZero(dataSourceProperties.getPort(), "langchain4j.pgvector.datasource.port");
String user = ensureNotBlank(dataSourceProperties.getUser(), "langchain4j.pgvector.datasource.user");
String password = ensureNotBlank(dataSourceProperties.getPassword(), "langchain4j.pgvector.datasource.password");
String database = ensureNotBlank(dataSourceProperties.getDatabase(), "langchain4j.pgvector.datasource.database");

return PgVectorEmbeddingStore.builder()
.host(host)
.port(port)
.user(user)
.password(password)
.database(database)
.host(dataSourceProperties.getHost())
.port(dataSourceProperties.getPort())
.user(dataSourceProperties.getUser())
.password(dataSourceProperties.getPassword())
.database(dataSourceProperties.getDatabase())
.table(properties.getTable())
.createTable(properties.getCreateTable())
.dimension(dimension)
Expand Down

0 comments on commit e29c321

Please sign in to comment.