libs/simdvec/README.md
libs/simdvec provides optimized vector distance and scoring kernels used by
Elasticsearch's vector search (kNN, BBQ, scalar quantization). It contains both
Java-side Panama SIMD code and a native C++ library (libvec) with hand-tuned
SIMD kernels, loaded at runtime via FFI.
libs/simdvec/
├── src/ # Java module (org.elasticsearch.simdvec)
│ ├── main/java/ # Public API, scorer suppliers, and Panama SIMD paths
│ ├── test/ # Unit and scorer-level tests
│ └── testFixtures/ # Shared test utilities
├── native/ # Native C++ library (libvec)
│ ├── src/vec/c/
│ │ ├── aarch64/ # ARM kernels (NEON baseline, SVE in *_2.cpp)
│ │ └── amd64/ # x64 kernels (AVX2 baseline, AVX-512 in *_2.cpp)
│ ├── src/vec/headers/ # Shared and platform-specific headers
│ ├── Makefile # Cross-compilation build (all platforms)
│ └── Dockerfile.cross-toolchain
└── build.gradle # Gradle build config (multi-release JAR, JDK 21 coverage)
libs/native — Low-level Panama FFI bindings
VectorLibrary.java — interface declaring native function signaturesJdkVectorLibrary.java — Panama implementation, loads libvecVectorSimilarityFunctions.java — public facadeSource files follow a naming convention based on the ISA tier they target:
vec_1.cpp) — baseline: AVX2 on x64, NEON + dotprod on ARM.vec_2.cpp) — extended: AVX-512 (icelake) on x64, SVE on ARM.vec_bf16_3.cpp) — cooperlake on x64: adds vdpbf16ps for native BF16 dot product.At runtime, caps.cpp probes for CPU and OS support and the Java side selects
the appropriate tier.
The native kernels cover single-pair and bulk scoring for:
The native library is built via the Makefile in native/. For
cross-compilation of all three platform binaries (darwin-aarch64,
linux-aarch64, linux-x64), use the Docker-based toolchain:
# Build the cross-compilation toolchain image
./build_cross_toolchain_image.sh
# Build and publish binaries
./publish_vec_binaries.sh
For local development on the current platform:
cd native
make local # builds for the host platform
make install # copies the binary where Gradle tests expect it
make install places the library in
libs/native/libraries/build/platform/<os>-<arch>/ so that Gradle tests can
use it instead of fetching from Artifactory. Set LOCAL_VEC_BINARY_OS=true to
skip the Artifactory download:
make install
LOCAL_VEC_BINARY_OS=true ./gradlew :libs:simdvec:test
# Run simdvec tests (from repo root)
./gradlew :libs:simdvec:test
The Gradle build also runs a testJava21 task to verify runtime version guards
when running/testing with a JDK newer than 21.