I have about 3.5M documents (approx index size 90G and it can grow upto 10x this size). I have a knn_vector
field A which is of 5000 dimensions and one other field B with 80 dimensions. I use the approx neighbors query as part of my filter query and that part for A takes about 60 to 90 seconds. when I replace the same query with the exact search of A, I get sub 200ms response time.
From what I observe, the exact search via script for A is much faster (<200ms) when compared to the approx search which is the opposite of what is expected.
When the same operations are performed for B, the results are as expected and latency is just about 30ms.
I run this on a i3.2xlarge
machine and have 10 shards spread across 3 nodes (Initially had 3 shards and increased up to 10 to see if there are improvements).
Sample query:
"query": {
"function_score": {
"query": {
"bool": {
"filter": [
{
"term": {
"filter1": "value1"
}
},
{
"knn":{
"A": {
"vector": [1,2,3...5k],
"k": 100
}
}],
functions: [
{
"script_score": {
"script": {
"lang": "knn",
"source": "knn_score",
"params": {
"field": "A",
"vector": [1,2,3,...5k],
"space_type": "l2"
}
}
}
}
]
}
}
}
}
The above example is a simplified version of what I’m trying to do. The exact search (script_score) will also have other features and we want to control the score by adjusting weights for each function. The plan was to do approximate search on the 5k dim vector and use the other features to boost but we didn’t expect this to happen.Can someone throw some light on what I need to do next and where to look?