I'm conducting a nested document search with Solr, obtaining the corresponding parent documents based on the vector distance of the child documents. So far so good. However, I want to display the vector distance score of the corresponding child-document in the [child] field of the parent documents, but all child-documents are showing a score of 0.
I've spent several days searching resources including the Solr Reference Guide, but I still haven't found the answer I need. Here is an example of the nested document in my Solr:
{
id: 1,
doc_type: "parent",
text: "sentence A. sentence B. sentence C."
children{[
{id: 2,doc_type: "child",text_piece: "sentence A.", embedding:[0.1,0.2,0.3...]},
{id: 3,doc_type: "child",text_piece: "sentence B.", embedding:[...]},
{id: 4,doc_type: "child",text_piece: "sentence C.", embedding:[...]}
]},
{
id: 5,
doc_type: "parent",
text: "sentence D. sentence E. "
children{[
{id: 6,doc_type: "child",text_piece: "sentence D.", embedding:[...]},
{id: 7,doc_type: "child",text_piece: "sentence E.", embedding:[...]},
]}
}
My query roughly looks like this:
q={!parent which='doc_type:parent' score=max}{!knn f=embedding topK=2}[0.2,0.1,-0.5,...]&fl=['*','score','[child]',[explain style=nl]']
translated from pysolr code, please ignore syntax errors if there is any
The results are as follows:
docs: [
{
id: 1,
doc_type: "parent",
text:"sentence A. sentence B. sentence C. ",
split_text:[
{id:2,text_piece:"sentence A.", score:0.0, embedding:[...], [explain]: {'match': False, 'value': 0.0, 'description': 'Not a match'}},
{id:3,text_piece:"sentence B.", score:0.0, embedding:[...], [explain]: {'match': False, 'value': 0.0, 'description': 'Not a match'}},
{id:4,text_piece:"sentence C.", score:0.0, embedding:[...], [explain]: {'match': False, 'value': 0.0, 'description': 'Not a match'}}]
[explain]: {'match': True, 'value': 0.849, 'description': 'Score based on 2 child docs in range from 129 to 130, using score mode Max', 'details': [{'match': True, 'value': 0.849,'description': 'within top 2'}]}
]
'Score based on 2 child docs in range from 129 to 130, using score mode Max'
The results above are just an example. Suppose the score of the sub-document with id=2 is 0.849, and the score of the sub-document with id=3 is 0.5, I hope these two scores can be displayed in their respective score fields.
Currently, I perform a two-step searche on the child-documents and parent documents, and then merge the results. Although I can get the results I need through this compromise method, it is accompanied by a decrease in performance and code readability. If you have a better method, please let me know. Thank you.