Skip to content

feat(llm): make InfoExtract max_length configurable via settings - #415

Open
lplalbert wants to merge 3 commits into
apache:mainfrom
lplalbert:feat/info-extract-max-length-setting
Open

lplalbert wants to merge 3 commits into
apache:mainfrom
lplalbert:feat/info-extract-max-length-setting

Conversation

@lplalbert

@lplalbert lplalbert commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Refs #107 (Tiny Task: fix TODO/FIXME in LLM code)

What

The TODO on InfoExtract.valid() asked to make max_length configurable in settings
instead of a hard-coded 256. Extracted element ids over the limit are dropped before graph
write, and the limit is a deployment/storage constraint, so it belongs with the other
HugeGraph settings.

Changes

  • HugeGraphConfig.max_element_id_length: int = 256 (compared as UTF-8 bytes — same
    semantics as before).
  • InfoExtract.__init__(..., max_length: Optional[int] = None) resolves the configured
    limit; valid() falls back to it while keeping an explicit override. Behavior at default
    settings is unchanged (limit 256).
  • Nonpositive limits are rejected (review round 2d1c284): HugeGraphConfig validates
    max_element_id_length positive at load/update time — the configuration fails instead of
    valid() silently rejecting every id and _filter_long_id emptying the graph — and
    InfoExtract.__init__ applies the same check to the explicit constructor override.
  • Contract tests in test_info_extract.py: settings default, explicit override,
    _filter_long_id filtering, and positivity at both entry points.

Validation (actually run; offline only)

  • src/tests/operators/llm_op/test_info_extract.py: 5 tests in TestInfoExtractIdLengthLimit,
    each red before its fix (stashed), green after.
  • SKIP_EXTERNAL_SERVICES=true uv run pytest src/tests/operators/llm_op/ src/tests/config/
    → 146 passed, 3 subtests passed; full src/tests → 1294 passed, 12 skipped, 2 failed (the
    known pre-existing Windows mode-bit pair in test_external_config.py, unrelated).
  • ruff format --check / ruff check → clean on touched files
  • ty check → 0 diagnostics in touched production files; test_info_extract.py carries the
    file's existing InfoExtract(None) fake-LLM diagnostics (7 after this round, 5 before —
    same pre-existing class)
  • Real-provider verification: none (offline tests only)

Refs #107

🤖 Generated with Claude Code

@github-actions github-actions Bot added the llm label Nov 9, 2026

@bitflicker64 bitflicker64 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.

Blocking: no. Summary: The configurable limit keeps the 256-byte default and the valid() override, and the new tests cover both. The new setting is missing from the config.md table that documents every other HugeGraphConfig key.

edge_limit_pre_label: int = 8

# graph element config
max_element_id_length: int = 256

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.

Minor: hugegraph-llm/config.md lists every other HugeGraphConfig key in the HugeGraph table, but not MAX_ELEMENT_ID_LENGTH, so users cannot find the setting this PR adds. Add a MAX_ELEMENT_ID_LENGTH row (Optional[Integer], default 256, UTF-8 bytes) to that table.

@lplalbert

Copy link
Copy Markdown
Contributor Author

Fixed in a19731f — config.md now lists MAX_ELEMENT_ID_LENGTH (default 256, compared as
UTF-8 bytes, over-limit elements filtered by valid()) in the HugeGraph database table.

@bitflicker64 bitflicker64 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.

Blocking: no. Score: 9/10. Summary: max_element_id_length keeps the 256-byte default and the valid() override, the new tests cover settings, override and _filter_long_id, and the config.md row from the earlier review is in place.

@imbajin imbajin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Score: 7.5/10 · Confidence: high

Blocking: yes

Summary

A nonpositive ID length limit can discard all extracted graph elements without failing the extraction.

Evidence

The new integer setting has no positive constraint; valid() rejects byte lengths greater than or equal to the limit and _filter_long_id removes the elements.

Validation notes

Static source inspection; no running HugeGraph or LLM service was used. The prior documentation comment is addressed by the current config.md row.

edge_limit_pre_label: int = 8

# graph element config
max_element_id_length: int = 256

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

⚠️ Reject nonpositive ID length limits

If MAX_ELEMENT_ID_LENGTH is set to 0 or a negative integer, this unconstrained setting is accepted, but valid() rejects every ID because its UTF-8 byte length is always greater than or equal to the limit. _filter_long_id() then drops all vertices and edges after extraction and returns the empty graph with warnings rather than failing the configuration. Please validate that the configured limit is positive, and apply the same check to the explicit constructor override.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed — pushed (2d1c284). Root cause: max_element_id_length had no positivity constraint and InfoExtract.__init__ took the explicit override unchecked, while valid() rejects ids whose UTF-8 byte length is >= the limit — so a limit of 0 or a negative integer rejects every id and _filter_long_id silently returned the empty graph with warnings.

Structural fix: HugeGraphConfig now validates the setting positive in a field validator, so the configuration fails at load/update time instead of emptying the graph later; and InfoExtract.__init__ applies the same check to the effective limit, so the explicit constructor override is rejected the same way.

Tests: test_settings_reject_nonpositive_length_limit and test_explicit_length_limit_must_be_positive cover 0 and -1 at both entry points. Red without the fix ("ValueError not raised").

lplalbert and others added 3 commits November 16, 2026 01:49
Resolve the TODO on InfoExtract.valid(): the extracted element-id length
limit was a hard-coded 256 and could not be configured. Add
HugeGraphConfig.max_element_id_length (default 256, compared as UTF-8
bytes, same semantics as before), resolve it in the InfoExtract
constructor with an explicit max_length override, and let valid() fall
back to the configured limit. Behavior at default settings is unchanged.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Name the new HugeGraphConfig.max_element_id_length setting in the
configuration table with its UTF-8 byte comparison semantics.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Review round for apache#415: a configured MAX_ELEMENT_ID_LENGTH of 0 or a
negative integer was accepted, but valid() rejects every id whose UTF-8
byte length is >= the limit - which is every id - so _filter_long_id
silently emptied the graph with warnings instead of failing the
configuration.

HugeGraphConfig now validates max_element_id_length positive at load and
update time (pydantic field validator), and InfoExtract applies the same
check to the effective limit so the explicit constructor override is
rejected the same way.

Validation: 2 new regressions red-green (settings 0/-1 rejected, explicit
override 0/-1 rejected); llm_op + config suites 146 passed (known
test_external_config pair excluded, pre-existing); full hugegraph-llm
suite 1294 passed 12 skipped 2 failed (same known pair); ruff clean; ty
production files clean (the test file gains 2 more instances of its
existing InfoExtract(None) fake-LLM pattern).

Co-Authored-By: Claude Code <noreply@anthropic.com>
@lplalbert
lplalbert force-pushed the feat/info-extract-max-length-setting branch from a19731f to 2d1c284 Compare November 15, 2026 17:58

@bitflicker64 bitflicker64 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.

Blocking: no. Score: 9/10. Summary: max_element_id_length keeps the 256-byte default, and HugeGraphConfig plus the InfoExtract constructor reject nonpositive limits, which resolves the earlier review comments. The new tests fail on the base and pass at this head.

@imbajin imbajin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Score: 8.0/10 · Confidence: high

Blocking: no

Summary

The configurable byte threshold preserves the old default, but the documented boundary is misleading and can discard IDs users expect to keep.

Evidence

The new configuration row says IDs over the maximum are filtered, while valid() rejects byte lengths equal to the configured value as well. The added tests explicitly exercise this exclusive boundary.

Validation notes

Static source and test inspection; no running HugeGraph or LLM service was used. Existing nonpositive-limit and documentation issues are addressed at this head.

Comment thread hugegraph-llm/config.md
| `MAX_GRAPH_PATH` | Optional[Integer] | 10 | 最大图路径长度 |
| `MAX_GRAPH_ITEMS` | Optional[Integer] | 30 | 最大图项目数 |
| `EDGE_LIMIT_PRE_LABEL` | Optional[Integer] | 8 | 每个标签的边数限制 |
| `MAX_ELEMENT_ID_LENGTH` | Optional[Integer] | 256 | 信息抽取元素 ID 的最大长度(按 UTF-8 字节比较,超限元素被过滤,默认 256 与历史行为一致) |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

⚠️ Document the exclusive ID length threshold

The new setting is described as a maximum that filters IDs exceeding it, but valid() rejects IDs whose UTF-8 byte length is equal to the configured value too. For example, setting it to 1 discards every nonempty ID, and setting it to 10 discards 10-byte IDs. Please document that IDs must be strictly shorter than this threshold (or otherwise make the configuration contract match the comparison while preserving the historical default).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants