class RubyLLM::SearchResults
A SearchResults wraps documents a Tool returns so the model can cite them. It serializes to the search-results convention: a tool message whose content is {"search_results": [...]} renders as citable blocks on providers with citation support.
def execute(query:) docs = MyVectorStore.search(query) RubyLLM::SearchResults.new( *docs.map { |doc| { title: doc.name, url: doc.link, text: doc.body } } ) end
Cited passages come back on the response as Message#citations.
Attributes
The normalized results, as an array of hashes with :title, :text, and optional :url keys.
Public Class Methods
Source
# File lib/ruby_llm/search_results.rb, line 34 def initialize(*results, **result) results << result if result.any? @results = results.map { |entry| normalize(entry) } raise ArgumentError, 'SearchResults requires at least one result' if @results.empty? end
Returns a new SearchResults built from one or more result hashes, or from a single result given as keywords.
RubyLLM::SearchResults.new(title: 'Q4 Report', url: report_url, text: report_text) RubyLLM::SearchResults.new({ title: 'A', text: '...' }, { title: 'B', text: '...' })
Each result is reduced to its :title, :url, and :text entries. Raises ArgumentError if no results are given or a result is missing :title or :text.