Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Cohere ai Cohere python ChatCitation Model

From Leeroopedia
Knowledge Sources
Domains SDK, RAG
Last Updated 2026-02-15 14:00 GMT

Overview

The ChatCitation class is a Pydantic model representing a citation that links a section of generated text to source documents.

Description

The ChatCitation model represents a section of the generated reply which cites external knowledge. It contains positional information (start and end indices) that mark where in the generated text the citation applies, the cited text itself, a list of document_ids identifying the source documents, and an optional type field (of type ChatCitationType) indicating whether the citation applies to text content (TEXT_CONTENT) or a plan (PLAN). Character positions are zero-indexed. This model extends UncheckedBaseModel and is auto-generated from the Cohere API definition by Fern.

Usage

Use this model when processing citations from Cohere's Retrieval-Augmented Generation (RAG) responses. Citations allow you to trace which parts of the model's generated output are grounded in specific source documents, enabling transparency and verifiability in AI-generated content.

Code Reference

Source Location

Signature

class ChatCitation(UncheckedBaseModel):
    start: int = pydantic.Field()
    end: int = pydantic.Field()
    text: str = pydantic.Field()
    document_ids: typing.List[str] = pydantic.Field()
    type: typing.Optional[ChatCitationType] = pydantic.Field(default=None)

Import

from cohere.types import ChatCitation

I/O Contract

Field Type Required Default Description
start int Yes - The index of text that the citation starts at, counting from zero. For example, a generation of Hello, world! with a citation on world would have a start value of 7.
end int Yes - The index of text that the citation ends after, counting from zero. For example, a generation of Hello, world! with a citation on world would have an end value of 11.
text str Yes - The text of the citation. For example, a generation of Hello, world! with a citation of world would have a text value of world.
document_ids List[str] Yes - Identifiers of documents cited by this section of the generated reply.
type Optional[ChatCitationType] No None The type of citation indicating what part of the response the citation is for. One of: TEXT_CONTENT, PLAN.

Usage Examples

import cohere

client = cohere.Client(api_key="YOUR_API_KEY")

response = client.chat(
    model="command-r-plus",
    message="What is the capital of France?",
    documents=[
        {"title": "France", "text": "The capital of France is Paris."},
    ],
)

# Process citations from the response
if response.citations:
    for citation in response.citations:
        # Extract the cited text and its position
        print(f"Citation text: '{citation.text}'")
        print(f"Position: [{citation.start}, {citation.end})")
        print(f"Source documents: {citation.document_ids}")
        print(f"Citation type: {citation.type}")
        print()

        # Verify the citation text matches the response text
        generated_text = response.text
        assert generated_text[citation.start:citation.end] == citation.text

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment