We try to use the ANN (Approximate Nearest Neighbor) feature of the 8.0 Version of Elasticsearch. (k-nearest neighbor (kNN) search | Elasticsearch Guide [8.1] | Elastic)
At the moment we have indexed 16 million documents
Index a: ~6Mio
Index b: ~10Mio
We created the index using the following mapping
{
"mappings": {
"properties": {
"vector": {
"type": "dense_vector",
"dims": 768,
"index": true,
"similarity": "l2_norm"
}
}
}
}
And the following query to retrieve the ann results
POST a/_knn_search
{
"knn": {
"field": "vector",
"query_vector": [
0.5619577,
-1.7599238,
...
],
"k": 100,
"num_candidates": 1000
},
"_source": ["id", "documentParts.title"]
}
The setup is in a cloud environment where we currently have
- 8 VCPUs
- 128GBs of RAM
- 2TB of SSD storage
On the virtual machine I have set up a Kibana and ES using docker-compose (GitHub - deviantony/docker-elk: The Elastic stack (ELK) powered by Docker and Compose.)
including the following env
environment:
- "ES_JAVA_OPTS=-Xmx64g -Xms64g"
This setup worked quite fine and we were happy with the response times. (1-6 seconds for k=50 ANN)
So now we tried to do the same with cosine
instead of l2_norm
.
{
"mappings": {
"properties": {
"vector": {
"type": "dense_vector",
"dims": 768,
"index": true,
"similarity": "cosine"
}
}
}
}
We reindex all the data on the same machine and now we have 32 Mio docs.
Index a: ~6Mio
Index b: ~10Mio
Index a_cos: ~6Mio
Index b_cos: ~10Mio
Now we constantly get timeouts for the requests that worked perfectly before.
Error 504 (Gateway Timeout)
Why is it not working anymore?
What changed?
How can I debug this?
Is there a potential solution?
Thanks a lot