class RubyLLM::Citation
A Citation links a span of generated text to the source material that supports it. Providers return citations in different shapes. RubyLLM normalizes all of them into Citation objects on Message#citations. Fields a provider does not report are nil.
chat = RubyLLM.chat(model: 'claude-sonnet-4-5').with_citations response = chat.ask "Who created Ruby?", with: "facts.txt" response.citations.each do |citation| citation.title # => "facts.txt" citation.cited_text # => the quoted passage from facts.txt citation.text # => the span of the answer it supports end
Attributes
The quoted snippet from the source material, or nil.
The character offset where the cited span ends in the response content, or nil.
The last page of a PDF citation (1-indexed, inclusive), or nil.
The 0-indexed position of the source document or search result, or nil.
The character offset where the cited span starts in the response content, or nil.
response.content[citation.start_index...citation.end_index] == citation.text # => true
The first page of a PDF citation (1-indexed, inclusive), or nil.
The span of the response content this citation supports, or nil.
The title or filename of the cited source, or nil.
The URL of the cited source, when citing the web, or nil.
Public Instance Methods
Source
# File lib/ruby_llm/citation.rb, line 85 def ==(other) other.is_a?(Citation) && to_h == other.to_h end
Returns true if other is a Citation with the same attributes, false otherwise.
Source
# File lib/ruby_llm/citation.rb, line 69 def to_h { url: url, title: title, cited_text: cited_text, text: text, start_index: start_index, end_index: end_index, source_index: source_index, start_page: start_page, end_page: end_page }.compact end
Returns the citation as a Hash with symbol keys, omitting nil fields.