Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
/claim #3333
Based on feedback from #4032, reduce the scope of the changes to just vector_storage, not change data_types::vectors::VectorElementType.
All changes within segment crate. Changes are not visible outside segment, qdrant builds and passes tests with segment/f16 feature.
Key Changes
f16 feature (adds half dependency).
Implement data_types::primitive::PrimitiveVectorElement for f16.
In vector_storage::vector_storage_base:
This is the type used in VectorStorageEnum:
Add new mod spaces::metric_f16 (feature f16). Implement spaces::Metric for all metrics.
For types::Distance, vector functions are generic:
These are called with both VectorElementType and VectorStorageElementType.
Implementers of vector_storage::query_scorer::QueryScorer and related functions are generic over TMetric: Metric (and VectorElementType as required). For example (vector_storage::raw_scorer):
This is because the query is VectorElementType, while vector_storage is VectorStorageElementType.
Test Failures
cargo test -p segment --features f16
Potentially these failures are due to rounding error with the reduced precision of f16.
Next Steps
In vector_storage::quantized::quantized_vectors::QuantizedVectors::create_impl:
quantization::encoded_vectors_u8::EncodedVectorsU8::encode takes f32 slices, which requires collecting f16 slices into a vec of f32 vecs. Could support f16 or otherwise minimize unnecessary allocation / copying.
segment::spaces::metric_f16 only has fallback implementations for Metrics. Support for avx, sse, and neon intrinsics should be straightforward. This was somewhat implemented in #4032.