🆕 Find the k-nearest neighbors (k-NN) for your vector data https://opensearch.org/docs/latest/search-plugins/knn/index/
  • Java 91%
  • C++ 8.3%
  • CMake 0.4%
  • C 0.2%
Find a file
Vikash Tiwari ed2214acc8
Reject NaN and infinite query vectors before native k-NN search (#3731)
A knn query vector with a NaN or infinite component reached native engine code unvalidated. Neither nmslib's
HNSW sort comparator nor Faiss's MinimaxHeap is NaN-safe, so one such search segfaulted the node (any user with
search access could crash it). Indexing already rejected NaN/Infinity; only the query paths did not.

Reject non-finite query vector components on both query paths, for every engine:
- KNNQueryBuilder.doToQuery: the float-vector branch now calls KNNValidationUtil.validateFloatVectorValue(float[]),
  the same NaN/Infinity check the byte/binary branches already run via validateByteVectorValue. This is the single
  chokepoint every knn query (k-NN and radial) and every engine funnels through before native search.
- KNNScoringSpaceUtil.convertVectorToPrimitive: the float knn_score path rejects NaN/Infinity too, so it returns a
  4xx instead of NaN scores. knn_score has its own vector parse and does not pass through doToQuery.

KNNValidationUtil gains a validateFloatVectorValue(float[]) overload (null is a no-op, otherwise each component is
checked) so callers validate a whole vector in one call.

Tests:
- KNNValidationUtilTests: the float[] overload for all-finite, NaN and infinity.
- KNNQueryBuilderTests: NaN and infinite float query vectors are rejected at doToQuery.
- KNNScriptScoringIT: knn_score rejects a non-finite vector with 4xx.
- NonFiniteQueryVectorIT (new): per engine a finite query returns 200, NaN and 1e39 query vectors return 400, and
  a finite query still returns 200 afterwards; nmslib is skipped where new-index creation is deprecated (3.0+).

