diff --git a/auto-configurations/vector-stores/spring-ai-autoconfigure-vector-store-neo4j/src/main/java/org/springframework/ai/vectorstore/neo4j/autoconfigure/Neo4jVectorStoreAutoConfiguration.java b/auto-configurations/vector-stores/spring-ai-autoconfigure-vector-store-neo4j/src/main/java/org/springframework/ai/vectorstore/neo4j/autoconfigure/Neo4jVectorStoreAutoConfiguration.java index a01cd031a6d..6c46a0f06db 100644 --- a/auto-configurations/vector-stores/spring-ai-autoconfigure-vector-store-neo4j/src/main/java/org/springframework/ai/vectorstore/neo4j/autoconfigure/Neo4jVectorStoreAutoConfiguration.java +++ b/auto-configurations/vector-stores/spring-ai-autoconfigure-vector-store-neo4j/src/main/java/org/springframework/ai/vectorstore/neo4j/autoconfigure/Neo4jVectorStoreAutoConfiguration.java @@ -75,6 +75,7 @@ public Neo4jVectorStore vectorStore(Driver driver, EmbeddingModel embeddingModel .indexName(properties.getIndexName()) .idProperty(properties.getIdProperty()) .constraintName(properties.getConstraintName()) + .textProperty(properties.getTextProperty()) .build(); } diff --git a/auto-configurations/vector-stores/spring-ai-autoconfigure-vector-store-neo4j/src/main/java/org/springframework/ai/vectorstore/neo4j/autoconfigure/Neo4jVectorStoreProperties.java b/auto-configurations/vector-stores/spring-ai-autoconfigure-vector-store-neo4j/src/main/java/org/springframework/ai/vectorstore/neo4j/autoconfigure/Neo4jVectorStoreProperties.java index cc37bb1acd3..c2cb3748356 100644 --- a/auto-configurations/vector-stores/spring-ai-autoconfigure-vector-store-neo4j/src/main/java/org/springframework/ai/vectorstore/neo4j/autoconfigure/Neo4jVectorStoreProperties.java +++ b/auto-configurations/vector-stores/spring-ai-autoconfigure-vector-store-neo4j/src/main/java/org/springframework/ai/vectorstore/neo4j/autoconfigure/Neo4jVectorStoreProperties.java @@ -47,6 +47,8 @@ public class Neo4jVectorStoreProperties extends CommonVectorStoreProperties { private String constraintName = Neo4jVectorStore.DEFAULT_CONSTRAINT_NAME; + private String textProperty = Neo4jVectorStore.DEFAULT_TEXT_PROPERTY; + public String getDatabaseName() { return this.databaseName; } @@ -111,4 +113,11 @@ public void setConstraintName(String constraintName) { this.constraintName = constraintName; } + public String getTextProperty() { + return this.textProperty; + } + + public void setTextProperty(String textProperty) { + this.textProperty = textProperty; + } } diff --git a/vector-stores/spring-ai-neo4j-store/src/main/java/org/springframework/ai/vectorstore/neo4j/Neo4jVectorStore.java b/vector-stores/spring-ai-neo4j-store/src/main/java/org/springframework/ai/vectorstore/neo4j/Neo4jVectorStore.java index 45dc727e73e..8fe7f5558e0 100644 --- a/vector-stores/spring-ai-neo4j-store/src/main/java/org/springframework/ai/vectorstore/neo4j/Neo4jVectorStore.java +++ b/vector-stores/spring-ai-neo4j-store/src/main/java/org/springframework/ai/vectorstore/neo4j/Neo4jVectorStore.java @@ -148,6 +148,8 @@ public class Neo4jVectorStore extends AbstractObservationVectorStore implements public static final String DEFAULT_ID_PROPERTY = "id"; + public static final String DEFAULT_TEXT_PROPERTY = "text"; + public static final String DEFAULT_CONSTRAINT_NAME = DEFAULT_LABEL + "_unique_idx"; private static final Map<Neo4jDistanceType, VectorStoreSimilarityMetric> SIMILARITY_TYPE_MAPPING = Map.of( @@ -172,6 +174,8 @@ public class Neo4jVectorStore extends AbstractObservationVectorStore implements private final String idProperty; + private final String textProperty; + private final String constraintName; private final Neo4jVectorFilterExpressionConverter filterExpressionConverter = new Neo4jVectorFilterExpressionConverter(); @@ -192,6 +196,7 @@ protected Neo4jVectorStore(Builder builder) { this.indexNameNotSanitized = builder.indexName; this.indexName = SchemaNames.sanitize(builder.indexName, true).orElseThrow(); this.idProperty = SchemaNames.sanitize(builder.idProperty).orElseThrow(); + this.textProperty = SchemaNames.sanitize(builder.textProperty).orElseThrow(); this.constraintName = SchemaNames.sanitize(builder.constraintName).orElseThrow(); this.initializeSchema = builder.initializeSchema; } @@ -323,7 +328,7 @@ private Map<String, Object> documentToRecord(Document document, float[] embeddin row.put("id", document.getId()); var properties = new HashMap<String, Object>(); - properties.put("text", document.getText()); + properties.put(this.textProperty, document.getText()); document.getMetadata().forEach((k, v) -> properties.put("metadata." + k, Values.value(v))); row.put("properties", properties); @@ -345,7 +350,7 @@ private Document recordToDocument(org.neo4j.driver.Record neoRecord) { return Document.builder() .id(node.get(this.idProperty).asString()) - .text(node.get("text").asString()) + .text(node.get(this.textProperty).asString()) .metadata(Map.copyOf(metaData)) .score((double) score) .build(); @@ -411,6 +416,8 @@ public static class Builder extends AbstractVectorStoreBuilder<Builder> { private String idProperty = DEFAULT_ID_PROPERTY; + private String textProperty = DEFAULT_TEXT_PROPERTY; + private String constraintName = DEFAULT_CONSTRAINT_NAME; private boolean initializeSchema = false; @@ -516,6 +523,18 @@ public Builder idProperty(String idProperty) { return this; } + /** + * Sets the property name for text-content. + * @param textProperty the text property to use + * @return the builder instance + */ + public Builder textProperty(String textProperty) { + if (StringUtils.hasText(textProperty)) { + this.textProperty = textProperty; + } + return this; + } + /** * Sets the name of the unique constraint. * @param constraintName the constraint name to use