|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: Memory-optimized search |
| 4 | +parent: Optimizing vector storage |
| 5 | +nav_order: 30 |
| 6 | +--- |
| 7 | + |
| 8 | +# Memory-optimized search |
| 9 | +Introduced 3.1 |
| 10 | +{: .label .label-purple } |
| 11 | + |
| 12 | +Memory-optimized search allows the Faiss engine to run efficiently without loading the entire vector index into off-heap memory. Without this optimization, Faiss typically loads the full index into memory, which can become unsustainable if the index size exceeds available physical memory. With memory-optimized search, the engine memory-maps the index file and relies on the operating system's file cache to serve search requests. This approach avoids unnecessary I/O and allows repeated reads to be served directly from the system cache. |
| 13 | + |
| 14 | +Memory-optimized search affects only search operations. Indexing behavior remains unchanged. |
| 15 | +{: .note } |
| 16 | + |
| 17 | +## Limitations |
| 18 | + |
| 19 | +The following limitations apply to memory-optimized search in OpenSearch: |
| 20 | +- Supported only for the [Faiss engine]({{site.url}}{{site.baseurl}}/field-types/supported-field-types/knn-methods-engines/#faiss-engine) with the [HNSW method]({{site.url}}{{site.baseurl}}/field-types/supported-field-types/knn-methods-engines/#hnsw-parameters-1) |
| 21 | +- Does not support [IVF]({{site.url}}{{site.baseurl}}/field-types/supported-field-types/knn-methods-engines/#ivf-parameters) or [product quantization (PQ)]({{site.url}}{{site.baseurl}}/vector-search/optimizing-storage/faiss-product-quantization) |
| 22 | +- Requires an index restart to enable or disable |
| 23 | + |
| 24 | +If you use IVF or PQ, the engine loads data into memory regardless of whether memory-optimized mode is enabled. |
| 25 | +{: .important } |
| 26 | + |
| 27 | +## Configuration |
| 28 | + |
| 29 | +To enable memory-optimized search, set `index.knn.memory_optimized_search` to `true` when creating an index: |
| 30 | + |
| 31 | +```json |
| 32 | +PUT /test_index |
| 33 | +{ |
| 34 | + "settings": { |
| 35 | + "index.knn": true, |
| 36 | + "index.knn.memory_optimized_search": true |
| 37 | + }, |
| 38 | + "mappings": { |
| 39 | + "properties": { |
| 40 | + "vector_field": { |
| 41 | + "type": "knn_vector", |
| 42 | + "dimension": 128, |
| 43 | + "method": { |
| 44 | + "name": "hnsw", |
| 45 | + "engine": "faiss" |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | +} |
| 51 | +``` |
| 52 | +{% include copy-curl.html %} |
| 53 | + |
| 54 | +To enable memory-optimized search on an existing index, you must close the index, update the setting, and then reopen the index: |
| 55 | + |
| 56 | +```json |
| 57 | +POST /test_index/_close |
| 58 | +``` |
| 59 | +{% include copy-curl.html %} |
| 60 | + |
| 61 | +```json |
| 62 | +PUT /test_index/_settings |
| 63 | +{ |
| 64 | + "index.knn.memory_optimized_search": true |
| 65 | +} |
| 66 | +``` |
| 67 | +{% include copy-curl.html %} |
| 68 | + |
| 69 | +```json |
| 70 | +POST /test_index/_open |
| 71 | +``` |
| 72 | +{% include copy-curl.html %} |
| 73 | + |
| 74 | +## Integration with disk-based search |
| 75 | + |
| 76 | +When you configure a field with `on_disk` mode and `1x` compression, memory-optimized search is automatically enabled for that field, even if memory optimization isn't enabled at the index level. For more information, see [Memory-optimized vectors]({{site.url}}{{site.baseurl}}/field-types/supported-field-types/knn-memory-optimized/). |
| 77 | + |
| 78 | + |
| 79 | +Memory-optimized search differs from [disk-based search]({{site.url}}{{site.baseurl}}/vector-search/optimizing-storage/disk-based-vector-search/) because it doesn't use compression or quantization. It only changes how vector data is loaded and accessed during search. |
| 80 | +{: .note } |
| 81 | + |
| 82 | +## Performance optimization |
| 83 | + |
| 84 | +When memory-optimized search is enabled, the [warm-up API]({{site.url}}{{site.baseurl}}/vector-search/performance-tuning-search/#warm-up-the-index) loads only the essential information needed for search operations, such as opening streams to the underlying Faiss index file. This minimal warm-up results in: |
| 85 | +- Faster initial searches. |
| 86 | +- Reduced memory overhead. |
| 87 | +- More efficient resource utilization. |
| 88 | + |
| 89 | +For fields where memory-optimized search is disabled, the warm-up process loads vectors into off-heap memory. |
| 90 | + |
| 91 | +## Next steps |
| 92 | + |
| 93 | +- [Disk-based vector search]({{site.url}}{{site.baseurl}}/vector-search/optimizing-storage/disk-based-vector-search/) |
| 94 | +- [Vector quantization]({{site.url}}{{site.baseurl}}/vector-search/optimizing-storage/knn-vector-quantization/) |
| 95 | +- [Performance tuning]({{site.url}}{{site.baseurl}}/vector-search/performance-tuning/) |
0 commit comments