Skip to content

DocumentChunkLocation dataclass

Specifies a chunk-level location within a document, providing positioning information for cited content using logical document segments or chunks.

Source code in src/aws_sdk_bedrock_runtime/models.py
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
@dataclass(kw_only=True)
class DocumentChunkLocation:
    """Specifies a chunk-level location within a document, providing
    positioning information for cited content using logical document
    segments or chunks.
    """

    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 chunk identifier or index of the cited content within the
    document.
    """

    end: int | None = None
    """The ending chunk identifier or index of the cited content within the
    document.
    """

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

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

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

        if self.end is not None:
            serializer.write_integer(
                _SCHEMA_DOCUMENT_CHUNK_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_CHUNK_LOCATION.members["documentIndex"]
                    )

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

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

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

        deserializer.read_struct(_SCHEMA_DOCUMENT_CHUNK_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 chunk identifier or index of the cited content within the document.

start class-attribute instance-attribute

start: int | None = None

The starting chunk identifier or index of the cited content within the document.