Skip to content

[Feature Request]: Post-insert callback / hook support #2744

@tavurth

Description

@tavurth

Do you need to file a feature request?

  • I have searched the existing feature request and this feature request is not already filed.
  • I believe this is a legitimate feature request, not just a question or bug.

Feature Request Description

What problem does this solve?
There's currently no way to register a callback that fires after all documents finish processing. The only option is to await immediately after ainsert / apipeline_process_enqueue_documents at the call site, which doesn't work well for server contexts (e.g. document_routes.py) or out-of-process consumers.

Proposed API

async def on_documents_processed(results: list[DocProcessingStatus]) -> None:
    # triggered once all enqueued docs reach PROCESSED or FAILED
    ...

rag = LightRAG(
    ...
    on_insert_complete=on_documents_processed,
)

Or alternatively, accept it as a parameter on apipeline_process_enqueue_documents itself:

await rag.apipeline_process_enqueue_documents(
    on_complete=on_documents_processed
)

Why not just await?
Awaiting works fine for direct library use, but the server's pipeline_index_file fires processing as a background task — there's no clean external hook point without patching the router or monkey-patching the rag instance.

Alternatives considered

  • Polling doc_status storage — works but is wasteful
  • Monkey-patching rag.apipeline_process_enqueue_documents — fragile across version updates

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions