Class: Weft::SearchResponse

Inherits:
ApiModelBase show all
Defined in:
lib/weft/generated/models/search_response.rb

Overview

The weft-search-platform POST /v1/search response envelope.

Defined Under Namespace

Classes: EnumAttributeValidator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiModelBase

_deserialize, #_to_hash, #to_body, #to_s

Constructor Details

#initialize(attributes = {}) ⇒ SearchResponse

Initializes the object

Parameters:

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

    Model attributes in the form of hash



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/weft/generated/models/search_response.rb', line 157

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `Weft::SearchResponse` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  acceptable_attribute_map = self.class.acceptable_attribute_map
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!acceptable_attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `Weft::SearchResponse`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'query_trace_id')
    self.query_trace_id = attributes[:'query_trace_id']
  else
    self.query_trace_id = nil
  end

  if attributes.key?(:'query')
    self.query = attributes[:'query']
  else
    self.query = nil
  end

  if attributes.key?(:'format')
    self.format = attributes[:'format']
  end

  if attributes.key?(:'markdown')
    self.markdown = attributes[:'markdown']
  end

  if attributes.key?(:'result_count')
    self.result_count = attributes[:'result_count']
  end

  if attributes.key?(:'served_from')
    self.served_from = attributes[:'served_from']
  end

  if attributes.key?(:'as_of')
    self.as_of = attributes[:'as_of']
  end

  if attributes.key?(:'stale')
    self.stale = attributes[:'stale']
  end

  if attributes.key?(:'payment_note')
    self.payment_note = attributes[:'payment_note']
  end

  if attributes.key?(:'applied_filters')
    self.applied_filters = attributes[:'applied_filters']
  end

  if attributes.key?(:'decomposition_source')
    self.decomposition_source = attributes[:'decomposition_source']
  end

  if attributes.key?(:'embedder_model')
    self.embedder_model = attributes[:'embedder_model']
  else
    self.embedder_model = nil
  end

  if attributes.key?(:'candidates_considered')
    self.candidates_considered = attributes[:'candidates_considered']
  else
    self.candidates_considered = nil
  end

  if attributes.key?(:'warnings')
    if (value = attributes[:'warnings']).is_a?(Array)
      self.warnings = value
    end
  else
    self.warnings = nil
  end

  if attributes.key?(:'match_quality')
    self.match_quality = attributes[:'match_quality']
  else
    self.match_quality = 'none'
  end

  if attributes.key?(:'reason')
    self.reason = attributes[:'reason']
  end

  if attributes.key?(:'suggestion')
    self.suggestion = attributes[:'suggestion']
  end

  if attributes.key?(:'results')
    if (value = attributes[:'results']).is_a?(Array)
      self.results = value
    end
  else
    self.results = nil
  end
end

Instance Attribute Details

#applied_filtersObject

The FilterSpec actually applied to recall, echoed back so the caller sees exactly what constrained the results. In the current contract this is the caller's filters verbatim (empty object when none were sent).



46
47
48
# File 'lib/weft/generated/models/search_response.rb', line 46

def applied_filters
  @applied_filters
end

#as_ofObject

When the results were produced. Now on a live serve; on a snapshot the ORIGINAL serve time, because a replay returns exactly what was paid for, not current truth.



37
38
39
# File 'lib/weft/generated/models/search_response.rb', line 37

def as_of
  @as_of
end

#candidates_consideredObject

Returns the value of attribute candidates_considered.



53
54
55
# File 'lib/weft/generated/models/search_response.rb', line 53

def candidates_considered
  @candidates_considered
end

#decomposition_sourceObject

Origin of applied_filters; always CALLER.



49
50
51
# File 'lib/weft/generated/models/search_response.rb', line 49

def decomposition_source
  @decomposition_source
end

#embedder_modelObject

Returns the value of attribute embedder_model.



51
52
53
# File 'lib/weft/generated/models/search_response.rb', line 51

def embedder_model
  @embedder_model
end

#formatObject

Which view this response carries, echoing the requested format. json populates results and leaves markdown null; markdown populates markdown and leaves results empty. Exactly one is populated per response, never both — returning both eagerly would double the payload.



25
26
27
# File 'lib/weft/generated/models/search_response.rb', line 25

def format
  @format
end

#markdownObject

The flat comparison table, when format is markdown; null otherwise. Rendered deterministically from the same stored result the json view returns, so the two views of one search can never disagree.



28
29
30
# File 'lib/weft/generated/models/search_response.rb', line 28

def markdown
  @markdown
end

#match_qualityObject

Calibrated confidence in this result set — read this instead of thresholding a raw similarity score. strong: the top match is confidently on-intent, proceed. weak: above the relevance floor but inside the band where plausible-but-wrong matches live, verify the result before paying. none: nothing cleared the floor — results is empty and reason / suggestion say why. Results below the floor are never returned as near-misses.



