Class: Ask::RAG::Loader::JSON
Overview
Loads a JSON file as documents.
Supports two modes:
- Array of objects — each object becomes one document.
Specify
content_keyandmetadata_keysto map fields. - Single object — becomes one document.
Specify
content_keyfor which field holds the text.
Instance Method Summary collapse
-
#initialize(content_key: "content", metadata_keys: nil) ⇒ JSON
constructor
A new instance of JSON.
- #load(path) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(content_key: "content", metadata_keys: nil) ⇒ JSON
Returns a new instance of JSON.
29 30 31 32 |
# File 'lib/ask/rag/loader/json.rb', line 29 def initialize(content_key: "content", metadata_keys: nil) @content_key = content_key @metadata_keys = end |
Instance Method Details
#load(path) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/ask/rag/loader/json.rb', line 34 def load(path) raw = ::JSON.parse(File.read(path)) items = raw.is_a?(Array) ? raw : [raw] items.map { |item| build_document(item, path) } end |