From 25f368b75c6e550efc74514e075607e376631547 Mon Sep 17 00:00:00 2001 From: Sachin Naik <64352484+sachinynaik@users.noreply.github.com> Date: Tue, 8 Sep 2026 17:15:41 +0530 Subject: [PATCH] feat(types): carry entity indices on Relation for span attribution A relation's head and tail are plain strings, so a consumer cannot tell WHICH mention a relation came from when the same surface text appears more than once in the input. That breaks span-based anchoring: in a measured fixture "Dr Chen" occurs at offsets 0 and 24, and a relation naming "Dr Chen" is unattributable. Entity already carries start/end, and ExtractOutput already carries the per-item entities list, so the linkage exists on both sides and only the join is missing. Two optional integers restore it by reference: - no duplication of span data, so the copies cannot disagree - head/tail keep their type, so every existing consumer is unaffected - adapters that cannot supply indices simply omit them NotRequired rather than total=False: the four existing fields are required and should stay that way. Measured on knowledgator/gliner-relex-base-v1.0, which already returns entity_idx on both sides of each relation. Co-Authored-By: Claude Opus 5 (1M context) --- packages/sie_server/src/sie_server/types/responses.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/sie_server/src/sie_server/types/responses.py b/packages/sie_server/src/sie_server/types/responses.py index 9bb9b60ab..f060cf119 100644 --- a/packages/sie_server/src/sie_server/types/responses.py +++ b/packages/sie_server/src/sie_server/types/responses.py @@ -124,12 +124,19 @@ class Relation(TypedDict): tail: Tail entity text. relation: Relation type label. score: Confidence score. + head_idx: Index of the head entity in the same item's entities list, when the + adapter can supply it. Lets a consumer recover the head's character offsets + without duplicating them here, which is the only way to attribute a relation + when the same surface text occurs more than once in the input. + tail_idx: Index of the tail entity in the same item's entities list. """ head: str tail: str relation: str score: float + head_idx: NotRequired[int] + tail_idx: NotRequired[int] class Classification(TypedDict):