Skip to content

"not in" filtering is not working. #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bldev2473 opened this issue Apr 14, 2025 · 2 comments
Closed

"not in" filtering is not working. #326

bldev2473 opened this issue Apr 14, 2025 · 2 comments

Comments

@bldev2473
Copy link

bldev2473 commented Apr 14, 2025

Hi, I'd like to use the pre-filtering feature. I'm using VectorRetriever.
pre-filters

But following error occurred.

neo4j.exceptions.CypherSyntaxError: {code: Neo.ClientError.Statement.SyntaxError} {message: Invalid input 'NOT': expected an expression or ')' (line 1, column 131 (offset: 130))
"MATCH (node:`Chunk`) WHERE node.`embedding` IS NOT NULL AND size(node.`embedding`) = toInteger($embedding_dimension) AND (node.id NOT IN $param_0) WITH node, vector.similarity.cosine(node.`embedding`, $query_vector) AS score ORDER BY score DESC LIMIT $top_k RETURN node {.id, .text, .content_id} AS node, labels(node) AS nodeLabels, elementId(node) AS elementId, elementId(node) AS id, score"

My implementation is:

filters ={
    "id": {
        "$nin": docIds # list of strings
    }
retriever_result = retriever.search(query_text=query_text, filters=filters)

I think WHERE NOT thing IN list not WHERE thing NOT IN list is the correct syntax.
It seems that the current version of _single_condition_cypher() function in filters.py can't handle this.

def _single_condition_cypher(
    field: str,
    native_operator_class: Type[Operator],
    value: Any,
    param_store: ParameterStore,
    node_alias: str = DEFAULT_NODE_ALIAS,
) -> str:
    native_op = native_operator_class(node_alias=node_alias)
    param_name = param_store.add(native_op.cleaned_value(value))
    query_snippet = f"{native_op.lhs(field)} {native_op.CYPHER_OPERATOR} ${param_name}"
    return query_snippet
@stellasia stellasia mentioned this issue Apr 14, 2025
15 tasks
@stellasia
Copy link
Contributor

Hi @bldev2473 ,

Thank you for raising this issue. A fix has just been merged and will be part of the next release.

@stellasia
Copy link
Contributor

stellasia commented Apr 29, 2025

1.7.0 has just been released, with the fix, so closing this issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants