-
Notifications
You must be signed in to change notification settings - Fork 9.3k
feat(graphrag): fix merge concurrency and add resume-from-checkpoint #14238
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
Merged
wangq8
merged 9 commits into
infiniflow:main
from
prpercival:feat/graphrag-resume-checkpoint
May 6, 2026
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
afca146
feat(graphrag): fix merge concurrency and add resume-from-checkpoint
prpercival 33004a8
fix(graphrag): preserve neighbor merges, log unbind path, assert phas…
prpercival 7993f1c
Merge branch 'main' into feat/graphrag-resume-checkpoint
prpercival daf46c6
Merge branch 'main' into feat/graphrag-resume-checkpoint
prpercival 94db318
Merge branch 'main' into feat/graphrag-resume-checkpoint
prpercival 1889930
feat(graphrag): restore wipe=false on new REST delete route + bulk in…
prpercival bb10a44
Remove unused import
prpercival faac64a
fix(web): normalize chunk_count/document_count -> chunk_num/doc_num i…
prpercival 797fa53
Merge remote-tracking branch 'origin/main' into feat/graphrag-resume-…
prpercival File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # | ||
| # Copyright 2025 The InfiniFlow Authors. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| """GraphRAG phase-completion markers. | ||
|
|
||
| Markers let a re-run of GraphRAG skip phases that already completed in a | ||
| prior (possibly cancelled or crashed) task on the same KB. | ||
|
|
||
| Markers are stored in Redis under ``graphrag:phase:{kb_id}:{phase}`` with a | ||
| 7-day TTL. They are intentionally KB-scoped (not task-scoped) so they | ||
| survive task cancellation and the creation of a new task on resume. | ||
|
|
||
| Invalidation rules (callers responsibility): | ||
| * ``clear_phase_markers`` is invoked by ``run_graphrag_for_kb`` whenever new | ||
| document content is merged into the global graph -- the merged graph has | ||
| changed, so prior resolution and community results are stale. | ||
| * ``clear_phase_markers`` is invoked by the unbind-task endpoint when the | ||
| caller asks to wipe the graph. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
|
|
||
| from rag.utils.redis_conn import REDIS_CONN | ||
|
|
||
|
|
||
| PHASE_RESOLUTION = "resolution_done" | ||
| PHASE_COMMUNITY = "community_done" | ||
|
|
||
| ALL_PHASES = (PHASE_RESOLUTION, PHASE_COMMUNITY) | ||
|
|
||
| # 7 days is well above any expected single GraphRAG run on typical hardware | ||
| # and keeps stale markers self-pruning if invalidation paths are missed. | ||
| _DEFAULT_TTL_SECONDS = 7 * 24 * 3600 | ||
|
|
||
|
|
||
| def _phase_key(kb_id: str, phase: str) -> str: | ||
| return f"graphrag:phase:{kb_id}:{phase}" | ||
|
|
||
|
|
||
| def has_phase_marker(kb_id: str, phase: str) -> bool: | ||
| """Return True iff the marker for (kb_id, phase) exists.""" | ||
| if not kb_id or not phase: | ||
| return False | ||
| try: | ||
| return bool(REDIS_CONN.exist(_phase_key(kb_id, phase))) | ||
| except Exception: | ||
| # Markers are an optimization; a Redis miss must NEVER block a run. | ||
| logging.exception("has_phase_marker(%s, %s) failed", kb_id, phase) | ||
| return False | ||
|
|
||
|
|
||
| def set_phase_marker(kb_id: str, phase: str, ttl: int = _DEFAULT_TTL_SECONDS) -> bool: | ||
| """Persist a marker indicating the named phase has completed for kb_id.""" | ||
| if not kb_id or not phase: | ||
| return False | ||
| try: | ||
| return bool(REDIS_CONN.set(_phase_key(kb_id, phase), "1", ttl)) | ||
| except Exception: | ||
| logging.exception("set_phase_marker(%s, %s) failed", kb_id, phase) | ||
| return False | ||
|
|
||
|
|
||
| def clear_phase_markers(kb_id: str, phases: tuple[str, ...] = ALL_PHASES) -> None: | ||
| """Drop the named phase markers for kb_id (no-op on miss).""" | ||
| if not kb_id: | ||
| return | ||
| for phase in phases: | ||
| try: | ||
| REDIS_CONN.delete(_phase_key(kb_id, phase)) | ||
| except Exception: | ||
| logging.exception("clear_phase_markers(%s, %s) failed", kb_id, phase) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.