Class: Langchain::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/langchain/data.rb

Overview

Abstraction for data loaded by a Loader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, source: nil, chunker: Langchain::Chunker::Text) ⇒ Data

Returns a new instance of Data.

Parameters:

  • data (String)

    data that was loaded

  • options (Hash)

    a customizable set of options



12
13
14
15
16
# File 'lib/langchain/data.rb', line 12

def initialize(data, source: nil, chunker: Langchain::Chunker::Text)
  @source = source
  @data = data
  @chunker_klass = chunker
end

Instance Attribute Details

#sourceString (readonly)

URL or Path of the data source

Returns:

  • (String)


8
9
10
# File 'lib/langchain/data.rb', line 8

def source
  @source
end

Instance Method Details

#chunks(opts = {}) ⇒ Array<String>

Parameters:

  • opts (Hash) (defaults to: {})

    options passed to the chunker

Returns:

  • (Array<String>)


25
26
27
# File 'lib/langchain/data.rb', line 25

def chunks(opts = {})
  @chunker_klass.new(@data, **opts).chunks
end

#valueString

Returns:

  • (String)


19
20
21
# File 'lib/langchain/data.rb', line 19

def value
  @data
end