fix: bound automatic schema extraction input - #543
Conversation
|
Hi @nkgotcode, can you please sign the Contributor License Agreement as advised here? |
NathalieCharbel
left a comment
There was a problem hiding this comment.
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 "" |
There was a problem hiding this comment.
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.
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
Complexity
Complexity: Low
How Has This Been Tested?
uv run pytest tests/unit/experimental/pipeline/config/template_pipeline/test_simple_kg_builder.py tests/unit/experimental/components/test_schema.py -quv 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.pyuv 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.pygit diff --checkChecklist
The following requirements should have been met (depending on the changes in the branch):