Giter VIP home page Giter VIP logo

Comments (5)

johans1 avatar johans1 commented on April 29, 2024

make test

from vespa.

arnej27959 avatar arnej27959 commented on April 29, 2024

current behavior (via jackson's writeNumberField) is to render -inf as a string "-Infinity", which is legal JSON but not a number (as most users would expect).

I suggest rendering a number which is easy for a human to spot as an "invalid marker" (-1.0 or -999999999 for example). 0.0 is a valid (and common) actual relevance number so we should probably not use that.

from vespa.

vekterli avatar vekterli commented on April 29, 2024

Seems like using null is used for both NaN and +/-Infinity when emitting JSON in JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

I've also seen suggestions of using +/-1e9999 or similar massive exponents that will (most likely) implicitly roll over to infinity by the receiving parser. Pros: it's still a number. Cons: kinda smelly.

from vespa.

havardpe avatar havardpe commented on April 29, 2024

extra con for -1e9999: if the parser is try-hard you could end up with expensive handling of NaN/Inf values (BigDecimal and friends)

from vespa.

arnej27959 avatar arnej27959 commented on April 29, 2024

I think we should keep current behavior for now.

Fixing this specifically for relevance is easy, diff below. But we should probably wait until Vespa 8, or some customer really needs this fix. Since it's jackson that produces current behavior, it's possible/ that JSON consumers already has handling of it (or is willing to add that). If we make the change, we should also make sure to do it when rendering rank features and other structured data where doubles with possible overflows are rendered to JSON.

diff --git a/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java b/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java
index 31f8194..1e4233c 100644
--- a/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java
+++ b/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java
@@ -329,7 +329,13 @@ public class JsonRenderer extends AsynchronousSectionedRenderer<Result> {
         if (id != null)
             generator.writeStringField(ID, id);
 
-        generator.writeNumberField(RELEVANCE, hit.getRelevance().getScore());
+        generator.writeFieldName(RELEVANCE);
+        double rv = hit.getRelevance().getScore();
+        if (Double.isNaN(rv) || Double.isInfinite(rv)) {
+            generator.writeNull();
+        } else {
+            generator.writeNumber(rv);
+        }
 
         if (hit.types().size() > 0) {
             generator.writeArrayFieldStart(TYPES);

from vespa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.