Signed-off-by: Vikash Tiwari <viktari@amazon.com>
2026-12-02 08:51:39 -08:00
.github Increment version to 3.11.0-SNAPSHOT (#3697) 2026-11-19 13:40:38 -08:00
.idea Add simple IntelliJ debugger config (#2287) 2024-11-25 23:19:54 -08:00
benchmarks Remove benchmarks folder from k-NN repo (#2127) 2024-09-19 09:33:09 -07:00
build-tools Upgrade JaCoCo and ASM coverage dependencies (#3666) 2026-11-05 14:32:58 -08:00
buildSrc Switch checkstyle to spotless (#297) 2022-02-18 09:41:38 -08:00
gradle Guard eclipse() to spotless tasks and keep P2 mirror on pinned version (k-NN) (#3546) 2026-09-03 11:18:00 -07:00
jni Stop printing "JNIEnv not found" from Faiss OpenMP worker threads (#3708) 2026-11-18 10:50:32 -08:00
qa Add support for SQ 2 bit and 4 bit with Lucene engine (#3562) 2026-09-15 19:01:58 -07:00
release-notes Add release notes for 3.10.1 (#3715) (#3717) 2026-11-23 22:01:57 -05:00
remote-index-build-client Guard eclipse() to spotless tasks and keep P2 mirror on pinned version (k-NN) (#3546) 2026-09-03 11:18:00 -07:00
sandbox Add half_float as a vector data type for Flat and HNSW (#3578) 2026-09-18 08:26:35 -07:00
scripts Add SPDX license header checker and missing headers (#3532) 2026-09-04 08:47:06 -07:00
src Reject NaN and infinite query vectors before native k-NN search (#3731) 2026-12-02 08:51:39 -08:00
.codecov.yml Fix KNN build and run due to Lucene upgrade 10.4.0 (#3135) 2026-03-05 16:48:51 -08:00
.gitignore Clean JNI artifacts with ./gradlew clean (#2516) 2025-02-11 00:21:00 -06:00
.gitmodules Add faiss support in jni (#28) 2021-10-22 14:47:59 -07:00
.licenserc.json Switch license header checker to peterzhuamazon/license_checker_github_action (#3637) 2026-11-18 10:59:46 -08:00
.whitesource Track 2.19 as a Mend base branch (#3665) 2026-11-05 11:01:19 -08:00
ADMINS.md Add ADMINS.md 2021-06-23 15:48:16 -07:00
build.gradle Fix Windows JNI build with CMake 4.5.0 by passing -j to the build tool (#3713) 2026-11-23 21:32:57 -08:00
CHANGELOG.md Support multi-layer CAGRA HNSW graphs in memory-optimized search which descends from a deterministic entry point instead of starting from randomly selected points. (#3719) 2026-11-26 18:54:52 -08:00
CODE_OF_CONDUCT.md Update CODE_OF_CONDUCT 2021-04-16 09:14:53 -07:00
CONTRIBUTING.md Clarify changelog expectations for release notes (#3380) 2026-07-06 16:13:40 -07:00
DEVELOPER_GUIDE.md Added support for 1 bit SQ with remote build (#3270) 2026-04-17 13:59:55 -07:00
gradle.properties Bump default bwc version to 1.3.4 (#477) 2022-07-28 16:12:13 -07:00
GRADLE_GRAPH.md Added new gradle task validateLibraryUsage so that System.loadLibrary cannot be run outside of KNNLibraryLoader (#3033) 2025-12-18 13:29:55 -08:00
gradlew Gradle 9.2.0 and GitHub Actions JDK 25 Upgrade (#2984) 2025-11-24 14:21:25 -08:00
gradlew.bat Gradle 9.2.0 and GitHub Actions JDK 25 Upgrade (#2984) 2025-11-24 14:21:25 -08:00
LICENSE.txt Add windows support (#583) (#599) 2022-10-28 15:59:52 -05:00
lombok.config Adding lombok support (#393) 2022-05-11 17:15:32 -07:00
MAINTAINERS.md Adding kotwanikunal was the maintainer for KNN plugin (#3410) 2026-06-30 18:15:23 -04:00
NOTICE.txt Update license headers (#194) 2021-11-09 18:26:35 -06:00
README.md Update README.md (#2821) 2025-08-04 13:10:00 -04:00
RELEASING.md Refactor BWC framework into sub-projects (#362) 2022-04-18 11:11:59 -05:00
RFC.md Fix invalid url 2021-09-10 14:53:18 -07:00
SECURITY.md Updating security reachout email (#1700) 2024-05-15 09:23:06 -07:00
settings.gradle Add Intel SVS (Scalable Vector Search) as a sandbox tenant engine (#3551) 2026-09-08 15:37:22 -07:00
TRIAGING.md Update TRIAGING.md (#2749) 2025-06-12 18:43:33 -04:00

Build and Test k-NN codecov Documentation Chat PRs welcome!

OpenSearch k-NN

Welcome!

OpenSearch k-NN enables you to run the nearest neighbor search on billions of documents across thousands of dimensions with the same ease as running any regular OpenSearch query. You can use aggregations and filter clauses to further refine your similarity search operations. k-NN similarity search powers use cases such as product recommendations, fraud detection, image and video search, related document search, and more.

Project Resources

Credits and Acknowledgments

This project uses two similarity search libraries to perform Approximate Nearest Neighbor Search: the Apache 2.0-licensed Non-Metric Space Library and the MIT licensed Faiss library. Thank you to all who have contributed to those projects including Bilegsaikhan Naidan, Leonid Boytsov, Yury Malkov and David Novak for nmslib and Hervé Jégou, Matthijs Douze, Jeff Johnson and Lucas Hosseini for Faiss.

Code of Conduct

This project has adopted the Amazon Open Source Code of Conduct. For more information see the Code of Conduct FAQ, or contact opensource-codeofconduct@amazon.com with any additional questions or comments.

License

This project is licensed under the Apache v2.0 License.

Copyright OpenSearch Contributors. See NOTICE for details.