apache / apache/lucene

Create a generic method in the Explanation class to get explanation attributes [LUCENE-8647]

Open
#9,693 1 comment 0 reactions 0 assignees View on GitHub
affects-version:7.5 legacy-jira-priority:Minor module:core/search type:enhancement
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

Initial proposal and discussion can be found here - 

 

 

Currently the Explanation class has a toString method, but it doesn't seem to have any method to output the explanation as a NamedList. Part of the reason is that NamedList is a Solr only concept and it cannot exist in lucene. But this leads to utility functions like ( and which assume a particular structure about explanations.

 

Explanation should instead have a toMap method which returns a Map of key-value pairs which can then be converted to a NamedList in Solr. This can be exceptionally useful if we have a class inheriting from Explanation that adds more attributes.

 

For example for Learning to Rank model explanations we can have a ModelExplanation class which adds doc-specific feature scores and other machine learning model explanations to the output. It also allows the ExplainAugmenter and other classes to have a more generic way of getting an Explanation's data in a structured format.

 

The way it currently does so is very ugly -

 

This also implies that we shouldn't keep Explanation as a final class anymore. Storing and parsing things like feature values in the explanation description doesn't seem like the right way.

---
Migrated from [LUCENE-8647](https://issues.apache.org/jira/browse/LUCENE-8647) by Sambhav Kothari (@samj1912)

Contributor guide

Open the contributing guide

Research direction

Start by reading the Explanation class and its existing toString method, then inspect Solr's ExplainAugmenterFactory.java and SolrPluginUtils.java references to the current explanation structure. Review the linked Lucene-Java user discussion and consider how a generic Map representation and subclassing would support ModelExplanation. Done means an agreed API design with compatible Lucene and Solr usage, implementation, and coverage for structured explanation attributes.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.