Skip to content

Commit 6c87134

Browse files
shrikanthkrjmartisk
authored andcommitted
pass configs and an extension value to make sure vector extensions are created and can be overridden by passing that config
1 parent d7027e5 commit 6c87134

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

embedding-stores/pgvector/deployment/src/main/java/io/quarkiverse/langchain4j/pgvector/deployment/PgVectorEmbeddingStoreProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void createBean(
8080
.setRuntimeInit()
8181
.unremovable()
8282
.scope(ApplicationScoped.class)
83-
.supplier(recorder.pgVectorAgroalPoolInterceptor())
83+
.supplier(recorder.pgVectorAgroalPoolInterceptor(config))
8484
.qualifiers(datasourceQualifier)
8585
.done());
8686

embedding-stores/pgvector/runtime/src/main/java/io/quarkiverse/langchain4j/pgvector/PgVectorAgroalPoolInterceptor.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.quarkiverse.langchain4j.pgvector;
22

3+
import io.quarkiverse.langchain4j.pgvector.runtime.PgVectorEmbeddingStoreConfig;
34
import java.sql.Connection;
45
import java.sql.SQLException;
56
import java.sql.Statement;
@@ -14,10 +15,18 @@
1415
*/
1516
public class PgVectorAgroalPoolInterceptor implements AgroalPoolInterceptor {
1617

18+
PgVectorEmbeddingStoreConfig config;
19+
20+
public PgVectorAgroalPoolInterceptor(PgVectorEmbeddingStoreConfig config) {
21+
this.config = config;
22+
}
23+
1724
@Override
1825
public void onConnectionCreate(Connection connection) {
1926
try (Statement statement = connection.createStatement()) {
20-
if (ConfigUtils.isProfileActive("dev") || ConfigUtils.isProfileActive("test")) {
27+
boolean createExtension =
28+
ConfigUtils.isProfileActive("dev") || ConfigUtils.isProfileActive("test") || this.config.registerVectorPGExtension();
29+
if (createExtension) {
2130
statement.executeUpdate("CREATE EXTENSION IF NOT EXISTS vector");
2231
}
2332
PGvector.addVectorType(connection);

embedding-stores/pgvector/runtime/src/main/java/io/quarkiverse/langchain4j/pgvector/runtime/PgVectorEmbeddingStoreConfig.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static io.quarkus.runtime.annotations.ConfigPhase.RUN_TIME;
44

5+
import io.smallrye.config.WithName;
56
import java.util.List;
67
import java.util.Optional;
78

@@ -53,6 +54,14 @@ public interface PgVectorEmbeddingStoreConfig {
5354
@WithDefault("false")
5455
Boolean dropTableFirst();
5556

57+
/**
58+
* Whether the PG extension should be created on Start.
59+
* By Default, if it's dev or test environment the value is overridden to true
60+
*/
61+
@WithDefault("false")
62+
@WithName("register-vector-pg-extension")
63+
Boolean registerVectorPGExtension();
64+
5665
/**
5766
* Metadata configuration.
5867
*/

embedding-stores/pgvector/runtime/src/main/java/io/quarkiverse/langchain4j/pgvector/runtime/PgVectorEmbeddingStoreRecorder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ public PgVectorEmbeddingStore apply(SyntheticCreationalContext<PgVectorEmbedding
3535
};
3636
}
3737

38-
public Supplier<PgVectorAgroalPoolInterceptor> pgVectorAgroalPoolInterceptor() {
38+
public Supplier<PgVectorAgroalPoolInterceptor> pgVectorAgroalPoolInterceptor(PgVectorEmbeddingStoreConfig config) {
3939
return new Supplier<>() {
4040
@Override
4141
public PgVectorAgroalPoolInterceptor get() {
42-
return new PgVectorAgroalPoolInterceptor();
42+
return new PgVectorAgroalPoolInterceptor(config);
4343
}
4444
};
4545
}

0 commit comments

Comments
 (0)