From 0d9ea7ff2238a6d744eb068ac5d8a00302bd347f Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Thu, 16 Mar 2023 11:48:59 -0400 Subject: [PATCH] Add reference to hybrid mmap extensions setting in k-NN (#3262) (#3477) * Add reference to hybrid mmap extensions setting in k-NN * Removed extra line * Reworded based on tech review * Update _search-plugins/knn/performance-tuning.md * Implemented editorial comments --------- (cherry picked from commit 492c9ec7323ab7b7c6a7b547dd18e7e4c4e4a50d) Signed-off-by: Fanit Kolchina Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] Co-authored-by: Naarcha-AWS <97990722+Naarcha-AWS@users.noreply.github.com> --- _search-plugins/knn/performance-tuning.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/_search-plugins/knn/performance-tuning.md b/_search-plugins/knn/performance-tuning.md index d179d99685..66b137b206 100644 --- a/_search-plugins/knn/performance-tuning.md +++ b/_search-plugins/knn/performance-tuning.md @@ -7,7 +7,7 @@ nav_order: 45 # Performance tuning -This topic provides performance tuning recommendations to improve indexing and search performance for approximate k-NN. From a high level, k-NN works according to these principles: +This topic provides performance tuning recommendations to improve indexing and search performance for approximate k-NN (ANN). From a high level, k-NN works according to these principles: * Native library indices are created per knn_vector field / (Lucene) segment pair. * Queries execute on segments sequentially inside the shard (same as any other OpenSearch query). * Each native library index in the segment returns <=k neighbors. @@ -82,6 +82,12 @@ Take the following steps to improve search performance: If your use case is simply to read the IDs and scores of the nearest neighbors, you can disable reading stored fields, which saves time retrieving the vectors from stored fields. +* **Use `mmap` file I/O** + + For the Lucene-based approximate k-NN search, there is no dedicated cache layer that speeds up read/write operations. Instead, the plugin relies on the existing caching mechanism in OpenSearch core. In versions 2.4 and earlier of the Lucene-based approximate k-NN search, read/write operations were based on Java NIO by default, which can be slow, depending on the Lucene version and number of segments per shard. Starting with version 2.5, k-NN enables [`mmap`](https://en.wikipedia.org/wiki/Mmap) file I/O by default when the store type is `hybridfs` (the default store type in OpenSearch). This leads to fast file I/O operations and improves the overall performance of both data ingestion and search. The two file extensions specific to vector values that use `mmap` are `.vec` and `.vem`. For more information about these file extensions, see [the Lucene documentation](https://lucene.apache.org/core/9_0_0/core/org/apache/lucene/codecs/lucene90/Lucene90HnswVectorsFormat.html). + + The `mmap` file I/O uses the system file cache rather than memory allocated for the Java heap, so no additional allocation is required. To change the default list of extensions set by the plugin, update the `index.store.hybrid.mmap.extensions` setting at the cluster level using the [Cluster Settings API]({{site.url}}{{site.baseurl}}/api-reference/cluster-api/cluster-settings). **Note**: This is an expert-level setting that requires closing the index before updating the setting and reopening it after the update. + ## Improving recall Recall depends on multiple factors like number of vectors, number of dimensions, segments, and so on. Searching over a large number of small segments and aggregating the results leads to better recall than searching over a small number of large segments and aggregating results. The larger the native library index, the more chances of losing recall if you're using smaller algorithm parameters. Choosing larger values for algorithm parameters should help solve this issue but sacrifices search latency and indexing time. That being said, it's important to understand your system's requirements for latency and accuracy, and then choose the number of segments you want your index to have based on experimentation.