Tighten evidence context source excerpts

This commit is contained in:
2026-08-09 20:04:46 +00:00
parent f6d037b613
commit bef8ca263b
6 changed files with 15 additions and 491 deletions

View File

@@ -167,6 +167,7 @@ func canonicalizeOwned(value Document) (Document, error) {
return nil, fmt.Errorf("document must be a JSON array")
}
seenUnitIDs := make(map[int]struct{}, len(value))
sourceID := ""
for unitIndex := range value {
unit := value[unitIndex]
if unit.ID <= 0 || strings.TrimSpace(unit.Kind) == "" || strings.TrimSpace(unit.Text) == "" {
@@ -175,6 +176,11 @@ func canonicalizeOwned(value Document) (Document, error) {
if err := validateUnitRef(unit, unitIndex); err != nil {
return nil, err
}
if sourceID == "" {
sourceID = unit.Ref.SourceID
} else if unit.Ref.SourceID != sourceID {
return nil, fmt.Errorf("units[%d].ref.source_id must match units[0].ref.source_id", unitIndex)
}
if _, exists := seenUnitIDs[unit.ID]; exists {
return nil, fmt.Errorf("units contains duplicate unit id %d", unit.ID)
}