Repository navigation
unstructured2graph/sessions-graph: write turn provenance at extraction time - #400
Merged
Merged
Conversation
…n time Segment gains an optional, opaque source_id, which sessions-graph fills with the turn's action_id. The GLiNER2 backend writes exact provenance from the spans the model already returns, with no extra model calls: - MENTIONED_IN.sources lists the turns that mention each entity, merged by union so re-ingesting is idempotent; - each extracted relationship is keyed on (type, head, tail, chunk, source_id): a fact said in two turns is two edges, each with its own valid_at, which also ends the last-write-wins SET of valid_at within a session; - each edge carries source_id, role (the speaker) and text (the sentence or sentences covering both endpoints, capped at 300 characters). Without a source_id, keys and behaviour are unchanged. Closes #392 Claude-Session: https://claude.ai/code/session_01BczgXHGBrKsHSQUGB8P8te
This was referenced Oct 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #392. Part of map #390. The decisions are recorded on #392.
Why
Hybrid retrieval needs to know which turn each entity and fact came from. Until now the GLiNER2 backend dropped that at write time: a session is a single chunk, so entities linked only to the whole session. The eval then guessed the turn afterwards (
link_turnsin #389), by timestamp or substring match, which links a short or common entity name to every turn that contains the string. The backend already knows the exact turn, because it extracts one window per segment, and a segment is a turn.What changes
Segment.source_id: an optional, opaque id that unstructured2graph never interprets. sessions-graph fills it with the turn'saction_id. When identical turns are merged into one segment, it takes the first turn's id.MENTIONED_IN.sources: the turn ids that mention each entity in the chunk, merged by union, so re-ingesting is idempotent.upsert_extracted_relationshipskeys on(type, head, tail, chunk, source_id). A fact said in two turns becomes two edges, each with its ownvalid_at. Before, they collapsed into one edge, andSET r.valid_atkept whichever turn was written last.source_id,role(user or assistant) andtext: the sentence or sentences covering both endpoint spans, at most 300 characters. The full turn is one hop away throughsource_id.roletells the two speakers apart; it isn't a filter.source_id, e.g. plain document ingestion, keys and behaviour are unchanged.No extra model calls: all of it comes from spans GLiNER2 already returns.
Tests
All run against a real Memgraph with the GLiNER2 fakes:
sourcesfor an entity mentioned in two turns;The sessions-graph reconciliation e2e test now checks that the edge's
source_idis the user message'saction_id, and thatsourceslists both turns.Results, run locally:
Follow-ups
link_turnsandMENTIONED_IN_TURN.