Skip to content

fix: add max_items limit to fetch_all_edges to prevent unbounded memory growth #513

@JiayuuWang

Description

@JiayuuWang

Bug

The fetch_all_nodes function has a max_items parameter (default 2000) to prevent fetching too many items, but fetch_all_edges was missing this safeguard. This could cause memory issues with graphs that have a large number of edges.

Proposed Fix

Add _MAX_EDGES = 5000 as the default limit for edges, matching the pattern already established for nodes.

File

  • backend/app/utils/zep_paging.py

Code Change

# Add constant
_MAX_EDGES = 5000

# Update function signature
def fetch_all_edges(
    client: Zep,
    graph_id: str,
    page_size: int = _DEFAULT_PAGE_SIZE,
    max_items: int = _MAX_EDGES,  # Add this parameter
    ...
):
    # Add check in the loop
    if len(all_edges) >= max_items:
        all_edges = all_edges[:max_items]
        logger.warning(f"Edge count reached limit ({max_items}), stopping pagination...")
        break

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions