Fix Cypher syntax for vector property in Neo4jVectorStore

- Fix parameter access syntax in setNodeVectorProperty DDL statement
- Define DEFAULT_TRANSACTION_SIZE for the hardcoded batch size in
the delete query

Fixes #1623

Signed-off-by: jitokim <pigberger70@gmail.com>
This commit is contained in:
jitokim
2024-10-31 06:36:44 +09:00
committed by Mark Pollack
parent f6a648e85c
commit 1cdec7b6c3

View File

@@ -48,11 +48,14 @@ import org.springframework.util.Assert;
* @author Christian Tzolov
* @author Thomas Vitale
* @author Soby Chacko
* @author Jihoon Kim
*/
public class Neo4jVectorStore extends AbstractObservationVectorStore implements InitializingBean {
public static final int DEFAULT_EMBEDDING_DIMENSION = 1536;
public static final int DEFAULT_TRANSACTION_SIZE = 10_000;
public static final String DEFAULT_LABEL = "Document";
public static final String DEFAULT_INDEX_NAME = "spring-ai-document-index";
@@ -117,7 +120,7 @@ public class Neo4jVectorStore extends AbstractObservationVectorStore implements
SET u.%2$s = row.id,
u += row.properties
WITH row, u
CALL db.create.setNodeVectorProperty(u, $embeddingProperty, row.embedding)
CALL db.create.setNodeVectorProperty(u, $embeddingProperty, row[$embeddingProperty])
""".formatted(this.config.label, this.config.idProperty);
session.executeWrite(
tx -> tx.run(statement, Map.of("rows", rows, "embeddingProperty", this.config.embeddingProperty))
@@ -137,7 +140,7 @@ public class Neo4jVectorStore extends AbstractObservationVectorStore implements
MATCH (n:%s) WHERE n.%s IN $ids
CALL { WITH n DETACH DELETE n } IN TRANSACTIONS OF $transactionSize ROWS
""".formatted(this.config.label, this.config.idProperty),
Map.of("ids", idList, "transactionSize", 10_000))
Map.of("ids", idList, "transactionSize", DEFAULT_TRANSACTION_SIZE))
.consume();
return Optional.of(idList.size() == summary.counters().nodesDeleted());
}