class RubyLLM::FileStore

A FileStore keeps a chatโ€™s files: what people attach, what tools return, long tool results, and what code writes. Chat#with_file_store gives a chat one, and the model works with it through five tools that list, read, search, write, and edit its files, so a file reaches the model only when the model asks for it.

chat = RubyLLM.chat.with_file_store
chat.ask "Which clauses changed?", with: ["contract-v1.pdf", "contract-v2.pdf"]
chat.file_store.list.map(&:path) # => ["contract-v1.pdf", "contract-v2.pdf"]

RubyLLM ships FileStore::Memory, the default, and FileStore::Directory, which keeps the files in a folder; RubyLLM.file_store builds them. The Rails integration keeps a persisted chatโ€™s files in Active Storage.

chat.with_file_store(RubyLLM.file_store.directory("tmp/work"))

Write your own store by subclassing FileStore and implementing list, find, read, write, and delete. RubyLLM only ever passes them paths FileStore.path accepts: relative, with forward slashes, and without empty, ., or .. parts.

class BucketStore < RubyLLM::FileStore
  def initialize(bucket, prefix)
    super()
    @bucket = bucket
    @prefix = prefix
  end

  def list(prefix = nil) = ...
  def find(path) = ...
  def read(path) = ...
  def write(path, content, content_type: nil) = ...
  def delete(path) = ...
end