Class: Vellum::SearchResult

Inherits:
Object
  • Object
show all
Defined in:
lib/vellum_ai/types/search_result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, score:, keywords:, document:, additional_properties: nil) ⇒ SearchResult

Parameters:

  • text (String)

    The text of the chunk that matched the search query.

  • score (Float)

    A score representing how well the chunk matches the search query.

  • keywords (Array<String>)
  • document (SearchResultDocument)

    The document that contains the chunk that matched the search query.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vellum_ai/types/search_result.rb', line 16

def initialize(text:, score:, keywords:, document:, additional_properties: nil)
  # @type [String] The text of the chunk that matched the search query.
  @text = text
  # @type [Float] A score representing how well the chunk matches the search query.
  @score = score
  # @type [Array<String>]
  @keywords = keywords
  # @type [SearchResultDocument] The document that contains the chunk that matched the search query.
  @document = document
  # @type [OpenStruct] Additional properties unmapped to the current class definition
  @additional_properties = additional_properties
end

Instance Attribute Details

#additional_propertiesObject (readonly)

Returns the value of attribute additional_properties.



8
9
10
# File 'lib/vellum_ai/types/search_result.rb', line 8

def additional_properties
  @additional_properties
end

#documentObject (readonly)

Returns the value of attribute document.



8
9
10
# File 'lib/vellum_ai/types/search_result.rb', line 8

def document
  @document
end

#keywordsObject (readonly)

Returns the value of attribute keywords.



8
9
10
# File 'lib/vellum_ai/types/search_result.rb', line 8

def keywords
  @keywords
end

#scoreObject (readonly)

Returns the value of attribute score.



8
9
10
# File 'lib/vellum_ai/types/search_result.rb', line 8

def score
  @score
end

#textObject (readonly)

Returns the value of attribute text.



8
9
10
# File 'lib/vellum_ai/types/search_result.rb', line 8

def text
  @text
end

Class Method Details

.from_json(json_object:) ⇒ SearchResult

Deserialize a JSON object to an instance of SearchResult

Parameters:

  • json_object (JSON)

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vellum_ai/types/search_result.rb', line 33

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  text = struct.text
  score = struct.score
  keywords = struct.keywords
  if parsed_json["document"].nil?
    document = nil
  else
    document = parsed_json["document"].to_json
    document = SearchResultDocument.from_json(json_object: document)
  end
  new(text: text, score: score, keywords: keywords, document: document, additional_properties: struct)
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


59
60
61
62
63
64
# File 'lib/vellum_ai/types/search_result.rb', line 59

def self.validate_raw(obj:)
  obj.text.is_a?(String) != false || raise("Passed value for field obj.text is not the expected type, validation failed.")
  obj.score.is_a?(Float) != false || raise("Passed value for field obj.score is not the expected type, validation failed.")
  obj.keywords.is_a?(Array) != false || raise("Passed value for field obj.keywords is not the expected type, validation failed.")
  SearchResultDocument.validate_raw(obj: obj.document)
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of SearchResult to a JSON object

Returns:

  • (JSON)


51
52
53
# File 'lib/vellum_ai/types/search_result.rb', line 51

def to_json(*_args)
  { "text": @text, "score": @score, "keywords": @keywords, "document": @document }.to_json
end