Skip to content

Commit 972eb49

Browse files
Temuu-jinilayaperumalg
authored andcommitted
Add custom text-property and set default to previously used "text"
Add property to auto config and properties class Signed-off-by: Temucin Damdinjamts-Kintaert <[email protected]>
1 parent 1c06d7c commit 972eb49

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

auto-configurations/vector-stores/spring-ai-autoconfigure-vector-store-neo4j/src/main/java/org/springframework/ai/vectorstore/neo4j/autoconfigure/Neo4jVectorStoreAutoConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public Neo4jVectorStore vectorStore(Driver driver, EmbeddingModel embeddingModel
7575
.indexName(properties.getIndexName())
7676
.idProperty(properties.getIdProperty())
7777
.constraintName(properties.getConstraintName())
78+
.textProperty(properties.getTextProperty())
7879
.build();
7980
}
8081

auto-configurations/vector-stores/spring-ai-autoconfigure-vector-store-neo4j/src/main/java/org/springframework/ai/vectorstore/neo4j/autoconfigure/Neo4jVectorStoreProperties.java

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

4848
private String constraintName = Neo4jVectorStore.DEFAULT_CONSTRAINT_NAME;
4949

50+
private String textProperty = Neo4jVectorStore.DEFAULT_TEXT_PROPERTY;
51+
5052
public String getDatabaseName() {
5153
return this.databaseName;
5254
}
@@ -111,4 +113,12 @@ public void setConstraintName(String constraintName) {
111113
this.constraintName = constraintName;
112114
}
113115

116+
public String getTextProperty() {
117+
return this.textProperty;
118+
}
119+
120+
public void setTextProperty(String textProperty) {
121+
this.textProperty = textProperty;
122+
}
123+
114124
}

vector-stores/spring-ai-neo4j-store/src/main/java/org/springframework/ai/vectorstore/neo4j/Neo4jVectorStore.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ public class Neo4jVectorStore extends AbstractObservationVectorStore implements
148148

149149
public static final String DEFAULT_ID_PROPERTY = "id";
150150

151+
public static final String DEFAULT_TEXT_PROPERTY = "text";
152+
151153
public static final String DEFAULT_CONSTRAINT_NAME = DEFAULT_LABEL + "_unique_idx";
152154

153155
private static final Map<Neo4jDistanceType, VectorStoreSimilarityMetric> SIMILARITY_TYPE_MAPPING = Map.of(
@@ -172,6 +174,8 @@ public class Neo4jVectorStore extends AbstractObservationVectorStore implements
172174

173175
private final String idProperty;
174176

177+
private final String textProperty;
178+
175179
private final String constraintName;
176180

177181
private final Neo4jVectorFilterExpressionConverter filterExpressionConverter = new Neo4jVectorFilterExpressionConverter();
@@ -192,6 +196,7 @@ protected Neo4jVectorStore(Builder builder) {
192196
this.indexNameNotSanitized = builder.indexName;
193197
this.indexName = SchemaNames.sanitize(builder.indexName, true).orElseThrow();
194198
this.idProperty = SchemaNames.sanitize(builder.idProperty).orElseThrow();
199+
this.textProperty = SchemaNames.sanitize(builder.textProperty).orElseThrow();
195200
this.constraintName = SchemaNames.sanitize(builder.constraintName).orElseThrow();
196201
this.initializeSchema = builder.initializeSchema;
197202
}
@@ -323,7 +328,7 @@ private Map<String, Object> documentToRecord(Document document, float[] embeddin
323328
row.put("id", document.getId());
324329

325330
var properties = new HashMap<String, Object>();
326-
properties.put("text", document.getText());
331+
properties.put(this.textProperty, document.getText());
327332

328333
document.getMetadata().forEach((k, v) -> properties.put("metadata." + k, Values.value(v)));
329334
row.put("properties", properties);
@@ -345,7 +350,7 @@ private Document recordToDocument(org.neo4j.driver.Record neoRecord) {
345350

346351
return Document.builder()
347352
.id(node.get(this.idProperty).asString())
348-
.text(node.get("text").asString())
353+
.text(node.get(this.textProperty).asString())
349354
.metadata(Map.copyOf(metaData))
350355
.score((double) score)
351356
.build();
@@ -411,6 +416,8 @@ public static class Builder extends AbstractVectorStoreBuilder<Builder> {
411416

412417
private String idProperty = DEFAULT_ID_PROPERTY;
413418

419+
private String textProperty = DEFAULT_TEXT_PROPERTY;
420+
414421
private String constraintName = DEFAULT_CONSTRAINT_NAME;
415422

416423
private boolean initializeSchema = false;
@@ -516,6 +523,18 @@ public Builder idProperty(String idProperty) {
516523
return this;
517524
}
518525

526+
/**
527+
* Sets the property name for text-content.
528+
* @param textProperty the text property to use
529+
* @return the builder instance
530+
*/
531+
public Builder textProperty(String textProperty) {
532+
if (StringUtils.hasText(textProperty)) {
533+
this.textProperty = textProperty;
534+
}
535+
return this;
536+
}
537+
519538
/**
520539
* Sets the name of the unique constraint.
521540
* @param constraintName the constraint name to use

0 commit comments

Comments
 (0)