Class: Vellum::SearchResultRequest

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, score:, keywords:, document:, meta: OMIT, additional_properties: nil) ⇒ Vellum::SearchResultRequest

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 (Vellum::SearchResultDocumentRequest)

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

  • meta (Vellum::SearchResultMetaRequest) (defaults to: OMIT)

    Additional information about the search result.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



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

def initialize(text:, score:, keywords:, document:, meta: OMIT, additional_properties: nil)
  @text = text
  @score = score
  @keywords = keywords
  @document = document
  @meta = meta if meta != OMIT
  @additional_properties = additional_properties
  @_field_set = { "text": text, "score": score, "keywords": keywords, "document": document, "meta": meta }.reject do | _k, v |
  v == OMIT
end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



20
21
22
# File 'lib/vellum_ai/types/search_result_request.rb', line 20

def additional_properties
  @additional_properties
end

#documentVellum::SearchResultDocumentRequest (readonly)

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

Returns:



16
17
18
# File 'lib/vellum_ai/types/search_result_request.rb', line 16

def document
  @document
end

#keywordsArray<String> (readonly)

Returns:

  • (Array<String>)


14
15
16
# File 'lib/vellum_ai/types/search_result_request.rb', line 14

def keywords
  @keywords
end

#metaVellum::SearchResultMetaRequest (readonly)

Returns Additional information about the search result.

Returns:



18
19
20
# File 'lib/vellum_ai/types/search_result_request.rb', line 18

def meta
  @meta
end

#scoreFloat (readonly)

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

Returns:

  • (Float)

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



12
13
14
# File 'lib/vellum_ai/types/search_result_request.rb', line 12

def score
  @score
end

#textString (readonly)

Returns The text of the chunk that matched the search query.

Returns:

  • (String)

    The text of the chunk that matched the search query.



10
11
12
# File 'lib/vellum_ai/types/search_result_request.rb', line 10

def text
  @text
end

Class Method Details

.from_json(json_object:) ⇒ Vellum::SearchResultRequest

Parameters:

  • json_object (String)

Returns:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/vellum_ai/types/search_result_request.rb', line 49

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

.validate_raw(obj:) ⇒ Void

Parameters:

  • obj (Object)

Returns:

  • (Void)


88
89
90
91
92
93
94
# File 'lib/vellum_ai/types/search_result_request.rb', line 88

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.")
  Vellum::SearchResultDocumentRequest.validate_raw(obj: obj.document)
  obj.meta.nil? || Vellum::SearchResultMetaRequest.validate_raw(obj: obj.meta)
end

Instance Method Details

#to_jsonString

Returns:

  • (String)


79
80
81
# File 'lib/vellum_ai/types/search_result_request.rb', line 79

def to_json
  @_field_set&.to_json
end