Skip to content

[BUG] Empty group_id not handled consistently in full-text and similarity search #810

@galshubeli

Description

@galshubeli

Bug Description

When searching without specifying a group_id, the current implementation behaves inconsistently between full-text search and similarity search due to different filtering logic:

  • Full-text search: Applies a WHERE clause using $group_ids, even when it is None, which results in no matches returned.
WHERE e.group_id IN $group_ids
  • Similarity search: Does not filter by group_id when group_ids is None, and instead defaults to extracting relationships across all groups:
WHERE e.group_id IS NOT NULL

Full-text:

    query = (
        get_relationships_query('edge_name_and_fact', provider=driver.provider)
        + """
        YIELD relationship AS rel, score
        MATCH (n:Entity)-[e:RELATES_TO {uuid: rel.uuid}]->(m:Entity)
        WHERE e.group_id IN $group_ids """
        + filter_query
        + """
        WITH e, score, n, m
        RETURN
        """
        + ENTITY_EDGE_RETURN
        + """
        ORDER BY score DESC
        LIMIT $limit
        """
    )

Similarity:

    group_filter_query: LiteralString = 'WHERE e.group_id IS NOT NULL'
    if group_ids is not None:
        group_filter_query += '\nAND e.group_id IN $group_ids'
        query_params['group_ids'] = group_ids

        if source_node_uuid is not None:
            query_params['source_uuid'] = source_node_uuid
            group_filter_query += '\nAND (n.uuid = $source_uuid)'

        if target_node_uuid is not None:
            query_params['target_uuid'] = target_node_uuid
            group_filter_query += '\nAND (m.uuid = $target_uuid)'

    query = (
        RUNTIME_QUERY
        + """
        MATCH (n:Entity)-[e:RELATES_TO]->(m:Entity)
        """
        + group_filter_query
        + filter_query
        + """
        WITH DISTINCT e, n, m, """
        + get_vector_cosine_func_query('e.fact_embedding', '$search_vector', driver.provider)
        + """ AS score
        WHERE score > $min_score
        RETURN
        """
        + ENTITY_EDGE_RETURN
        + """
        ORDER BY score DESC
        LIMIT $limit
        """
    )

Steps to Reproduce

Run the quick-start examples (Falkordb/Neo4j)

Expected Behavior

Consistent group_id filtering

Actual Behavior

Inconsistent group_id filtering

Environment

  • Graphiti Version: [0.18.2]
  • Python Version: [3.12]
  • Operating System: [Ubuntu 22.04]
  • Database Backend: [Neo4j 5.26, FalkorDB 1.1.2]
  • LLM Provider & Model: [OpenAI gpt-4.1]

Installation Method

  • pip install
  • uv add
  • Development installation (git clone)

Error Messages/Traceback

Paste the full error message and traceback here

Configuration

# Relevant configuration or initialization code

Additional Context

  • Does this happen consistently or intermittently?
  • Which component are you using? (core library, REST server, MCP server)
  • Any recent changes to your environment?
  • Related issues or similar problems you've encountered?

Possible Solution

If you have ideas about what might be causing the issue or how to fix it, please share them here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions