- Newest
- Most votes
- Most comments
Based on the current architecture of k-NN in Amazon OpenSearch Service, segment replication is the primary and most effective mitigation for ensuring consistent k-NN results between primary and replica shards.
Your analysis is correct: the inconsistency you're observing stems from the non-deterministic nature of HNSW graph construction. When using document replication (the default), each shard copy independently builds its own HNSW graph from the same documents, and even with identical data, the graph structure can vary slightly, leading to different traversal paths and result counts during approximate nearest neighbor searches.
While tuning HNSW parameters like ef_search, ef_construction, and m can improve overall recall quality and reduce approximation error, these parameters do not make the graph construction process deterministic. Higher values may bring results closer together across shards, but they won't guarantee identical results when each shard builds its own independent graph.
Unfortunately, there are no other documented mitigations in Amazon OpenSearch Service that can guarantee result consistency across primary and replica shards for k-NN queries besides segment replication. The fundamental issue is that as long as each shard copy builds its own graph independently, some degree of variation is inherent to the approximate nature of HNSW.
If the trade-offs of segment replication (increased network usage, potential replication lag, and higher primary node load) are concerns for your use case, you would need to accept some level of result inconsistency as a characteristic of approximate nearest neighbor search with independent graph construction. However, segment replication remains the recommended approach when result consistency is a critical requirement for your application.
Sources
Amazon OpenSearch Service 101: How many shards do I need | AWS Big Data Blog
k-Nearest Neighbor (k-NN) search in Amazon OpenSearch Service - Amazon OpenSearch Service
Relevant content
- asked 4 months ago
- asked a year ago
