(dims: MetadataDimensions)
| 113 | |
| 114 | impl From<MetadataDimensions> for Metadata { |
| 115 | fn from(dims: MetadataDimensions) -> Self { |
| 116 | let total = dims |
| 117 | .iter() |
| 118 | .map(|d| { |
| 119 | let x = *d as f32; |
| 120 | x * x |
| 121 | }) |
| 122 | .sum::<f32>(); |
| 123 | // @NOTE: As `MetadataDimensions` have high weight values, we |
| 124 | // need to handle overflow during intermediate addition when |
| 125 | // calculating the euclidean norm |
| 126 | let mag = total.min(f32::MAX).sqrt(); |
| 127 | Self { mag, mbits: dims } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | impl From<&QueryFilterDimensions> for Metadata { |