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 Citation Model

From Leeroopedia
Revision as of 12:16, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Cohere_ai_Cohere_python_Citation_Model.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains SDK, Citations, RAG
Last Updated 2026-02-15 14:00 GMT

Overview

Citation is a Pydantic model that represents a V2 citation linking a span of generated text back to its source documents.

Description

The Citation model contains information about where in the generated response text a particular citation appears and which sources it references. It uses character-level start and end indices to identify the cited span, along with the actual text snippet being cited. The sources field provides a list of Source objects that back the cited text. A content_index field indicates which content block within a multi-block response the citation belongs to. The type field (of type CitationType) indicates whether the citation refers to text content, thinking content, or a plan, with possible values "TEXT_CONTENT", "THINKING_CONTENT", and "PLAN".

Usage

Use Citation when processing V2 chat responses that include citations. Citations are returned by the Cohere API when retrieval-augmented generation is active and citation generation is enabled. Each citation object lets you trace a specific passage of the model's output back to its supporting source documents.

Code Reference

Source Location

Signature

class Citation(UncheckedBaseModel):
    start: typing.Optional[int] = pydantic.Field(default=None)
    end: typing.Optional[int] = pydantic.Field(default=None)
    text: typing.Optional[str] = pydantic.Field(default=None)
    sources: typing.Optional[typing.List[Source]] = None
    content_index: typing.Optional[int] = pydantic.Field(default=None)
    type: typing.Optional[CitationType] = None

Import

from cohere.types import Citation

I/O Contract

Fields

Field Type Required Description
start Optional[int] No Start index of the cited snippet in the generated text.
end Optional[int] No End index of the cited snippet in the generated text.
text Optional[str] No Text snippet that is being cited.
sources Optional[List[Source]] No List of source objects backing the citation.
content_index Optional[int] No Index of the content block in which this citation appears.
type Optional[CitationType] No The type of citation. One of "TEXT_CONTENT", "THINKING_CONTENT", or "PLAN".

Usage Examples

from cohere.types import Citation

# Citations are typically returned as part of a V2 chat response
response = client.chat(
    model="command-a-03-2025",
    messages=[{"role": "user", "content": "Summarize the quarterly report."}],
    documents=[{"id": "doc1", "data": {"text": "Revenue grew 15% year-over-year."}}],
)

# Iterate over citations in the response
for citation in response.message.citations:
    cited_text = citation.text
    span = f"[{citation.start}:{citation.end}]"
    print(f"Citation {span}: '{cited_text}'")
    print(f"  Type: {citation.type}")
    print(f"  Content block index: {citation.content_index}")
    if citation.sources:
        for source in citation.sources:
            print(f"  Source: {source}")

Related Pages

Page Connections

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