Skip to content

fix: bound automatic schema extraction input - #543

Open
nkgotcode wants to merge 1 commit into
neo4j:mainfrom
nkgotcode:fix/schema-extraction-chunk-input
Open

fix: bound automatic schema extraction input#543
nkgotcode wants to merge 1 commit into
neo4j:mainfrom
nkgotcode:fix/schema-extraction-chunk-input

Conversation

@nkgotcode

Copy link
Copy Markdown

Description

Fixes #457.

This updates automatic schema extraction in the simple KG pipeline so schema extraction consumes splitter chunks instead of the full loader input. It also lets schema extraction accept chunk-list input and uses the first chunk for the schema prompt.

Type of Change

  • Bug fix
  • N/A: New feature
  • N/A: Breaking change
  • N/A: Documentation update
  • N/A: Project configuration change

Complexity

Complexity: Low

How Has This Been Tested?

  • Unit tests
  • N/A: E2E tests
  • N/A: Manual tests

uv run pytest tests/unit/experimental/pipeline/config/template_pipeline/test_simple_kg_builder.py tests/unit/experimental/components/test_schema.py -q

uv run ruff check src/neo4j_graphrag/experimental/components/schema.py src/neo4j_graphrag/experimental/pipeline/config/template_pipeline/simple_kg_builder.py tests/unit/experimental/pipeline/config/template_pipeline/test_simple_kg_builder.py tests/unit/experimental/components/test_schema.py

uv run ruff format --check src/neo4j_graphrag/experimental/components/schema.py src/neo4j_graphrag/experimental/pipeline/config/template_pipeline/simple_kg_builder.py tests/unit/experimental/pipeline/config/template_pipeline/test_simple_kg_builder.py tests/unit/experimental/components/test_schema.py

git diff --check

Checklist

The following requirements should have been met (depending on the changes in the branch):

  • Unit tests have been updated
  • CLA (https://neo4j.com/developer/cla/) has been signed
  • CHANGELOG.md updated if appropriate
  • N/A: Documentation has been updated
  • N/A: E2E tests have been updated
  • N/A: Examples have been updated
  • N/A: New files have copyright header

@nkgotcode
nkgotcode requested a review from a team as a code owner June 16, 2026 01:41
@NathalieCharbel
NathalieCharbel self-requested a review June 25, 2026 12:42
@NathalieCharbel

Copy link
Copy Markdown
Contributor

Hi @nkgotcode, can you please sign the Contributor License Agreement as advised here?

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

Thank you @nkgotcode for tackling this! Feeding the whole document text to automatic schema extraction is indeed a known limitation.
As I mentioned in my comment below, taking the first chunk may fix the issue, but introduce another problem of a poor schema and hence a poor extracted graph.
The direction I'd suggest is to sample across the document under an explicit budget rather than taking the first chunk. It keeps the single LLM call, stays close to the change you've already made, and gives the schema real coverage.
Happy to further discuss the sampling approach if you'd go for this approach and review the PR again.
Thanks again for the contribution!

constructed asynchronously.
"""
if isinstance(text, list):
text = text[0].text if text else ""

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.

I don't believe taking only the first chunk is a good idea, especially for large docs. With the default chunk_size=4000, the schema is derived from only the first ~4000 characters, which is unlikely to be representative of the docs. Since this schema is later used to guide LLM-based extraction, it introduces a significant limitation: the pruning step will discard any nodes or relationships that are not reflected in this initial schema. As a result, the final generated graph is likely to be of poor quality.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: schema extraction uses the whole file without splitting in chunks

2 participants