Use <> for inequality operator in Neo4j filter expression implementation

This commit is contained in:
Dimitrios Begnis
2024-05-20 23:56:41 +02:00
committed by Mark Pollack
parent 8389913999
commit bce45c2d2f
2 changed files with 5 additions and 3 deletions

View File

@@ -24,6 +24,7 @@ import org.springframework.ai.vectorstore.filter.converter.AbstractFilterExpress
* Converts {@link Expression} into Neo4j condition expression format.
*
* @author Gerrit Meier
* @author Dimitrios Begnis
*/
public class Neo4jVectorFilterExpressionConverter extends AbstractFilterExpressionConverter {
@@ -46,7 +47,7 @@ public class Neo4jVectorFilterExpressionConverter extends AbstractFilterExpressi
case AND -> " AND ";
case OR -> " OR ";
case EQ -> " = ";
case NE -> " != ";
case NE -> " <> ";
case LT -> " < ";
case LTE -> " <= ";
case GT -> " > ";

View File

@@ -37,6 +37,7 @@ import static org.springframework.ai.vectorstore.filter.Filter.ExpressionType.OR
/**
* @author Gerrit Meier
* @author Dimitrios Begnis
*/
public class Neo4jVectorFilterExpressionConverterTests {
@@ -76,13 +77,13 @@ public class Neo4jVectorFilterExpressionConverterTests {
@Test
public void testNe() {
// year >= 2020 OR country = "BG" AND city != "Sofia"
// year >= 2020 OR country = "BG" AND city <> "Sofia"
String vectorExpr = converter
.convertExpression(new Expression(OR, new Expression(GTE, new Key("year"), new Value(2020)),
new Expression(AND, new Expression(EQ, new Key("country"), new Value("BG")),
new Expression(NE, new Key("city"), new Value("Sofia")))));
assertThat(vectorExpr).isEqualTo(
"node.`metadata.year` >= 2020 OR node.`metadata.country` = \"BG\" AND node.`metadata.city` != \"Sofia\"");
"node.`metadata.year` >= 2020 OR node.`metadata.country` = \"BG\" AND node.`metadata.city` <> \"Sofia\"");
}
@Test