Repository navigation
fix(infinity): declare extra field + serialize dict on write to unbreak RAPTOR - #14998
Conversation
…for RAPTOR builds The Infinity backend's RAPTOR support was broken since v0.25.2 introduced the 'extra' field in code (task_executor.py:1011) without adding it to conf/infinity_mapping.json. The migration in _migrate_db() reads from the mapping file to add new columns to existing tables — since 'extra' was never declared there, the column was never created, and every RAPTOR build that calls search_fields([..., 'extra'], ...) fails with: InfinityException: (3013, 'Fail to bind the expression: extra') Symptoms: - Running RAPTOR on any dataset on the Infinity backend fails immediately - The error surfaces inside get_raptor_chunk_methods() in task_executor.py - Affects v0.25.2, v0.25.3, v0.25.4, and current main Fix (two parts): 1. conf/infinity_mapping.json — declare 'extra' as varchar so _migrate_db() automatically adds the column to existing tables on next RAGFlow start (no manual DB migration needed for upgrading installations). 2. rag/utils/infinity_conn.py insert() — serialize 'extra' dict to JSON string before write. Modelled on the existing 'chunk_data' handling right above. The read path (raptor_utils._as_extra_dict) already accepts both dict and JSON string, so no read-side change needed. Other backends are unaffected: OceanBase has 'extra' as a JSON column (rag/utils/ob_conn.py:95), and ES/OpenSearch handle dicts natively.
📝 WalkthroughWalkthroughThis PR adds missing ChangesRAPTOR Extra Field for Infinity Backend
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
🧹 Nitpick comments (2)
rag/utils/infinity_conn.py (2)
441-450: ⚡ Quick winConsider adding logging for the new
extrafield serialization flow.The new
extrafield handling introduces a new code path that serializes dict values to JSON. Adding a debug log would aid troubleshooting and align with the existingchunk_datalogging pattern (line 370).As per coding guidelines, "Add logging for new flows" for Python files.
📝 Suggested logging addition
elif k == "extra": # RAPTOR writes {"raptor_method": ...} as a dict; Infinity's # `extra` column is varchar so we serialize on the write path. # The read path (raptor_utils._as_extra_dict) already accepts # both dict and JSON-string. Other backends (OceanBase JSON # column, ES/OpenSearch) keep dict shape — this is Infinity-only. if isinstance(v, dict): d[k] = json.dumps(v) + self.logger.debug(f"Serialized extra field to JSON for Infinity: {d[k][:100]}...") else: d[k] = v if v else ""🤖 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/utils/infinity_conn.py` around lines 441 - 450, Add a debug log for the new Infinity-specific `extra` serialization path so developers can see when dicts are being JSON-serialized and when falsy values are coerced to empty strings; inside the `elif k == "extra":` branch (variables k, v, d), log at debug level before assigning to d[k] indicating whether v is a dict (and being json.dumps'd) or is falsy and being set to "", and include a small snippet of the value or its type in the message to aid troubleshooting while avoiding sensitive data.
441-450: Confirm the inconsistency inextrafield handling betweeninsert()andupdate()methods.The
insert()method serializesextrafield dict values to JSON strings (lines 441-450), but theupdate()method (lines 491-618) lacks equivalent handling—dict values would pass through unchanged at line 96's default case. While the current codebase does not passextrafield dicts toupdate()(only pagerank updates are found), this inconsistency should be addressed for defensive consistency: either add JSON serialization to theupdate()path or add a comment documenting why it's safe to omit when handling Infinity's varchar column.🤖 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/utils/infinity_conn.py` around lines 441 - 450, The insert() path currently serializes dict values for the "extra" key to JSON (see the block handling k == "extra" where dict -> json.dumps(v)), but update() does not; fix update() (the update() method handling the update payload where keys/values are normalized) to perform the same serialization for the "extra" key (i.e., if key == "extra" and value is a dict, replace with json.dumps(value); otherwise keep existing empty-string fallback), or if you prefer to leave update() unchanged add a clear comment in update() referencing insert() and raptor_utils._as_extra_dict explaining why dicts will never reach update() for Infinity varchar columns. Ensure you modify the code paths in update() that build the d/normalized payload to mirror insert()’s handling so behavior is consistent.
🤖 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.
Nitpick comments:
In `@rag/utils/infinity_conn.py`:
- Around line 441-450: Add a debug log for the new Infinity-specific `extra`
serialization path so developers can see when dicts are being JSON-serialized
and when falsy values are coerced to empty strings; inside the `elif k ==
"extra":` branch (variables k, v, d), log at debug level before assigning to
d[k] indicating whether v is a dict (and being json.dumps'd) or is falsy and
being set to "", and include a small snippet of the value or its type in the
message to aid troubleshooting while avoiding sensitive data.
- Around line 441-450: The insert() path currently serializes dict values for
the "extra" key to JSON (see the block handling k == "extra" where dict ->
json.dumps(v)), but update() does not; fix update() (the update() method
handling the update payload where keys/values are normalized) to perform the
same serialization for the "extra" key (i.e., if key == "extra" and value is a
dict, replace with json.dumps(value); otherwise keep existing empty-string
fallback), or if you prefer to leave update() unchanged add a clear comment in
update() referencing insert() and raptor_utils._as_extra_dict explaining why
dicts will never reach update() for Infinity varchar columns. Ensure you modify
the code paths in update() that build the d/normalized payload to mirror
insert()’s handling so behavior is consistent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 28c8e7c7-c8b7-4bbc-945c-e9d0595a47be
📒 Files selected for processing (2)
conf/infinity_mapping.jsonrag/utils/infinity_conn.py
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14998 +/- ##
=======================================
Coverage 93.12% 93.12%
=======================================
Files 10 10
Lines 713 713
Branches 116 116
=======================================
Hits 664 664
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…reak RAPTOR (#14998) ### What problem does this PR solve? Fixes #14997. RAPTOR builds on the Infinity backend have been broken since v0.25.2 introduced the `extra` field in code (`rag/svr/task_executor.py:1011`) without declaring it in `conf/infinity_mapping.json`. Every RAPTOR job fails with: ``` infinity.common.InfinityException: (3013, 'Fail to bind the expression: extra@src/planner/expression_binder_impl.cpp:99') ``` The auto-migration in `common/doc_store/infinity_conn_base.py:_migrate_db()` adds any columns it finds in the mapping JSON to existing tables — so the only thing standing between users and a working RAPTOR build is that one missing declaration. OceanBase, ES, and OpenSearch were unaffected because they store `extra` as a native JSON type; only Infinity (which has a strict `varchar`/`integer`/`float` schema) needed the addition. ### The fix Two-part change: 1. **`conf/infinity_mapping.json`**: declare `"extra": {"type": "varchar", "default": ""}`. On next startup, `_migrate_db()` adds the column to all existing chunk tables — no manual DDL needed for upgrading installations. 2. **`rag/utils/infinity_conn.py` `insert()`**: serialize the `extra` dict to a JSON string at write time, since Infinity's `varchar` can't store a Python dict directly. Modelled on the existing `chunk_data` handling a few lines above. The read path (`rag/utils/raptor_utils.py:_as_extra_dict`) already normalises both dict and JSON-string inputs, so no read-side change is needed. Other backends are untouched — `task_executor.py` still writes the dict, and the OceanBase/ES/OpenSearch insert paths handle dicts natively. ### Verification Tested on a v0.25.4 deployment with the Infinity backend by applying the same two changes via mounted-volume override: - Confirmed `_migrate_db()` adds the `extra` column to all pre-existing chunk tables on startup (column visible via Infinity's `show_columns()`). - Triggered RAPTOR builds on four datasets (~21k chunks total) via `POST /api/v1/datasets/<id>/index?type=raptor`. - All four progressed past the previously-failing `get_raptor_chunk_methods()` call into actual entity-extraction and clustering work without the (3013) error. - GraphRAG builds (which can trigger the same path indirectly via `task_executor.py:857`) also progressed cleanly. ### Type of change - [X] Bug Fix (non-breaking change which fixes an issue)
What problem does this PR solve?
Fixes #14997.
RAPTOR builds on the Infinity backend have been broken since v0.25.2 introduced the
extrafield in code (rag/svr/task_executor.py:1011) without declaring it inconf/infinity_mapping.json. Every RAPTOR job fails with:The auto-migration in
common/doc_store/infinity_conn_base.py:_migrate_db()adds any columns it finds in the mapping JSON to existing tables — so the only thing standing between users and a working RAPTOR build is that one missing declaration. OceanBase, ES, and OpenSearch were unaffected because they storeextraas a native JSON type; only Infinity (which has a strictvarchar/integer/floatschema) needed the addition.The fix
Two-part change:
conf/infinity_mapping.json: declare"extra": {"type": "varchar", "default": ""}. On next startup,_migrate_db()adds the column to all existing chunk tables — no manual DDL needed for upgrading installations.rag/utils/infinity_conn.pyinsert(): serialize theextradict to a JSON string at write time, since Infinity'svarcharcan't store a Python dict directly. Modelled on the existingchunk_datahandling a few lines above.The read path (
rag/utils/raptor_utils.py:_as_extra_dict) already normalises both dict and JSON-string inputs, so no read-side change is needed. Other backends are untouched —task_executor.pystill writes the dict, and the OceanBase/ES/OpenSearch insert paths handle dicts natively.Verification
Tested on a v0.25.4 deployment with the Infinity backend by applying the same two changes via mounted-volume override:
_migrate_db()adds theextracolumn to all pre-existing chunk tables on startup (column visible via Infinity'sshow_columns()).POST /api/v1/datasets/<id>/index?type=raptor.get_raptor_chunk_methods()call into actual entity-extraction and clustering work without the (3013) error.task_executor.py:857) also progressed cleanly.Type of change