58
59
60
# File 'lib/weft/generated/models/search_response.rb', line 58

def match_quality
  @match_quality
end

#payment_noteObject

How payment works across the catalog, stated once for the whole response rather than repeated in every endpoint's usage instructions.



43
44
45
# File 'lib/weft/generated/models/search_response.rb', line 43

def payment_note
  @payment_note
end

#queryObject

Returns the value of attribute query.



22
23
24
# File 'lib/weft/generated/models/search_response.rb', line 22

def query
  @query
end

#query_trace_idObject

Opaque trace id for the served query, matching the platform query_trace_id — and the search_id that re-reads it. Deliberately the same id rather than a second handle: one serve, one name.



20
21
22
# File 'lib/weft/generated/models/search_response.rb', line 20

def query_trace_id
  @query_trace_id
end

#reasonObject

Machine-readable cause of an empty result set, non-null exactly when match_quality is none. below_relevance_floor: candidates ranked but the best scored under the floor. filter_collapsed_pool: a caller filter cut the pool before ranking and nothing relevant survived — relax the filter. no_catalog_coverage: recall returned no candidates at all on an unfiltered query. unsupported_filter_value: a CATEGORICAL filter value (type / protocol) matches zero stored values, so it could never have matched — categorical only, since a continuous bound like price that matches nothing is reported as filter_collapsed_pool instead (the bound needs raising, the dimension is not unsupported). index_unavailable: no active index — an operational fault, paired with the EMPTY_INDEX warning.



61
62
63
# File 'lib/weft/generated/models/search_response.rb', line 61

def reason
  @reason
end

#result_countObject

How many (Provider + Capability) results the search produced. Read THIS, not results.length, for the count: on a markdown response results is empty by design, so result_count > 0 with an empty results is a rendered table while result_count == 0 is a genuine zero-result.



31
32
33
# File 'lib/weft/generated/models/search_response.rb', line 31

def result_count
  @result_count
end

#resultsObject

Ranked (Provider + Capability) results; empty when the index is empty or nothing cleared the relevance floor. Results BELOW the floor are never returned — an empty list plus a reason is the honest answer, not a list of near-misses in the same shape as a genuine match.



67
68
69
# File 'lib/weft/generated/models/search_response.rb', line 67

def results
  @results
end

#served_fromObject

live for a fresh serve; snapshot for an immutable replay of a completed search. A re-read is a snapshot and says so — read it with as_of and stale.



34
35
36
# File 'lib/weft/generated/models/search_response.rb', line 34

def served_from
  @served_from
end

#staleObject

Whether the active search index has changed since these results were produced. true does not mean the results are wrong — it means they are a snapshot of an index that has since moved. Always false on a live serve.



40
41
42
# File 'lib/weft/generated/models/search_response.rb', line 40

def stale
  @stale
end

#suggestionObject

Human/agent-readable explanation of reason, carrying the concrete numbers behind it (pool sizes, the best discarded score against the floor, the values actually stored for a filter). Non-null exactly when reason is.



64
65
66
# File 'lib/weft/generated/models/search_response.rb', line 64

def suggestion
  @suggestion
end

#warningsObject

Returns the value of attribute warnings.



55
56
57
# File 'lib/weft/generated/models/search_response.rb', line 55

def warnings
  @warnings
end

Class Method Details

.acceptable_attribute_mapObject

Returns attribute mapping this model knows about



116
117
118
# File 'lib/weft/generated/models/search_response.rb', line 116

def self.acceptable_attribute_map
  attribute_map
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



121
122
123
# File 'lib/weft/generated/models/search_response.rb', line 121

def self.acceptable_attributes
  acceptable_attribute_map.values
end

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/weft/generated/models/search_response.rb', line 92

