Object-safe trait for asymmetric rerank codecs. Each impl wraps an existing `nodedb-codec::VectorCodec` and exposes a uniform shape so the sidecar can hold `Arc ` regardless of the underlying associated-type machinery.
| 46 | /// hold `Arc<dyn RerankCodec>` regardless of the underlying associated-type |
| 47 | /// machinery. |
| 48 | pub trait RerankCodec: Send + Sync { |
| 49 | /// Encode a full-precision vector. Returns fixed-width bytes for this codec. |
| 50 | fn encode(&self, v: &[f32]) -> Result<Vec<u8>, RerankError>; |
| 51 | |
| 52 | /// Prepare a query once before repeated distance calls. |
| 53 | fn prepare_query(&self, q: &[f32]) -> Result<PreparedQuery, RerankError>; |
| 54 | |
| 55 | /// Compute asymmetric distance from a prepared query to an encoded vector. |
| 56 | fn distance_prepared( |
| 57 | &self, |
| 58 | prepared: &PreparedQuery, |
| 59 | encoded: &[u8], |
| 60 | ) -> Result<f32, RerankError>; |
| 61 | |
| 62 | /// Identity tag for mismatch detection. |
| 63 | fn name(&self) -> CodecName; |
| 64 | |
| 65 | /// Train from a sample of vectors. Default no-op for codecs that don't need |
| 66 | /// training (e.g. Binary). Specific codec impls override this when needed. |
| 67 | fn train(&mut self, _samples: &[&[f32]]) -> Result<(), RerankError> { |
| 68 | Ok(()) |
| 69 | } |
| 70 | |
| 71 | /// Serialize trained state to bytes. Each codec uses its own magic header |
| 72 | /// (NDSQ / NDBIN / NDPQ / NDRBQ / NDBBQ). The bytes are codec-specific; |
| 73 | /// `rerank_codec_from_bytes` is used for restore, paired with `name()`. |
| 74 | fn to_bytes(&self) -> Result<Vec<u8>, RerankError>; |
| 75 | } |
| 76 | |
| 77 | /// Reconstruct a `RerankCodec` from its byte form. The `name` tag tells us |
| 78 | /// which wrapper to dispatch into; the bytes are the codec's own format. |
nothing calls this directly
no outgoing calls
no test coverage detected