Class: Vellum::SearchResult
- Inherits:
-
Object
- Object
- Vellum::SearchResult
- Defined in:
- lib/vellum_ai/types/search_result.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#keywords ⇒ Object
readonly
Returns the value of attribute keywords.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ SearchResult
Deserialize a JSON object to an instance of SearchResult.
-
.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.
Instance Method Summary collapse
- #initialize(text:, score:, keywords:, document:, additional_properties: nil) ⇒ SearchResult constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of SearchResult to a JSON object.
Constructor Details
#initialize(text:, score:, keywords:, document:, additional_properties: nil) ⇒ SearchResult
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_properties ⇒ Object (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 |
#document ⇒ Object (readonly)
Returns the value of attribute document.
8 9 10 |
# File 'lib/vellum_ai/types/search_result.rb', line 8 def document @document end |
#keywords ⇒ Object (readonly)
Returns the value of attribute keywords.
8 9 10 |
# File 'lib/vellum_ai/types/search_result.rb', line 8 def keywords @keywords end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
8 9 10 |
# File 'lib/vellum_ai/types/search_result.rb', line 8 def score @score end |
#text ⇒ Object (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
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.
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
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 |