def _record_to_document(self, record: UniProtRecord) -> Document:
        """Convert a UniProt record to a LlamaIndex Document."""
        text_parts = []

        if "id" in self.include_fields:
            text_parts.append(f"Protein ID: {record.id}")
        if "accession" in self.include_fields:
            text_parts.append(f"Accession numbers: {', '.join(record.accession)}")
        if "description" in self.include_fields:
            text_parts.append(f"Description: {record.description}")
        if "gene_names" in self.include_fields:
            text_parts.append(f"Gene names: {', '.join(record.gene_names)}")
        if "organism" in self.include_fields:
            text_parts.append(f"Organism: {record.organism}")
        if "comments" in self.include_fields:
            text_parts.append("Comments:")
            text_parts.extend(f"- {comment}" for comment in record.comments)
        if "keywords" in self.include_fields:
            text_parts.append(f"Keywords: {', '.join(record.keywords)}")
        if "features" in self.include_fields:
            text_parts.append("Features:")
            text_parts.extend(
                f"- {feature['type']} ({feature['location']}): {feature['description']}"
                for feature in record.features
            )
        if "sequence_length" in self.include_fields:
            text_parts.append(f"Sequence length: {record.sequence_length} AA")
        if "sequence_mw" in self.include_fields:
            text_parts.append(f"Molecular weight: {record.sequence_mw} Da")
        if "taxonomy" in self.include_fields:
            # Clean up taxonomy by removing empty entries and joining with proper hierarchy
            clean_taxonomy = [t for t in record.taxonomy if t]
            text_parts.append("Taxonomy:")
            text_parts.append("  " + " > ".join(clean_taxonomy))
        if "taxonomy_id" in self.include_fields and record.taxonomy_id:
            text_parts.append(
                f"Taxonomy ID: {record.taxonomy_id['database']} {record.taxonomy_id['code']}"
            )
        if "cross_references" in self.include_fields:
            text_parts.append("Cross-references:")
            for ref in record.cross_references:
                text_parts.append(
                    f"- {ref['abbrev']}: {ref['id']}" + (f" - {'; '.join(ref['info'])}")
                )

        if "citations" in self.include_fields and record.citations:
            text_parts.append("Citations:")

            for citation in record.citations:
                text_parts.append(f"Reference {citation['number']}:")
                if citation["position"]:
                    text_parts.append("  Position: " + " ".join(citation["position"]))
                if citation["title"]:
                    text_parts.append("  Title: " + citation["title"])
                if citation["authors"]:
                    text_parts.append("  Authors: " + citation["authors"])
                if citation["location"]:
                    text_parts.append("  Location: " + " ".join(citation["location"]))
                if citation["comment"]:
                    text_parts.append("  Comments: " + " ".join(citation["comment"]))
                if citation["cross_references"]:
                    text_parts.append(
                        "  Cross-references: " + " ".join(citation["cross_references"])
                    )

        metadata = {
            "id": record.id,
        }

        return Document(text="\n".join(text_parts), metadata=metadata)
Convert a UniProt record to a LlamaIndex Document.
llama-index-integrations/readers/llama-index-readers-uniprot/llama_index/readers/uniprot/base.py