Skip to content

Commit 54f49b5

Browse files
committed
Fix PgVectorAutoconfiguration to use PgIDType
1 parent 4dbe734 commit 54f49b5

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/pgvector/PgVectorStoreAutoConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public PgVectorStore vectorStore(JdbcTemplate jdbcTemplate, EmbeddingModel embed
6464

6565
return PgVectorStore.builder(jdbcTemplate, embeddingModel)
6666
.schemaName(properties.getSchemaName())
67+
.idType(properties.getIdType())
6768
.vectorTableName(properties.getTableName())
6869
.vectorTableValidationsEnabled(properties.isSchemaValidation())
6970
.dimensions(properties.getDimensions())

spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vectorstore/pgvector/PgVectorStoreProperties.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class PgVectorStoreProperties extends CommonVectorStoreProperties {
4747

4848
private String schemaName = PgVectorStore.DEFAULT_SCHEMA_NAME;
4949

50+
private PgVectorStore.PgIdType idType = PgVectorStore.PgIdType.UUID;
51+
5052
private boolean schemaValidation = PgVectorStore.DEFAULT_SCHEMA_VALIDATION;
5153

5254
private int maxDocumentBatchSize = PgVectorStore.MAX_DOCUMENT_BATCH_SIZE;
@@ -99,6 +101,14 @@ public void setSchemaName(String schemaName) {
99101
this.schemaName = schemaName;
100102
}
101103

104+
public PgVectorStore.PgIdType getIdType() {
105+
return idType;
106+
}
107+
108+
public void setIdType(PgVectorStore.PgIdType idType) {
109+
this.idType = idType;
110+
}
111+
102112
public boolean isSchemaValidation() {
103113
return this.schemaValidation;
104114
}

vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorStore.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,6 @@ private String toJson(Map<String, Object> map) {
309309
}
310310

311311
private Object convertIdToPgType(String id) {
312-
if (this.initializeSchema) {
313-
return UUID.fromString(id);
314-
}
315-
316312
return switch (getIdType()) {
317313
case UUID -> UUID.fromString(id);
318314
case TEXT -> id;
@@ -534,6 +530,9 @@ public enum PgIndexType {
534530

535531
}
536532

533+
/**
534+
* The ID type for the Pg vector store schema. Defaults to UUID.
535+
*/
537536
public enum PgIdType {
538537

539538
UUID, TEXT, INTEGER, SERIAL, BIGSERIAL

0 commit comments

Comments
 (0)