def self.attribute_map
  {
    :'query_trace_id' => :'query_trace_id',
    :'query' => :'query',
    :'format' => :'format',
    :'markdown' => :'markdown',
    :'result_count' => :'result_count',
    :'served_from' => :'served_from',
    :'as_of' => :'as_of',
    :'stale' => :'stale',
    :'payment_note' => :'payment_note',
    :'applied_filters' => :'applied_filters',
    :'decomposition_source' => :'decomposition_source',
    :'embedder_model' => :'embedder_model',
    :'candidates_considered' => :'candidates_considered',
    :'warnings' => :'warnings',
    :'match_quality' => :'match_quality',
    :'reason' => :'reason',
    :'suggestion' => :'suggestion',
    :'results' => :'results'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/weft/generated/models/search_response.rb', line 495

def self.build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  transformed_hash = {}
  openapi_types.each_pair do |key, type|
    if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = nil
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[attribute_map[key]].is_a?(Array)
        transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
      end
    elsif !attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
    end
  end
  new(transformed_hash)
end

.openapi_nullableObject

List of attributes with nullable: true



150
151
152
153
# File 'lib/weft/generated/models/search_response.rb', line 150

def self.openapi_nullable
  Set.new([
  ])
end

.openapi_typesObject

Attribute type mapping.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/weft/generated/models/search_response.rb', line 126

def self.openapi_types
  {
    :'query_trace_id' => :'String',
    :'query' => :'String',
    :'format' => :'String',
    :'markdown' => :'String',
    :'result_count' => :'Integer',
    :'served_from' => :'String',
    :'as_of' => :'Time',
    :'stale' => :'Boolean',
    :'payment_note' => :'String',
    :'applied_filters' => :'SearchFilterSpec',
    :'decomposition_source' => :'String',
    :'embedder_model' => :'String',
    :'candidates_considered' => :'Integer',
    :'warnings' => :'Array<SearchResponseWarningsInner>',
    :'match_quality' => :'String',
    :'reason' => :'String',
    :'suggestion' => :'String',
    :'results' => :'Array<SearchResult>'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
# File 'lib/weft/generated/models/search_response.rb', line 457

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      query_trace_id == o.query_trace_id &&
      query == o.query &&
      format == o.format &&
      markdown == o.markdown &&
      result_count == o.result_count &&
      served_from == o.served_from &&
      as_of == o.as_of &&
      stale == o.stale &&
      payment_note == o.payment_note &&
      applied_filters == o.applied_filters &&
      decomposition_source == o.decomposition_source &&
      embedder_model == o.embedder_model &&
      candidates_considered == o.candidates_considered &&
      warnings == o.warnings &&
      match_quality == o.match_quality &&
      reason == o.reason &&
      suggestion == o.suggestion &&
      results == o.results
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


482
483
484
# File 'lib/weft/generated/models/search_response.rb', line 482

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



488
489
490
# File 'lib/weft/generated/models/search_response.rb', line 488

def hash
  [query_trace_id, query, format, markdown, result_count, served_from, as_of, stale, payment_note, applied_filters, decomposition_source, embedder_model, candidates_considered, warnings, match_quality, reason, suggestion, results].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/weft/generated/models/search_response.rb', line 264

def list_invalid_properties
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  invalid_properties = Array.new
  if @query_trace_id.nil?
    invalid_properties.push('invalid value for "query_trace_id", query_trace_id cannot be nil.')
  end

  if @query.nil?
    invalid_properties.push('invalid value for "query", query cannot be nil.')
  end

  if !@result_count.nil? && @result_count < 0
    invalid_properties.push('invalid value for "result_count", must be greater than or equal to 0.')
  end

  if @embedder_model.nil?
    invalid_properties.push('invalid value for "embedder_model", embedder_model cannot be nil.')
  end

  if @candidates_considered.nil?
    invalid_properties.push('invalid value for "candidates_considered", candidates_considered cannot be nil.')
  end

  if @candidates_considered < 0
    invalid_properties.push('invalid value for "candidates_considered", must be greater than or equal to 0.')
  end

  if @warnings.nil?
    invalid_properties.push('invalid value for "warnings", warnings cannot be nil.')
  end

  if @results.nil?
    invalid_properties.push('invalid value for "results", results cannot be nil.')
  end

  invalid_properties
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



517
518
519
520
521
522
523
524
525
526
527
528
529
# File 'lib/weft/generated/models/search_response.rb', line 517

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/weft/generated/models/search_response.rb', line 304

def valid?
  warn '[DEPRECATED] the `valid?` method is obsolete'
  return false if @query_trace_id.nil?
  return false if @query.nil?
  format_validator = EnumAttributeValidator.new('String', ["json", "markdown"])
  return false unless format_validator.valid?(@format)
  return false if !@result_count.nil? && @result_count < 0
  served_from_validator = EnumAttributeValidator.new('String', ["live", "snapshot"])
  return false unless served_from_validator.valid?(@served_from)
  decomposition_source_validator = EnumAttributeValidator.new('String', ["CALLER"])
  return false unless decomposition_source_validator.valid?(@decomposition_source)
  return false if @embedder_model.nil?
  return false if @candidates_considered.nil?
  return false if @candidates_considered < 0
  return false if @warnings.nil?
  match_quality_validator = EnumAttributeValidator.new('String', ["strong", "weak", "none"])
  return false unless match_quality_validator.valid?(@match_quality)
  reason_validator = EnumAttributeValidator.new('String', ["below_relevance_floor", "filter_collapsed_pool", "no_catalog_coverage", "unsupported_filter_value", "index_unavailable"])
  return false unless reason_validator.valid?(@reason)
  return false if @results.nil?
  true
end