Hi all, I configured a reranking search pipeline to be used with knn search.
What I want to achieve is to first find 15 most relevant elements with knn search, and further rerank them to return the final 5 elements.
The query I used is:
response = client.search(
index="test_index",
search_pipeline="rerank_pipeline",
body={
"query": {
"knn": {
"embedding": {
"vector": vector,
"k": 15
}
}
},
"ext": {
"rerank": {
"query_context": {
"query_text": "architecture generation"
}
}
},
"size": 5,
}
)
The query_text “architecture generation” is a keyword that I identified from the last element if I only do knn search with k=15. Normally, with my query, it should rerank the last element to the first one.
But it turns out the elements that I got with my query are the same as I would get with
response1 = client.search(index= 'test_index',
body= {
"size": 5,
"query": {
"knn": {
'embedding': {
"vector": vector,
"k": 5,
}
}
}})
but reordered. And the element with “architecture generation” that I expect to see is not here.
What my query did is to retrieve 5 elements and rerank them, even though I specified k=15 for knn.
Am I missing something?
An alternative way is to use both k=15 and size=15 then post-process to keep the top 5. But I wonder if it is possible to achieve it without post-processing.
Thanks in advance.