Skip to content

Commit 338b858

Browse files
authored
Merge pull request #4668 from vespa-engine/kkraune/nan
Add more details for -Inf
2 parents b66b771 + e4c446f commit 338b858

2 files changed

Lines changed: 35 additions & 8 deletions

File tree

en/learn/faq.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,39 @@ The additional filters are applied as a post filtering
8181
step over the hits from the capped range query. *match-phase* on the other hand, is safe to use with filters or other query terms,
8282
and also supports diversification which the capped range query term does not support.
8383

84-
### What could cause the relevance field to be -Infinity
85-
The returned [relevance](../reference/querying/default-result-format.html#relevance) for a hit can become "-Infinity" instead
86-
of a double. This can happen in two cases:
84+
### What could cause the relevance field to be -Infinity?
85+
If a ranking profile produces NaNs or Infinities -
86+
which are impossible to represent as a number in JSON -
87+
the strings "Infinity" or "-Infinity", (NaN becomes "-Infinity") are returned in result sets,
88+
and client libraries might handle that by default (e.g., Golang).
89+
90+
The returned [relevance](../reference/querying/default-result-format.html#relevance)
91+
for a hit can become "-Infinity" instead of a double:
92+
93+
- The [ranking](../basics/ranking.html) expression used a feature which became `NaN` (Not a Number).
94+
For example, `log(0)` would produce `-Infinity`.
95+
Use [isNan](../reference/ranking/ranking-expressions.html#isnan-x) to guard against this.
96+
- Surfacing low scoring hits using [grouping](../querying/grouping.html), that is,
97+
rendering low ranking hits with `each(output(summary()))` that are outside what Vespa computed and caches on a heap.
98+
This is controlled by the [total-keep-rank-count](../reference/schemas/schemas.html#total-keep-rank-count) parameter.
99+
- Using unset fields in the ranking function
100+
101+
Resolve this by one or more of:
102+
103+
- Extend the client code to specifically handle these strings
104+
- Make sure the field is set to some value for all documents
105+
- Add a default value for the field when accessing it in your rank profile:
106+
`if (isNan(attribute(last_update)), 0, attribute(last_update))`
107+
- Add a final guard in the ranking expressions coercing to some small number,
108+
making non-finite scores sink to the bottom while remaining a valid number:
109+
```
110+
function finite_or_sentinel(x) {
111+
expression: if (isNan(x - x), -1e9, x)
112+
}
113+
```
114+
- Use CBOR instead of JSON - using a binary format can represent NaNs and Infinities without issues,
115+
and it can also be faster/more efficient
87116
88-
- The [ranking](../basics/ranking.html) expression used a feature which became `NaN` (Not a Number). For example, `log(0)` would produce
89-
-Infinity. One can use [isNan](../reference/ranking/ranking-expressions.html#isnan-x) to guard against this.
90-
- Surfacing low scoring hits using [grouping](../querying/grouping.html), that is, rendering low ranking hits with `each(output(summary()))` that are outside what Vespa computed and caches on a heap. This is controlled by the [total-keep-rank-count](../reference/schemas/schemas.html#total-keep-rank-count) parameter.
91117
92118
### How to pin query results?
93119
To hard-code documents to positions in the result set,

en/reference/querying/default-result-format.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,9 @@
362362
<td>Double</td>
363363
<td>
364364
<p id="relevance">Double value representing the rank score.
365-
The rank score is returned from the <a href="../../ranking/ranking-intro.html">rank-profile</a>'s
366-
first, second, or <a href="../../ranking/phased-ranking.html#using-a-global-phase-expression">global</a> phase.
365+
The rank score is returned from the <a href="../../ranking/ranking-intro.html">rank-profile</a>.
366+
See the <a href="../../learn/faq.html#what-could-cause-the-relevance-field-to-be--infinity">FAQ</a>
367+
for how to handle <code>"-Infinity"</code> (represented as string) values.
367368
</p>
368369
</td>
369370
</tr>

0 commit comments

Comments
 (0)