Repository navigation
Refactor: enhance graphrag - part 2 - #14972
Conversation
📝 WalkthroughWalkthroughThis PR adds a configurable GraphRAG parameter ChangesGraphRAG Batch Chunk Token Size Configuration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
rag/nlp/search.py (1)
647-661: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick winAdd a log when
retrieve_all=Truepath is used.The new unbounded pagination flow has no trace point, which makes production diagnosis harder for large documents.
Suggested patch
p = offset + if retrieve_all: + logging.debug("chunk_list retrieve_all enabled for doc_id=%s, tenant_id=%s, kb_ids=%s", doc_id, tenant_id, kb_ids) while retrieve_all or p < max_count:As per coding guidelines,
**/*.py: Add logging for new flows.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rag/nlp/search.py` around lines 647 - 661, Add a log entry whenever the unbounded pagination path is taken (when retrieve_all is True) so production traces show the large-doc flow; inside the loop in rag/nlp/search.py (the block using variables retrieve_all, p, max_count, bs and calling self.dataStore.search/self.dataStore.get_fields) emit an info/debug log at the start of the iteration indicating that unbounded retrieval is active and include contextual identifiers (tenant_id, kb_ids), current page offset p and batch size limit (bs), and optionally a cumulative count or marker so operators can trace progress.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rag/graphrag/general/index.py`:
- Around line 60-70: The helper _positive_int_config currently accepts any
positive integer; change it to enforce the API bounds 512–8196 by
validating/clamping the parsed value to that range (e.g., if parsed value < 512
or > 8196, log a warning and return the default or clamp to the nearest bound),
and apply the same bounded validation wherever this helper is used (refer to
_positive_int_config and the call sites around the previous lines 157–159) so
persisted/manual configs cannot pass out-of-contract values that break batching.
- Around line 292-294: The early-return returns failed_docs as list[str] causing
inconsistency; change the return so failed_docs is a list[tuple[str,str]] to
match other exits. In the block that checks total_chunks == 0 and not subgraphs,
transform doc_ids into tuples (doc_id, "<reason>") — e.g. (doc_id,
"no_available_chunks") — and return {"ok_docs": [], "failed_docs":
failed_tuples, "total_docs": len(doc_ids), "total_chunks": 0, "seconds": 0.0};
reference variables/functions: total_chunks, subgraphs, callback, kb_id,
doc_ids.
In `@web/src/pages/dataset/dataset-setting/form-schema.ts`:
- Around line 73-78: The zod schema for batch_chunk_token_size currently allows
values below the backend's allowed range; update the validator for the
batch_chunk_token_size field to enforce the backend contract by adding a minimum
of 512 (e.g., replace/augment .positive() with .min(512)) while keeping the
existing .max(8196) and .int() constraints so client-side validation matches the
GraphRAG range 512..8196.
---
Outside diff comments:
In `@rag/nlp/search.py`:
- Around line 647-661: Add a log entry whenever the unbounded pagination path is
taken (when retrieve_all is True) so production traces show the large-doc flow;
inside the loop in rag/nlp/search.py (the block using variables retrieve_all, p,
max_count, bs and calling self.dataStore.search/self.dataStore.get_fields) emit
an info/debug log at the start of the iteration indicating that unbounded
retrieval is active and include contextual identifiers (tenant_id, kb_ids),
current page offset p and batch size limit (bs), and optionally a cumulative
count or marker so operators can trace progress.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f94b65ce-2308-4f03-8a69-4a98a194eac4
📒 Files selected for processing (12)
api/utils/api_utils.pyapi/utils/validation_utils.pyrag/graphrag/general/index.pyrag/nlp/search.pyrag/svr/task_executor.pyweb/src/components/parse-configuration/graph-rag-form-fields.tsxweb/src/interfaces/database/dataset.tsweb/src/interfaces/database/document.tsweb/src/locales/en.tsweb/src/locales/zh.tsweb/src/pages/dataset/dataset-setting/form-schema.tsweb/src/pages/dataset/dataset-setting/index.tsx
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14972 +/- ##
=======================================
Coverage 94.16% 94.16%
=======================================
Files 10 10
Lines 703 703
Branches 112 112
=======================================
Hits 662 662
Misses 25 25
Partials 16 16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
Type of change
Follow on: #14617