Skip to content

feat: allow caller-supplied metadata on extracted entity nodes and relationships - #590

Open
Aryan-Pardeshi wants to merge 1 commit into
neo4j:mainfrom
Aryan-Pardeshi:feat/entity-metadata
Open

feat: allow caller-supplied metadata on extracted entity nodes and relationships#590
Aryan-Pardeshi wants to merge 1 commit into
neo4j:mainfrom
Aryan-Pardeshi:feat/entity-metadata

Conversation

@Aryan-Pardeshi

Copy link
Copy Markdown

Closes #588

The issue lays out the asymmetry precisely, so I will not restate it beyond the summary: document nodes take caller metadata via document_metadata, chunk nodes take it via TextChunk.metadata, and extracted entity nodes and relationships have no equivalent — their properties come only from LLM output. The lexical bookkeeping layer is enrichable while the entity layer, the part the library exists to produce, is not.

This adds an entity_metadata parameter threaded from SimpleKGPipeline.run_async() through SimpleKGPipelineConfig to the extractor, where post_process_chunk() merges it into the properties of every extracted node and relationship.

Caller-supplied keys take precedence over LLM-produced ones. That is documented on the parameter: if the model happens to emit a tenant_id, the caller's value is the one that lands, since the whole point is an authoritative application-level marker.

EntityRelationExtractor.run() gains the parameter on the abstract signature, so the example custom extractor in examples/customize/build_graph/components/extractors/custom_extractor.py is updated to match. The parameter is optional throughout and nothing is passed when it is None, so existing pipelines are unaffected.

Verified the new tests fail against unmodified main (2 failed) and pass with the change. tests/unit/experimental/pipeline/test_kg_builder.py and tests/unit/components/test_entity_relation_extractor.py together: 44 passed. mypy clean on both touched source files, ruff check clean on every file in the diff.

One note on the wider suite: tests/unit shows 27 failures on this branch, but main shows the same 27 (they come from a mistralai SDK mismatch in my environment), and this branch adds 2 passes on top.

If you would rather this lived on a pluggable writer than on the pipeline signature, I am happy to rework it — the reporter sketched a Neo4jWriter subclass as the current workaround, and I can see the argument either way.

…lationships

Adds an entity_metadata parameter to SimpleKGPipeline.run_async that is
threaded through the pipeline to LLMEntityRelationExtractor. Caller-supplied
metadata is merged into every extracted node and relationship property at
construction, taking precedence over LLM-produced keys (tenant, owner, or
ingestion-time markers). Closes neo4j#588.
@Aryan-Pardeshi
Aryan-Pardeshi requested a review from a team as a code owner August 9, 2026 07:46
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.

No way to attach caller-supplied metadata to extracted entity nodes

1 participant