Skip to content

lightrag-memgraph: get_docs_paginated() unstable pagination (no secondary sort key) #220

Description

@antejavor

What's wrong

MemgraphDocStatusStorage.get_docs_paginated() in integrations/lightrag-memgraph/src/lightrag_memgraph/docstatus_impl.py sorts by a single field with no secondary tiebreaker:

ORDER BY {sort_expr} {order}

The reference JsonDocStatusStorage sorts an in-memory Python list, whose sort is stable and gives deterministic tie-breaking (by insertion order) for free. Memgraph's ORDER BY gives no stability guarantee among tied rows across separate query executions.

LightRAG commonly batch-writes many documents sharing the identical updated_at/created_at timestamp within one ingestion batch. Paging through the same listing (page 1, then page 2) can return the same document twice or silently skip one whenever ties exist — a pagination-correctness regression from the reference semantics. Doesn't show up in the current single-page integration tests, only with real timestamp-colliding data.

Acceptance criteria

  • get_docs_paginated()'s ORDER BY includes a secondary, always-unique tiebreaker (e.g. id)
  • Test with multiple documents sharing the same sort-field value, asserting stable results across two paginated calls

Blocked by

None - can start immediately

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions