Class: Ask::RAG::Loader::PDF

Inherits:
Base
  • Object
show all
Defined in:
lib/ask/rag/loader/pdf.rb

Overview

Loads a PDF file using the pdf-reader gem, producing one document per page. Each document's metadata includes the page number.

Instance Method Summary collapse

Methods inherited from Base

#lazy_load

Instance Method Details

#load(path) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/ask/rag/loader/pdf.rb', line 9

def load(path)
  reader = PDF::Reader.new(path)
  reader.pages.map.with_index(1) do |page, idx|
    Ask::Document.new(
      content: page.text,
      metadata: { source: path, page: idx, format: "pdf" }
    )
  end
end