Repository: langchain4j/langchain4j (2026-07-16T15:56:28Z)

Issue:
[BUG] PgVector does not pass through to the constructor from Builder
embeddingStore = PgVectorEmbeddingStore.builder()
                        .host(host)
                        .port(port)
                        .database(database)
                        .user(username)
                        .password(password)
                        .table("embeddings")
                        .dimension(aiContext.currentModelConfig.getVectorDimension())
                        .dropTableFirst(false)
                        .useIndex(false)
                        .createTable(false)
                        **.skipCreateVectorExtension(true**)
                        .indexListSize(100)
                        .build();

The skipCreateVectorExtension is not passed through to the Constructor of PgVectorEmbeddingStore
- 
- LangChain4j 17,2
- LLM(s) openAI
- Java version: 21



Discussion:

Patch:
diff --git a/langchain4j-pgvector/src/main/java/dev/langchain4j/store/embedding/pgvector/PgVectorEmbeddingStore.java b/langchain4j-pgvector/src/main/java/dev/langchain4j/store/embedding/pgvector/PgVectorEmbeddingStore.java
index 00309a8d5c5..2bf1d7c8679 100644
--- a/langchain4j-pgvector/src/main/java/dev/langchain4j/store/embedding/pgvector/PgVectorEmbeddingStore.java
+++ b/langchain4j-pgvector/src/main/java/dev/langchain4j/store/embedding/pgvector/PgVectorEmbeddingStore.java
@@ -229,18 +229,20 @@ protected PgVectorEmbeddingStore(
      * @param builder The builder containing all configuration
      */
     protected PgVectorEmbeddingStore(PgVectorEmbeddingStoreBuilder builder) {
-        this(
-                createDataSource(builder.host, builder.port, builder.user, builder.password, builder.database),
-                builder.table,
-                builder.dimension,
-                builder.useIndex,
-                builder.indexListSize,
-                builder.createTable,
-                builder.dropTableFirst,
-                builder.metadataStorageConfig,
-                builder.searchMode,
-                builder.textSearchConfig,
-                builder.rrfK);
+        this(new DatasourceBuilder()
+                .datasource(
+                        createDataSource(builder.host, builder.port, builder.user, builder.password, builder.database))
+                .table(builder.table)
+                .dimension(builder.dimension)
+                .useIndex(builder.useIndex)
+                .indexListSize(builder.indexListSize)
+                .createTable(builder.createTable)
+                .dropTableFirst(builder.dropTableFirst)
+                .skipCreateVectorExtension(builder.skipCreateVectorExtension)
+                .metadataStorageConfig(builder.metadataStorageConfig)
+                .searchMode(builder.searchMode)
+                .textSearchConfig(builder.textSearchConfig)
+                .rrfK(builder.rrfK));
     }
 
     /**
@@ -897,7 +899,8 @@ public PgVectorEmbeddingStore build() {
 
         public String toString() {
             return "PgVectorEmbeddingStore.PgVectorEmbeddingStoreBuilder(host=" + this.host + ", port=" + this.port
-                    + ", user=" + this.user + ", password=" + (this.password == null ? null : "********") + ", database=" + this.database + ", table="
+                    + ", user=" + this.user + ", password=" + (this.password == null ? null : "********")
+                    + ", database=" + this.database + ", table="
                     + this.table + ", dimension=" + this.dimension + ", useIndex=" + this.useIndex + ", indexListSize="
                     + this.indexListSize + ", createTable=" + this.createTable + ", dropTableFirst="
                     + this.dropTableFirst + ", skipCreateVectorExtension=" + this.skipCreateVectorExtension


Test patch:
diff --git a/langchain4j-pgvector/src/test/java/dev/langchain4j/store/embedding/pgvector/PgVectorEmbeddingStoreBuilderTest.java b/langchain4j-pgvector/src/test/java/dev/langchain4j/store/embedding/pgvector/PgVectorEmbeddingStoreBuilderTest.java
new file mode 100644
index 00000000000..07811562383
--- /dev/null
+++ b/langchain4j-pgvector/src/test/java/dev/langchain4j/store/embedding/pgvector/PgVectorEmbeddingStoreBuilderTest.java
@@ -0,0 +1,50 @@
+package dev.langchain4j.store.embedding.pgvector;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.lang.reflect.Field;
+import org.junit.jupiter.api.Test;
+
+class PgVectorEmbeddingStoreBuilderTest {
+
+    @Test
+    void builder_passes_skipCreateVectorExtension_to_the_store() throws Exception {
+        PgVectorEmbeddingStore store = PgVectorEmbeddingStore.builder()
+                .host("localhost")
+                .port(5432)
+                .user("user")
+                .password("password")
+                .database("database")
+                .table("embeddings")
+                .dropTableFirst(false)
+                .createTable(false)
+                .useIndex(false)
+                .skipCreateVectorExtension(true)
+                .build();
+
+        assertThat(skipCreateVectorExtension(store)).isTrue();
+    }
+
+    @Test
+    void builder_defaults_skipCreateVectorExtension_to_false() throws Exception {
+        PgVectorEmbeddingStore store = PgVectorEmbeddingStore.builder()
+                .host("localhost")
+                .port(5432)
+                .user("user")
+                .password("password")
+                .database("database")
+                .table("embeddings")
+                .dropTableFirst(false)
+                .createTable(false)
+                .useIndex(false)
+                .build();
+
+        assertThat(skipCreateVectorExtension(store)).isFalse();
+    }
+
+    private static boolean skipCreateVectorExtension(PgVectorEmbeddingStore store) throws Exception {
+        Field field = PgVectorEmbeddingStore.class.getDeclaredField("skipCreateVectorExtension");
+        field.setAccessible(true);
+        return field.getBoolean(store);
+    }
+}