Skip to content

DocumentCharLocation dataclass

Specifies a character-level location within a document, providing precise positioning information for cited content using start and end character indices.

Source code in src/aws_sdk_bedrock_runtime/models.py
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
@dataclass(kw_only=True)
class DocumentCharLocation:
    """Specifies a character-level location within a document, providing
    precise positioning information for cited content using start and end
    character indices.
    """

    document_index: int | None = None
    """The index of the document within the array of documents provided in the
    request.
    """

    start: int | None = None
    """The starting character position of the cited content within the
    document.
    """

    end: int | None = None
    """The ending character position of the cited content within the document."""

    def serialize(self, serializer: ShapeSerializer):
        serializer.write_struct(_SCHEMA_DOCUMENT_CHAR_LOCATION, self)

    def serialize_members(self, serializer: ShapeSerializer):
        if self.document_index is not None:
            serializer.write_integer(
                _SCHEMA_DOCUMENT_CHAR_LOCATION.members["documentIndex"],
                self.document_index,
            )

        if self.start is not None:
            serializer.write_integer(
                _SCHEMA_DOCUMENT_CHAR_LOCATION.members["start"], self.start
            )

        if self.end is not None:
            serializer.write_integer(
                _SCHEMA_DOCUMENT_CHAR_LOCATION.members["end"], self.end
            )

    @classmethod
    def deserialize(cls, deserializer: ShapeDeserializer) -> Self:
        return cls(**cls.deserialize_kwargs(deserializer))

    @classmethod
    def deserialize_kwargs(cls, deserializer: ShapeDeserializer) -> dict[str, Any]:
        kwargs: dict[str, Any] = {}

        def _consumer(schema: Schema, de: ShapeDeserializer) -> None:
            match schema.expect_member_index():
                case 0:
                    kwargs["document_index"] = de.read_integer(
                        _SCHEMA_DOCUMENT_CHAR_LOCATION.members["documentIndex"]
                    )

                case 1:
                    kwargs["start"] = de.read_integer(
                        _SCHEMA_DOCUMENT_CHAR_LOCATION.members["start"]
                    )

                case 2:
                    kwargs["end"] = de.read_integer(
                        _SCHEMA_DOCUMENT_CHAR_LOCATION.members["end"]
                    )

                case _:
                    logger.debug("Unexpected member schema: %s", schema)

        deserializer.read_struct(_SCHEMA_DOCUMENT_CHAR_LOCATION, consumer=_consumer)
        return kwargs

Attributes

document_index class-attribute instance-attribute

document_index: int | None = None

The index of the document within the array of documents provided in the request.

end class-attribute instance-attribute

end: int | None = None

The ending character position of the cited content within the document.

start class-attribute instance-attribute

start: int | None = None

The starting character position of the cited content within the document.