Skip to content

fix(infinity): declare extra field + serialize dict on write to unbreak RAPTOR - #14998

Merged
yingfeng merged 1 commit into
infiniflow:mainfrom
prateekjain:fix/infinity-raptor-extra-field
May 19, 2026
Merged

yingfeng merged 1 commit into
infiniflow:mainfrom
prateekjain:fix/infinity-raptor-extra-field

Conversation

@prateekjain

@prateekjain prateekjain commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Bug Fix (non-breaking change which fixes an issue)

…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.
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 19, 2026
@coderabbitai

coderabbitai Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds missing extra field support to the Infinity backend to fix RAPTOR build failures. The schema is extended with a varchar extra column, and the insert method now JSON-serializes dict values for storage, matching the dict-native storage available on OceanBase.

Changes

RAPTOR Extra Field for Infinity Backend

Layer / File(s) Summary
Infinity schema declaration for extra field
conf/infinity_mapping.json
Add extra property as varchar with empty-string default to the Infinity mapping schema, parallel to the existing raptor_layer_int field. The auto-migration in _migrate_db() will create this column on existing tables at next startup.
Extra field serialization in insert
rag/utils/infinity_conn.py
Within InfinityConnection.insert(), add special handling for the extra field: dict values are JSON-serialized to strings before storage in the varchar column; non-dict values normalize to empty string when falsy. Modeled on existing chunk_data serialization pattern.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

♾️infinity, size:S

Suggested reviewers

  • wangq8

Poem

🐰 A column went missing, the queries did fail,
But now with extra mapped, the RAPTOR won't stale!
JSON strings flow where the dicts once did dwell,
Infinity's RAPTOR builds dance through success's bell. 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix: declaring the extra field and serializing dicts on write for Infinity backend RAPTOR support.
Linked Issues check ✅ Passed The PR fully addresses all coding objectives from #14997: declaring the extra field in infinity_mapping.json [#14997], serializing dict to JSON string in infinity_conn.py insert() [#14997], and preserving other backend behavior [#14997].
Out of Scope Changes check ✅ Passed Both changes are narrowly scoped to resolve #14997: schema declaration in infinity_mapping.json and serialization logic in infinity_conn.py; no unrelated modifications are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed The PR description comprehensively addresses all template requirements with detailed problem explanation, solution breakdown, and verification steps.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
rag/utils/infinity_conn.py (2)

441-450: ⚡ Quick win

Consider adding logging for the new extra field serialization flow.

The new extra field handling introduces a new code path that serializes dict values to JSON. Adding a debug log would aid troubleshooting and align with the existing chunk_data logging 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 in extra field handling between insert() and update() methods.

The insert() method serializes extra field dict values to JSON strings (lines 441-450), but the update() 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 pass extra field dicts to update() (only pagerank updates are found), this inconsistency should be addressed for defensive consistency: either add JSON serialization to the update() 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6796a47 and 39fd98c.

📒 Files selected for processing (2)
  • conf/infinity_mapping.json
  • rag/utils/infinity_conn.py

@yingfeng yingfeng added the ci Continue Integration label May 19, 2026
@yingfeng
yingfeng marked this pull request as draft May 19, 2026 09:24
@yingfeng
yingfeng marked this pull request as ready for review May 19, 2026 09:24
@codecov

codecov Bot commented May 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.12%. Comparing base (6796a47) to head (39fd98c).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yingfeng
yingfeng merged commit eacec86 into infiniflow:main May 19, 2026
1 check passed
JinHai-CN pushed a commit that referenced this pull request May 21, 2026
…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)
@coderabbitai coderabbitai Bot mentioned this pull request Jun 7, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] RAPTOR builds fail on Infinity backend with '(3013) Fail to bind the expression: extra'

2 participants