-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathrank-features.html
More file actions
1819 lines (1583 loc) · 74.1 KB
/
rank-features.html
File metadata and controls
1819 lines (1583 loc) · 74.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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
261
262
263
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
# Copyright Vespa.ai. All rights reserved.
title: "Rank Feature Reference"
redirect_from:
- /en/reference/rank-features.html
---
<p>
This is the list of the rank features in Vespa.
These features are available during document ranking for combination into a complete rank score by a
<a href="ranking-expressions.html">ranking expression</a>.
The features are a combination of coarse grained features suitable for handwritten expressions,
and finer grained features suitable for machine learning.
</p><p>
See also <a href="../../basics/ranking.html">the overview of the ranking framework</a>, and
<a href="rank-feature-configuration.html">rank feature configuration parameters</a>.
Notes:
</p>
<ul>
<li>
Types: All rank feature values are floats. Integers are converted to exact whole value floats.
String values are converted to exact whole value floats using a hash function.
String literals in ranking expressions are converted using the same hash function,
to enable equality tests on string values.
</li><li>
Features which are <em>normalized</em> are between 0 and 1, where 0 is always the minimum and 1 the maximum.
Normalized features should normally be preferred because they are more easily combined by
<a href="ranking-expressions.html">ranking expressions</a> into a complete normalized score.
</li><li>
A query may override <em>any</em> rank feature value by submitting that value as a feature with the query.
</li><li>
Some features have parameters. It is always allowed to quote parameters with <em>"</em>.
Nested quotes are not allowed and must be escaped using <em>\</em>.
Parameters that can be parsed as feature names may be left unquoted.
Examples: <em>foo(bar(baz(5.5)))</em>, <em>foo("bar(\"baz(\\\"5.5\\\")\")")</em>, <em>foo("need quote")</em>
</li>
</ul>
<h2 id="feature-list">Feature list</h2>
<!--table-to-list-->
<table class="table" id="rank-feature-table">
<tr><td colspan="3"></td></tr>
<tr><td colspan="3"><h3 id="query-features">Query features</h3></td></tr>
<tr class="trx"><th class="thx">Feature name</th><th class="thx">Default</th><th class="thx">Description</th></tr>
<tr><td>query(<em>value</em>)</td>
<td>0</td>
<td>
<p id="query(value)">
An application specific feature submitted with the query,
see <a href="../../ranking/ranking-expressions-features.html#using-query-variables">using the query feature</a>.
</p>
</td></tr>
<tr><td>term(<em>n</em>).significance</td>
<td>0</td>
<td><p id="term(n).significance">
A normalized number (between 0.0 and 1.0) describing the significance
of the term; used as a multiplier or weighting factor by many other text matching rank features.
</p><p>
This should ideally be set by a searcher in the container for global correctness
as each node will estimate the significance values from the local corpus.
Use the
<a href="https://javadoc.io/doc/com.yahoo.vespa/container-search/latest/com/yahoo/prelude/query/TaggableItem.html#setSignificance(double)">
Java API for significance</a> or
<a href="../querying/yql.html#significance">YQL annotation for significance</a>.
</p><p>
As a fallback, a significance based on Robertson-Sparck-Jones term
weighting is used; it is logarithmic from 1.0 for rare terms down
to 0.5 for common terms (those occurring in every document seen).
</p><p>
Note that "rare" is defined as a frequency of 0.000001 or less.
This is the term document frequency (how many documents contain the
term out of all documents that can be observed), so you cannot get 1.0
as the fallback until you actually have a large number of documents
(minimum 1 million) in the same search process.
</p><p>
See <a href="rank-feature-configuration.html#term">numTerms</a> config.</p>
</td></tr>
<tr><td>term(<em>n</em>).weight</td>
<td>100</td>
<td><p id="term(n).weight">The importance of matching this query term given in the query</p></td></tr>
<tr><td>term(<em>n</em>).connectedness</td>
<td>0.1</td>
<td>
<p id="term(n).connectedness">
The normalized strength with which this term is connected to the previous term in the query.
Must be assigned to query terms in a <a href="../../applications/searchers.html">searcher</a> using the
<a href="https://javadoc.io/doc/com.yahoo.vespa/container-search/latest/com/yahoo/prelude/query/TaggableItem.html#setConnectivity(com.yahoo.prelude.query.Item,double)">
Java API for connectivity</a>
or <a href="../querying/yql.html#connectivity">YQL annotation for connectivity</a>.
</p>
</td></tr>
<tr><td>queryTermCount</td>
<td>0</td>
<td>
<p id="queryTermCount">
The total number of terms in this query, including both user and synthetic terms in all fields.
</p>
</td></tr>
<tr><td colspan="3"></td></tr>
<tr><td colspan="3"><h3 id="document-features">Document features</h3></td></tr>
<tr class="trx"><th class="thx">Feature name</th><th class="thx">Default</th><th class="thx">Description</th></tr>
<tr><td>fieldLength(<em>name</em>)</td>
<td>1000000</td>
<td>
<p id="fieldLength(name)">
The number of terms in this field if one or more query term matched the field,
1000000 if no query term matched the field.
</p>
</td></tr>
<tr><td>attribute(<em>name</em>)</td>
<td>null</td>
<td>
<p id="attribute(name)">
The value of a <a href="../schemas/schemas.html#tensor">tensor</a>
or single value <em>numeric</em> attribute or null/NaN if not set.
Use <em>isNan()</em> to check if value is not defined.
Using undefined values in ranking expressions leads to undefined behavior.
</p>
</td></tr>
<tr><td>attribute(<em>name</em>,<em>n</em>)</td>
<td>0</td>
<td>
<p id="attribute(name,n)">
The value at index n (base 0) of a <em>numeric</em> array attribute with the given name.
Note that the index number must be explicit, it cannot be the output of an
<a href="../schemas/schemas.html#function-rank">expression function</a>.
The order of the items in an array attribute is the same as the order they have in the input feed.
If items are added using partial updates they are added to the end of the existing items list.
</p>
</td></tr>
<tr><td>attribute(<em>name</em>,<em>key</em>).weight</td>
<td>0</td>
<td><p id="attribute(name,key).weight">The weight found at a given key in a weighted set attribute</p></td></tr>
<tr><td>attribute(<em>name</em>,<em>key</em>).contains</td>
<td>0</td>
<td>
<p id="attribute(name,key).contains">1 if the given key is present in a weighted set attribute, 0 otherwise</p>
</td></tr>
<tr><td>attribute(<em>name</em>).count</td>
<td>0</td>
<td><p id="attribute(name).count">The number of elements in the attribute with the given name.</p></td></tr>
<tr><td>tensorFromWeightedSet(<em>source</em>,<em>dimension</em>)</td>
<td>empty tensor</td>
<td>
<p id="tensorFromWeightedSet(source,dimension)">
Creates a <code>tensor<double></code> with one mapped dimension
from the given integer or string weighted set attribute.
The attribute is specified as the full feature name, <code>attribute(name)</code>.
The <em>dimension</em> parameter is optional. If omitted the dimension name will be the attribute name.
</p>
<p>Example: Given the weighted set:</p>
<pre>
{key1:0, key2:1, key3:2.5}
</pre>
<p><em>tensorFromWeightedSet(attribute(myField), dim)</em> produces:</p>
<pre>
tensor<double>(dim{}):{ {dim:key1}:0.0, {dim:key2}:1.0, {dim:key3}:2.5} }
</pre>
{% include note.html content="This creates a temporary tensor,
and has build cost and extra memory is touched.
Tensor evaluation is most effective when the cell types of all tensors are equal -
use <a href='ranking-expressions.html#cell_cast'>cell_cast</a> to enable optimizations.
Also, duplicating the field in the schema to a native tensor instead of creating from a set
can increase performance." %}
</td></tr>
<tr><td>tensorFromLabels(<em>attribute</em>,<em>dimension</em>)</td>
<td>empty tensor</td>
<td>
<p id="tensorFromLabels(source,dimension)">
Creates a <code>tensor<double></code> with one mapped dimension
from the given single value or array attribute.
The value(s) must be integers or strings. The attribute is specified as the full feature name,
<code>attribute(name)</code>.
The <em>dimension</em> parameter is optional. If omitted the dimension name will be the attribute name.
</p>
<p>
Example: Given an attribute field <code>myField</code> containing the array value:
</p>
<pre>
[v1, v2, v3]
</pre>
<p><em>tensorFromLabels(attribute(myField), dim)</em> produces:</p>
<pre>
tensor<double>(dim{}):{ {dim:v1}:1.0, {dim:v2}:1.0, {dim:v3}:1.0} }
</pre>
<p>See <em>tensorFromWeightedSet</em> for performance notes.</p>
</td></tr>
<tr><td>tensorFromStructs(<em>attribute</em>,<em>key</em>,<em>value</em>,<em>type</em>)</td>
<td>empty tensor</td>
<td>
<p id="tensorFromStructs(attribute,key,value,type)">
Creates a <code>tensor<type></code> with one mapped dimension
from the given <code>array<struct></code> attribute.
Keys are taken from the struct field <em>key</em> and values from the struct field <em>value</em>.
The resulting tensor will have one mapped dimension named after the <em>key</em> field.
The <em>type</em> parameter is required and must be <code>float</code> or <code>double</code>.
The function takes exactly four arguments.
</p>
<p>Example: Given an <code>array<struct></code> attribute <code>items</code> with fields
<code>name</code> (string) and <code>price</code> (float):</p>
<pre>
tensorFromStructs(attribute(items), name, price, float)
</pre>
<pre>
tensor<float>(name{}):{ {name:apple}:1.5, {name:banana}:0.75, {name:cherry}:2.25 }
</pre>
<p>Example: Integer keys and float values:</p>
<pre>
tensorFromStructs(attribute(ids), id, score, double)
</pre>
<pre>
tensor(id{}):{ {id:100}:10.5, {id:200}:20.75, {id:300}:30.25 }
</pre>
<p><em>Details:</em> Empty or missing arrays yield an empty tensor of the requested type.
The first argument must be an <code>attribute(...)</code> source.</p>
<p>See <em>tensorFromWeightedSet</em> for performance notes.</p>
</td>
</tr>
<tr><td colspan="3"></td></tr>
<tr><td colspan="3"><h3 id="field-match-features-normalized">Field match features - normalized</h3></td></tr>
<tr><td colspan="3">
fieldMatch features provide a good measure of the degree
to which a query matches the text of a field, but are expensive to calculate and therefore
often only suitable for <a href="../../ranking/phased-ranking.html">second-phase</a> ranking expressions.
See the <a href="string-segment-match.html">string segment match</a> document
for details on the algorithm computing this rank-feature set.
Note that even using a fine-grained sub features like fieldMatch(<em>name</em>).absoluteOccurrence
will have the same complexity and cost as using the general top level fieldMatch(<em>name</em>) feature.
</td></tr>
<tr class="trx"><th class="thx">Feature name</th><th class="thx">Default</th><th class="thx">Description</th></tr>
<tr><td>fieldMatch(<em>name</em>)</td>
<td>0</td>
<td>
<p id="fieldMatch(name)">
A normalized measure of the degree to which this query and field matched
(default, the long name of this is <code>match</code>). Use this if you do not
want to create your own combination function of more fine-grained fieldmatch features.
</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).proximity</td>
<td>0</td>
<td><p id="fieldMatch(name).proximity">
Normalized proximity - a value which is close to 1 when matched terms are close
<em>inside each segment</em>, and close to zero when they are far apart inside segments.
Relatively more connected terms influence this value more. This is
absoluteProximity/average connectedness for the query terms for this field.
</p><p>
Note that if all the terms are far apart,
the proximity will be 1, but the number of segments will be high.
Proximity is only concerned with closeness within segments,
a total score must also take the number of segments into account.</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).completeness</td>
<td>0</td>
<td>
<p id="fieldMatch(name).completeness">
The normalized total completeness, where field completeness is more important:
</p>
<p>
<code>queryCompleteness *
( 1 - <a href="rank-feature-configuration.html#fieldMatch">fieldCompletenessImportance</a> )
+ <a href="rank-feature-configuration.html#fieldMatch">fieldCompletenessImportance</a> * fieldCompleteness</code>
</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).queryCompleteness</td>
<td>0</td>
<td><p id="fieldMatch(name).queryCompleteness">The normalized ratio of query tokens matched in the field:</p>
<code>matches/query terms searching this field</code></td></tr>
<tr><td>fieldMatch(<em>name</em>).fieldCompleteness</td>
<td>0</td>
<td><p id="fieldMatch(name).fieldCompleteness">The normalized ratio of query tokens which was matched in the field:</p>
<code>matches/fieldLength</code></td></tr>
<tr><td>fieldMatch(<em>name</em>).orderness</td>
<td>0</td>
<td>
<p id="fieldMatch(name).orderness">
A normalized metric of how well the order of the terms agrees in the chosen segments:
</p>
<p><code>1-outOfOrder/pairs</code></p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).relatedness</td>
<td>0</td>
<td>
<p id="fieldMatch(name).relatedness">
A normalized measure of the degree to which different terms are related (occurring in the same segment):
</p>
<p><code>1-(segments-1)/(matches-1)</code></p></td></tr>
<tr><td>fieldMatch(<em>name</em>).earliness</td>
<td>0</td>
<td>
<p id="fieldMatch(name).earliness">
A normalized measure of how early the first segment occurs in this field.
</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).longestSequenceRatio</td>
<td>0</td>
<td>
<p id="fieldMatch(name).longestSequenceRatio">A normalized metric of the relative size of the longest sequence:</p>
<p><code>longestSequence/matches</code></p></td></tr>
<tr><td>fieldMatch(<em>name</em>).segmentProximity</td>
<td>0</td>
<td>
<p id="fieldMatch(name).segmentProximity">
A normalized metric of the closeness (inverse of spread) of segments in the field:
</p>
<p><code>1-segmentDistance/fieldLength</code></p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).unweightedProximity</td>
<td>0</td>
<td>
<p id="fieldMatch(name).unweightedProximity">
The normalized proximity of the matched terms, not taking term connectedness into account.
This number is close to 1 if all the matched terms are
following each other in sequence, and close to 0 if they are far from each other or out of order.
</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).absoluteProximity</td>
<td>0</td>
<td>
<p id="fieldMatch(name).absoluteProximity">
Returns the normalized proximity of the matched terms, weighted by the connectedness of
the query terms. This number is 0.1 if all the matched terms are and have default or lower
connectedness, close to 1 if they are following in sequence and have a high connectedness,
and close to 0 if they are far from each other in the segments or out of order.
</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).occurrence</td>
<td>0</td>
<td><p id="fieldMatch(name).occurrence">
Returns a normalized measure of the number of occurrences of the terms of the query.
This is 1 if there are many occurrences of the query terms <em>in absolute terms,
or relative to the total content of the field</em>, and 0 if there are none.
</p><p>
This is suitable for occurrence in fields containing regular text.</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).absoluteOccurrence</td>
<td>0</td>
<td><p id="fieldMatch(name).absoluteOccurrence">
Returns a normalized measure of the number of occurrence of the terms of the query:
</p><p class="equation-container" class="equation-container"><!-- depends on mathjax -->
$$\frac{\sum_{\text{all query terms}}(min(\text{number of occurrences of the term},maxOccurrences))}{(\text{query term count} × 100)}$$
</p><p>
This is 1 if there are many occurrences of the query terms, and 0 if there are none.
</p><p>
This number is not relative to the field length, so it is suitable for uses
of occurrence to denote relative importance between matched terms
(i.e. fields containing keywords, not normal text).</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).weightedOccurrence</td>
<td>0</td>
<td>
<p id="fieldMatch(name).weightedOccurrence">
Returns a normalized measure of the number of occurrence of the terms of the query,
weighted by term weight.
This number is close to 1 if there are many occurrences of highly weighted query terms,
in absolute terms, or relative to the total content of the field, and 0 if there are none.
</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).weightedAbsoluteOccurrence</td>
<td>0</td>
<td><p id="fieldMatch(name).weightedAbsoluteOccurrence">
Returns a normalized measure of the number of occurrence of the terms of the query,
taking weights into account so that occurrences of higher weighted query terms
has more impact than lower weighted terms.
</p><p>
This is 1 if there are many occurrences of the highly weighted terms, and 0 if there are none.
</p><p>
This number is not relative to the field length, so it is suitable for uses
of occurrence to denote relative importance between matched terms
(i.e. fields containing keywords, not normal text).</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).significantOccurrence</td>
<td>0</td>
<td><p id="fieldMatch(name).significantOccurrence">
Returns a normalized measure of the number of occurrence of the terms of the query <em>in absolute terms,
or relative to the total content of the field</em>, weighted by term significance.
</p><p>
This number is 1 if there are many occurrences of the highly significant terms,
and 0 if there are none.</p>
</td></tr>
<tr><td colspan="3"></td></tr>
<tr><td colspan="3"><h3 id="field-match-features-normalized-and-relative-to-the-whole-query">
Field match features - normalized and relative to the whole query</h3></td></tr>
<tr class="trx"><th class="thx">Feature name</th><th class="thx">Default</th><th class="thx">Description</th></tr>
<tr><td>fieldMatch(<em>name</em>).weight</td>
<td>0</td>
<td><p id="fieldMatch(name).weight">
The normalized weight of this match relative to the whole query:
The sum of the weights of all <em>matched</em> terms/the sum of the weights of all <em>query</em> terms.
If all the query terms were matched, this is 1.
If no terms were matched, or these matches has weight zero this is 0.
</p><p>
As the sum of this number over all the terms of the query is always 1, sums over all fields of
normalized rank features for each field multiplied by this number
for the same field will produce a normalized number.
</p><p>
Note that this scales with the number of matched query terms in the field.
If you want a component which does not, divide by matches.</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).significance</td>
<td>0</td>
<td><p id="fieldMatch(name).significance">
Returns the normalized term significance of the terms of this match relative to the
whole query: The sum of the significance of all <em>matched</em> terms/the sum of the significance of all
<em>query</em> terms. If all the query terms were matched, this is 1. If no terms were matched, or if the
significance of all the matched terms is zero, this number is zero.
</p><p>
This metric has the same properties as weight.
</p><p>
See the <a href="#term(n).significance">term(n).significance</a> feature for how the significance
for a single term is calculated.</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).importance</td>
<td>0</td>
<td>
<p id="fieldMatch(name).importance">
Returns the average of significance and weight. This has the same properties as those metrics.
</p>
</td></tr>
<tr><td colspan="3"></td></tr>
<tr><td colspan="3">
<h3 id="field-match-features-not-normalized">Field match features - not normalized</h3></td></tr>
<tr class="trx"><th class="thx">Feature name</th><th class="thx">Default</th><th class="thx">Description</th></tr>
<tr><td>fieldMatch(<em>name</em>).segments</td>
<td>0</td>
<td>
<p id="fieldMatch(name).segments">
The number of field text segments which are needed to match the query as completely as possible
</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).matches</td>
<td>0</td>
<td>
<p id="fieldMatch(name).matches">
The total number of query terms which was matched in this field
</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).degradedMatches</td>
<td>0</td>
<td>
<p id="fieldMatch(name).degradedMatches">
The number of degraded query terms which was matched in this field.
A degraded term is a term where no occurrence information is available during calculation.
The number of degraded matches is less than or equal to the total number of matches.
</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).outOfOrder</td>
<td>0</td>
<td>
<p id="fieldMatch(name).outOfOrder">
The total number of out of order token sequences <em>within</em> matched field segments
</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).gaps</td>
<td>0</td>
<td>
<p id="fieldMatch(name).gaps">
The total number of position jumps (backward or forward) within field segments
</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).gapLength</td>
<td>0</td>
<td><p id="fieldMatch(name).gapLength">The summed length of all gaps within segments</p></td></tr>
<tr><td>fieldMatch(<em>name</em>).longestSequence</td>
<td>0</td>
<td>
<p id="fieldMatch(name).longestSequence">
The size of the longest matched continuous, in-order sequence in the field
</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).head</td>
<td>0</td>
<td>
<p id="fieldMatch(name).head">
The number of tokens in the field preceding the start of the first matched segment
</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).tail</td>
<td>0</td>
<td>
<p id="fieldMatch(name).tail">
The number of tokens in the field following the end of the last matched segment
</p>
</td></tr>
<tr><td>fieldMatch(<em>name</em>).segmentDistance</td>
<td>0</td>
<td>
<p id="fieldMatch(name).segmentDistance">
The sum of the distance between all segments making up a match to the query, measured
as the sum of the number of token positions separating the
<em>start</em> of each <em>field</em> adjacent segment.
</p>
</td></tr>
<tr><td colspan="3"></td></tr>
<tr><td colspan="3"><h3 id="query-and-field-similarity">Query and field similarity</h3></td></tr>
<tr><td colspan="3">
Normalized feature set measuring the approximate <em>similarity</em> between a field and the query.
These features are suitable in cases where the query is as large as the field (i.e. is a document)
such that we are interested in the similarity between the query and the entire field.
They are cheap to compute even if the query is large.
</td></tr>
<tr class="trx"><th class="thx">Feature name</th><th class="thx">Default</th><th class="thx">Description</th></tr>
<tr><td>textSimilarity(<em>name</em>)</td>
<td>0</td>
<td><p id="textSimilarity(name)">A weighted sum of the individual similarity measures.</p></td></tr>
<tr><td>textSimilarity(<em>name</em>).proximity</td>
<td>0</td>
<td>
<p id="textSimilarity(name).proximity">
A measure of how close together the query terms appear in the field.
</p>
</td></tr>
<tr><td>textSimilarity(<em>name</em>).order</td>
<td>0</td>
<td>
<p id="textSimilarity(name).order">
A measure of the order in which the query terms appear in the field compared to the query.
</p>
</td></tr>
<tr><td>textSimilarity(<em>name</em>).queryCoverage</td>
<td>0</td>
<td>
<p id="textSimilarity(name).queryCoverage">
A measure of how much of the query the field covers when a single term
from the field can only cover a single term in the query.
Query term weights are used during normalization.
</p>
</td></tr>
<tr><td>textSimilarity(<em>name</em>).fieldCoverage</td>
<td>0</td>
<td>
<p id="textSimilarity(name).fieldCoverage">
A measure of how much of the field the query covers when a single term from the query
can only cover a single term in the field.
</p>
</td></tr>
<tr><td colspan="3"></td></tr>
<tr><td colspan="3"><h3 id="query-term-and-field-match-features">Query term and field match features</h3></td></tr>
<tr class="trx"><th class="thx">Feature name</th><th class="thx">Default</th><th class="thx">Description</th></tr>
<tr><td>fieldTermMatch(<em>name</em>,<em>n</em>).firstPosition</td>
<td>1000000</td>
<td>
<p id="fieldTermMatch(name,n).firstPosition">
The position of the first occurrence of this query term in this index field.
<a href="rank-feature-configuration.html#fieldTermMatch">numTerms</a> configuration
</p>
</td></tr>
<tr><td>fieldTermMatch(<em>name</em>,<em>n</em>).occurrences</td>
<td>0</td>
<td>
<p id="fieldTermMatch(name,n).occurrences">
The number of occurrences of this query term in this index field
</p>
</td></tr>
<tr><td>matchCount(<em>name</em>)</td>
<td>0</td>
<td>
<p id="matchCount(name)">
Returns number of times any term in the query matches this index/attribute field.
</p>
</td></tr>
<tr><td>matches(<em>name</em>)</td>
<td>0</td>
<td>
<p id="matches(name)">
Returns 1 if the index/attribute field with the given name is matched by the query.
</p>
</td></tr>
<tr><td>matches(<em>name</em>,<em>n</em>)</td>
<td>0</td>
<td>
<p id="matches(name,n)">
Returns 1 if the index/attribute field with the given name is matched by the query term with position <em>n</em>.
</p>
</td></tr>
<tr><td>termDistance(<em>name</em>,<em>x</em>,<em>y</em>).forward</td>
<td>1000000</td>
<td>
<p id="termDistance(name,x,y).forward">
The minimum distance between the occurrences of term <em>x</em> and term <em>y</em> in this index field.
Term <em>x</em> occurs before term <em>y</em>.
</p>
</td></tr>
<tr><td>termDistance(<em>name</em>,<em>x</em>,<em>y</em>).forwardTermPosition</td>
<td>1000000</td>
<td>
<p id="termDistance(name,x,y).forwardTermPosition">
The position of the occurrence of term <em>x</em> in this index field used for the forward distance.
</p>
</td></tr>
<tr><td>termDistance(<em>name</em>,<em>x</em>,<em>y</em>).reverse</td>
<td>1000000</td>
<td>
<p id="termDistance(name,x,y).reverse">
The minimum distance between the occurrences of term <em>y</em> and term <em>x</em> in this index field.
Term <em>y</em> occurs before term <em>x</em>.
</p>
</td></tr>
<tr><td>termDistance(<em>name</em>,<em>x</em>,<em>y</em>).reverseTermPosition</td>
<td>1000000</td>
<td>
<p id="termDistance(name,x,y).reverseTermPosition">
The position of the occurrence of term <em>y</em> in this index field used for the reverse distance.
</p>
</td></tr>
<tr><td colspan="3"></td></tr>
<tr><td colspan="3">
<h3 id="features-for-indexed-multivalue-string-fields">Features for indexed multivalue string fields</h3></td></tr>
<tr class="trx"><th class="thx">Feature name</th><th class="thx">Default</th><th class="thx">Description</th></tr>
<tr><td>elementCompleteness(<em>name</em>).completeness</td>
<td>0</td>
<td>
<p id="elementCompleteness(name).completeness">
A weighted combination of fieldCompleteness and queryCompleteness for the element in the field that produces the
highest value for this output after the elements weight is factored in. The weighting can be adjusted using
<a href="rank-feature-configuration.html#elementCompleteness">elementCompleteness(name).fieldCompletenessImportance</a>.
</p>
</td></tr>
<tr><td>elementCompleteness(<em>name</em>).fieldCompleteness</td>
<td>0</td>
<td>
<p id="elementCompleteness(name).fieldCompleteness">
The field completeness of the best matching element. This is calculated as:
</p>
<p><code>max( (number of query terms matched in the element) /
(element size), 1.0)</code>.</p>
</td></tr>
<tr><td>elementCompleteness(<em>name</em>).queryCompleteness</td>
<td>0</td>
<td>
<p id="elementCompleteness(name).queryCompleteness">
The query completeness of the best matching element. This is calculated as:</p>
<p>
<code>(sum of weight for query terms matched in the element) /
(sum of weight for query terms searching the field)</code>.
</p>
</td></tr>
<tr><td>elementCompleteness(<em>name</em>).elementWeight</td>
<td>0</td>
<td><p id="elementCompleteness(name).elementWeight">
The weight of the best matching element, starting from the default - i.e., negative weights will return 0.
</p></td></tr>
<tr><td>elementSimilarity(<em>name</em>)</td>
<td>0</td>
<td>
<p id="elementSimilarity(name)">
Aggregated similarity between the query and individual field elements.
The same sub-scores used by the <code>textSimilarity</code> feature
are calculated for each individual element in the field.
The final output is calculated as the maximum of the combined element
similarity measures (similarity measures are combined the same way as
the default output of the <code>textSimilarity</code> feature)
multiplied with the element weight which is 1 for arrays,
and the supplied weights for indexed weighted sets.
</p>
<p>
This is a flexible feature;
how sub-scores are combined for each element and how element scores are aggregated may be configured.
You may also add additional outputs if you want to capture multiple signals from a single field.
Use <a href="rank-feature-configuration.html#elementSimilarity">elementSimilarity</a> to customize this feature.
</p>
</td></tr>
<tr><td colspan="3"></td></tr>
<tr><td colspan="3">
<h3 id="attribute-match-features-normalized">Attribute match features - normalized</h3></td></tr>
<tr class="trx"><th class="thx">Feature name</th><th class="thx">Default</th><th class="thx">Description</th></tr>
<tr><td>attributeMatch(<em>name</em>)</td>
<td>0</td>
<td>
<p id="attributeMatch(name)">
A normalized measure of the degree to which this query and field matched. This is currently the same as completeness.
Note that depending on what the attribute is used for, this may or may not be a suitable metric.
If the attribute is a weighted set representing counts of items (like tags),
<code>normalizedWeight</code> is probably a better metric.
</p>
</td></tr>
<tr><td>attributeMatch(<em>name</em>).completeness</td>
<td>0</td>
<td>
<p id="attributeMatch(name).completeness">
The normalized total completeness, where field completeness is more important:
</p><p>
<code>queryCompleteness * ( 1 - <a href="rank-feature-configuration.html#attributeMatch">fieldCompletenessImportance</a> +
<a href="rank-feature-configuration.html#attributeMatch">fieldCompletenessImportance</a> * fieldCompleteness )</code>
</p>
</td></tr>
<tr><td>attributeMatch(<em>name</em>).queryCompleteness</td>
<td>0</td>
<td>
<p id="attributeMatch(name).queryCompleteness">The query completeness for this attribute:</p>
<p><code>matches/the number of query terms searching this attribute</code></p></td></tr>
<tr><td>attributeMatch(<em>name</em>).fieldCompleteness</td>
<td>0</td>
<td>
<p id="attributeMatch(name).fieldCompleteness">
The normalized ratio of query tokens which was matched in the field.
For arrays: <code>matches/array length</code>
For weighted sets: <code>sum of weight of matched terms/sum of weights of entire set</code>.
This is relatively expensive to calculate for large weighted sets.
</p>
</td></tr>
<tr><td>attributeMatch(<em>name</em>).normalizedWeight</td>
<td>0</td>
<td>
<p id="attributeMatch(name).normalizedWeight">
A number which is close to 1 if the attribute weights of most matches in a weighted set are high
(relative to <a href="rank-feature-configuration.html#attributeMatch">maxWeight</a>), 0 otherwise
</p>
</td></tr>
<tr><td>attributeMatch(<em>name</em>).normalizedWeightedWeight</td>
<td>0</td>
<td>
<p id="attributeMatch(name).normalizedWeightedWeight">
A number which is close to 1 if the attribute weights of most matches in a weighted set are high
(relative to <a href="rank-feature-configuration.html#attributeMatch">maxWeight</a>),
and where highly weighted query terms has more impact, 0 otherwise
</p>
</td></tr>
<tr>
<td>closeness(<em>dimension</em>,<em>name</em>)</td>
<td>0</td>
<td><p id="closeness(dimension,name)">
Used with the <a href="../querying/yql.html#nearestneighbor">nearestNeighbor</a> query operator.
A number which is close to 1 when a point vector in the document is close
to a matching point vector in the query.
The document vectors and the query vector must be the same tensor
type, with one indexed dimension of size N, representing a point in an N-dimensional space.
</p>
<ul>
<li>
<p>
<em>dimension</em>: Specifies the dimension of <em>name</em>.
This must be either the string <code>field</code> or the string <code>label</code>.
</p>
<p>
When using <code>field</code>, the name given must be a field with a tensor attribute of appropriate type.
Often used when the document type has only one vector field,
see <a href="../../querying/nearest-neighbor-search#minimal-example">example</a>.
</p>
<p>
When using <code>label</code>, queries are assumed to contain a
<a href="../querying/yql.html#nearestneighbor">nearestNeighbor</a> query item
with a <a href="../querying/yql.html#label">label</a> that matches the given <em>name</em>.
This is useful when having multiple vector fields, where <code>closeness()</code> then maps
to the nearestNeighbor operator with the field configured.
<a href="../../querying/nearest-neighbor-search-guide#using-label">Example</a>.
</p>
</li>
<li> <em>name</em>: The value of the field name or label.
</li>
</ul>
<p>
{% include note.html content="<code>closeness()</code> is calculated <strong>only</strong> based on the vectors
matched with nearestNeighbor operator.
This means that the value of <code>closeness()</code> is not necessarily calculated based on the same vector
returned by <code>closest()</code> rank feature if nearestNeighbor search is approximate, as
<code>closest()</code> will be calculated based on <em>all</em> specified document vectors." %}
</p>
<p>
The output value is
$$ closeness(dimension,name) = \frac{1.0}{1.0 + distance(dimension,name)}$$
</p>
<p>
When the tensor field stores multiple vectors per document, the minimum distance
between the vectors of a document and the query vector is used in the calculation above.
</p>
</td></tr>
<tr><td>freshness(<em>name</em>)</td>
<td>0</td>
<td><p id="freshness(name)">
A number which is close to 1 if the timestamp in attribute <em>name</em> is recent compared to the current time
compared to <a href="rank-feature-configuration.html#freshness">maxAge</a>:
</p><p>
<code>max( 1-age(name)/maxAge , 0 )</code>
</p><p>
Scales linearly with age, see <a href="#freshness">freshness plot</a>.
</td></tr>
<tr><td>freshness(<em>name</em>).logscale</td>
<td>0</td>
<td><p id="freshness(name).logscale">
A logarithmic-shaped freshness; also goes from 1 to 0, but looks like <a href="#freshness">freshness plot</a>.
The function is based on <code>-log(age(name) + scale)</code> and is calculated as:
</p><p class="equation-container" class="equation-container"><!-- depends on mathjax -->
$$\frac{log(maxAge + scale) - log(age(name) + scale)}{log(maxAge + scale) - log(scale)}$$
</p><p>
where scale is defined using
<a href="rank-feature-configuration.html#freshness"> halfResponse and maxAge</a>:
</p><p class="equation-container" class="equation-container"><!-- depends on mathjax -->
$$\frac{-halfResponse^2}{2 × halfResponse - maxAge}$$
</p><p>
When <code>age(name) == halfResponse</code> the function output is 0.5.</p>
</td></tr>
<tr><td colspan="3"></td></tr>
<tr><td colspan="3"><h3 id="attribute-match-features-normalized-and-relative-to-the-whole-query">
Attribute match features - normalized and relative to the whole query</h3></td></tr>
<tr class="trx"><th class="thx">Feature name</th><th class="thx">Default</th><th class="thx">Description</th></tr>
<tr><td>attributeMatch(<em>name</em>).weight</td>
<td>0</td>
<td>
<p id="attributeMatch(name).weight">
This has the same semantics as fieldMatch(<em>name</em>).weight.
</p>
</td></tr>
<tr><td>attributeMatch(<em>name</em>).significance</td>
<td>0</td>
<td>
<p id="attributeMatch(name).significance">
This has the same semantics as fieldMatch(<em>name</em>).significance.
</p>
</td></tr>
<tr><td>attributeMatch(<em>name</em>).importance</td>
<td>0</td>
<td>
<p id="attributeMatch(name).importance">
Returns the average of significance and weight. This has the same properties as those metrics.
</p>
</td></tr>
<tr><td colspan="3"></td></tr>
<tr><td colspan="3">
<h3 id="attribute-match-features-not-normalized">Attribute match features - not normalized</h3></td></tr>
<tr class="trx"><th class="thx">Feature name</th><th class="thx">Default</th><th class="thx">Description</th></tr>
<tr><td>attributeMatch(<em>name</em>).matches</td>
<td>0</td>
<td><p id="attributeMatch(name).matches">The number of query terms which was matched in this attribute</p></td></tr>
<tr><td>attributeMatch(<em>name</em>).totalWeight</td>
<td>0</td>
<td>
<p id="attributeMatch(name).totalWeight">
The sum of the weights of the attribute keys matched in a weighted set attribute
</p>
</td></tr>
<tr><td>attributeMatch(<em>name</em>).averageWeight</td>
<td>0</td>
<td><p id="attributeMatch(name).averageWeight">totalWeight/matches</p></td></tr>
<tr><td>attributeMatch(<em>name</em>).maxWeight</td>
<td>0</td>
<td>
<p id="attributeMatch(name).maxWeight">
The maximum weight of the attribute keys matched in a weighted set attribute
</p>
</td></tr>
<tr><td>closest(<em>name</em>)</td>
<td>{}</td>
<td><p id="closest(name)">
Used with the
<a href="../querying/yql.html#nearestneighbor">nearestNeighbor</a>
query operator and a tensor field attribute <em>name</em> storing multiple vectors per document.
This feature returns a tensor with one or more mapped dimensions and one point with a value of 1.0,
where the label of that point indicates which document vector was closest to the
query vector in the nearest neighbor search.
</p>
<p>
Given a tensor field with type <code>tensor<float>(m{},x[3])</code>
used with the <em>nearestNeighbor</em> operator,
an example output of this feature is:
</p>
<pre>
tensor<float>(m{}):{ 3: 1.0 }
</pre>
<p>
In this example, the document vector with label <em>3</em> in the mapped <em>m</em> dimension