Insert a document, validating dimensions and (for MetaToken mode) vector count.
(&mut self, doc: MultiVectorDoc)
| 56 | |
| 57 | /// Insert a document, validating dimensions and (for MetaToken mode) vector count. |
| 58 | pub fn insert(&mut self, doc: MultiVectorDoc) -> Result<(), MultivecError> { |
| 59 | // Validate each vector's dimension. |
| 60 | for v in &doc.vectors { |
| 61 | if v.len() != self.dim { |
| 62 | return Err(MultivecError::DimMismatch { |
| 63 | expected: self.dim, |
| 64 | actual: v.len(), |
| 65 | }); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | // In MetaToken mode the count must equal k exactly. |
| 70 | if let MultiVecMode::MetaToken { k } = self.mode |
| 71 | && doc.vectors.len() != k as usize |
| 72 | { |
| 73 | return Err(MultivecError::MetaTokenCountMismatch { |
| 74 | expected: k, |
| 75 | actual: doc.vectors.len(), |
| 76 | }); |
| 77 | } |
| 78 | |
| 79 | self.docs.insert(doc.doc_id, doc); |
| 80 | Ok(()) |
| 81 | } |
| 82 | |
| 83 | /// Look up a document by ID. |
| 84 | pub fn get(&self, doc_id: u32) -> Option<&MultiVectorDoc> { |