def row_to_document()

in python/src/tablestore_for_agent_memory/util/tablestore_helper.py [0:0]


    def row_to_document(row: Optional[tablestore.Row], text_field: str, embedding_field: str) -> Optional[Document]:
        if row is None:
            return None
        document_id = row.primary_key[0][1]
        tenant_id = row.primary_key[1][1]
        metadata = {}
        text_content = None
        vector_content = None
        for col in row.attribute_columns:
            key = col[0]
            val = col[1]
            if key == text_field:
                text_content = val
                continue
            if key == embedding_field:
                vector_content = json.loads(val)
                continue
            metadata[key] = val
        return Document(
            document_id=document_id,
            tenant_id=tenant_id,
            text=text_content,
            embedding=vector_content,
            metadata=metadata,
        )