Skip to content

Citation dataclass

Contains information about a citation that references a specific source document. Citations provide traceability between the model's generated response and the source documents that informed that response.

Source code in src/aws_sdk_bedrock_runtime/models.py
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
@dataclass(kw_only=True)
class Citation:
    """Contains information about a citation that references a specific source
    document. Citations provide traceability between the model's generated
    response and the source documents that informed that response.
    """

    title: str | None = None
    """The title or identifier of the source document being cited."""

    source_content: list[CitationSourceContent] | None = None
    """The specific content from the source document that was referenced or
    cited in the generated response.
    """

    location: CitationLocation | None = None
    """The precise location within the source document where the cited content
    can be found, including character positions, page numbers, or chunk
    identifiers.
    """

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

    def serialize_members(self, serializer: ShapeSerializer):
        if self.title is not None:
            serializer.write_string(_SCHEMA_CITATION.members["title"], self.title)

        if self.source_content is not None:
            _serialize_citation_source_content_list(
                serializer,
                _SCHEMA_CITATION.members["sourceContent"],
                self.source_content,
            )

        if self.location is not None:
            serializer.write_struct(_SCHEMA_CITATION.members["location"], self.location)

    @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["title"] = de.read_string(_SCHEMA_CITATION.members["title"])

                case 1:
                    kwargs["source_content"] = (
                        _deserialize_citation_source_content_list(
                            de, _SCHEMA_CITATION.members["sourceContent"]
                        )
                    )

                case 2:
                    kwargs["location"] = _CitationLocationDeserializer().deserialize(de)

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

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

Attributes

location class-attribute instance-attribute

location: CitationLocation | None = None

The precise location within the source document where the cited content can be found, including character positions, page numbers, or chunk identifiers.

source_content class-attribute instance-attribute

source_content: list[CitationSourceContent] | None = None

The specific content from the source document that was referenced or cited in the generated response.

title class-attribute instance-attribute

title: str | None = None

The title or identifier of the source document being cited.