rank-eval.asciidoc 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. [[java-rest-high-rank-eval]]
  2. === Ranking Evaluation API
  3. The `rankEval` method allows to evaluate the quality of ranked search
  4. results over a set of search request. Given sets of manually rated
  5. documents for each search request, ranking evaluation performs a
  6. <<java-rest-high-multi-search,multi search>> request and calculates
  7. information retrieval metrics like _mean reciprocal rank_, _precision_
  8. or _discounted cumulative gain_ on the returned results.
  9. [[java-rest-high-rank-eval-request]]
  10. ==== Ranking Evaluation Request
  11. In order to build a `RankEvalRequest`, you first need to create an
  12. evaluation specification (`RankEvalSpec`). This specification requires
  13. to define the evaluation metric that is going to be calculated, as well
  14. as a list of rated documents per search requests. Creating the ranking
  15. evaluation request then takes the specification and a list of target
  16. indices as arguments:
  17. ["source","java",subs="attributes,callouts,macros"]
  18. --------------------------------------------------
  19. include-tagged::{doc-tests}/SearchDocumentationIT.java[rank-eval-request-basic]
  20. --------------------------------------------------
  21. <1> Define the metric used in the evaluation
  22. <2> Add rated documents, specified by index name, id and rating
  23. <3> Create the search query to evaluate
  24. <4> Combine the three former parts into a `RatedRequest`
  25. <5> Create the ranking evaluation specification
  26. <6> Create the ranking evaluation request
  27. [[java-rest-high-rank-eval-sync]]
  28. ==== Synchronous Execution
  29. The `rankEval` method executes `RankEvalRequest`s synchronously:
  30. ["source","java",subs="attributes,callouts,macros"]
  31. --------------------------------------------------
  32. include-tagged::{doc-tests}/SearchDocumentationIT.java[rank-eval-execute]
  33. --------------------------------------------------
  34. [[java-rest-high-rank-eval-async]]
  35. ==== Asynchronous Execution
  36. The `rankEvalAsync` method executes `RankEvalRequest`s asynchronously,
  37. calling the provided `ActionListener` when the response is ready.
  38. ["source","java",subs="attributes,callouts,macros"]
  39. --------------------------------------------------
  40. include-tagged::{doc-tests}/SearchDocumentationIT.java[rank-eval-execute-async]
  41. --------------------------------------------------
  42. <1> The `RankEvalRequest` to execute and the `ActionListener` to use when
  43. the execution completes
  44. The asynchronous method does not block and returns immediately. Once it is
  45. completed the `ActionListener` is called back using the `onResponse` method
  46. if the execution successfully completed or using the `onFailure` method if
  47. it failed.
  48. A typical listener for `RankEvalResponse` looks like:
  49. ["source","java",subs="attributes,callouts,macros"]
  50. --------------------------------------------------
  51. include-tagged::{doc-tests}/SearchDocumentationIT.java[rank-eval-execute-listener]
  52. --------------------------------------------------
  53. <1> Called when the execution is successfully completed.
  54. <2> Called when the whole `RankEvalRequest` fails.
  55. ==== RankEvalResponse
  56. The `RankEvalResponse` that is returned by executing the request
  57. contains information about the overall evaluation score, the
  58. scores of each individual search request in the set of queries and
  59. detailed information about search hits and details about the metric
  60. calculation per partial result.
  61. ["source","java",subs="attributes,callouts,macros"]
  62. --------------------------------------------------
  63. include-tagged::{doc-tests}/SearchDocumentationIT.java[rank-eval-response]
  64. --------------------------------------------------
  65. <1> The overall evaluation result
  66. <2> Partial results that are keyed by their query id
  67. <3> The metric score for each partial result
  68. <4> Rated search hits contain a fully fledged `SearchHit`
  69. <5> Rated search hits also contain an `Optional<Interger>` rating that
  70. is not present if the document did not get a rating in the request
  71. <6> Metric details are named after the metric used in the request
  72. <7> After casting to the metric used in the request, the
  73. metric details offers insight into parts of the metric calculation