# -*- coding: utf-8 -*-"""The document data structure used in RAG as the data chunk andretrieval result."""fromdataclassesimportdataclass,fieldimportshortuuidfromdashscope.api_entities.dashscope_responseimportDictMixinfrom..messageimport(TextBlock,ImageBlock,VideoBlock,)from..typesimportEmbedding
[docs]@dataclassclassDocMetadata(DictMixin):"""The metadata of the document."""content:TextBlock|ImageBlock|VideoBlock"""The data content, e.g., text, image, video."""doc_id:str"""The document ID."""chunk_id:int"""The chunk ID."""total_chunks:int"""The total number of chunks."""
[docs]@dataclassclassDocument:"""The data chunk."""metadata:DocMetadata"""The metadata of the data chunk."""id:str=field(default_factory=shortuuid.uuid)"""The unique ID of the data chunk."""# The fields that will be filled when the document is added to or# retrieved from the knowledge base.embedding:Embedding|None=field(default_factory=lambda:None)"""The embedding of the data chunk."""score:float|None=None"""The relevance score of the data chunk."""