Repository: meilisearch/meilisearch
File: crates/milli/src/update/new/indexer/write.rs (Rust)

Code before:
                            }));
                        }
                    },
                }
            }
            EntryHeader::ArroyDeleteVector(ArroyDeleteVector { docid }) => {
                for (_index, (_name, _embedder, writer, dimensions)) in arroy_writers {
                    let dimensions = *dimensions;
                    writer.del_items(wtxn, dimensions, docid)?;
                }
            }
            EntryHeader::ArroySetVectors(asvs) => {
                let ArroySetVectors { docid, embedder_id, .. } = asvs;
                let frame = frame_with_header.frame();
                let (_, _, writer, dimensions) =
                    arroy_writers.get(&embedder_id).expect("requested a missing embedder");
                let mut embeddings = Embeddings::new(*dimensions);
                let all_embeddings = asvs.read_all_embeddings_into_vec(frame, aligned_embedding);
                // FIXME: /!\ Case where number of embeddings is divisor of `dimensions` would still pass
                if *dimensions!= 0 && all_embeddings.len() % *dimensions != 0 {
                    return Err(Error::UserError(UserError::InvalidVectorDimensions {
                        expected: *dimensions,
                        found: all_embeddings.len(),
                    }));
                }
                embeddings.append(all_embeddings.to_vec()).unwrap();
                writer.del_items(wtxn, *dimensions, docid)?;
                writer.add_items(wtxn, docid, &embeddings)?;
            }
        }
    }

    Ok(())
}


Review comment (suggestion):
```suggestion
                if embeddings.append(all_embeddings.to_vec()).is_err() {
                    return Err(Error::UserError(UserError::InvalidVectorDimensions {
                        expected: *dimensions,
                        found: all_embeddings.len(),
                    }));
                }
```

Instead of rewriting the code inside of `embeddings.append` I would prefer that you just use the result it returns.

Code after:
                            }));
                        }
                    },
                }
            }
            EntryHeader::ArroyDeleteVector(ArroyDeleteVector { docid }) => {
                for (_index, (_name, _embedder, writer, dimensions)) in arroy_writers {
                    let dimensions = *dimensions;
                    writer.del_items(wtxn, dimensions, docid)?;
                }
            }
            EntryHeader::ArroySetVectors(asvs) => {
                let ArroySetVectors { docid, embedder_id, .. } = asvs;
                let frame = frame_with_header.frame();
                let (_, _, writer, dimensions) =
                    arroy_writers.get(&embedder_id).expect("requested a missing embedder");
                let mut embeddings = Embeddings::new(*dimensions);
                let all_embeddings = asvs.read_all_embeddings_into_vec(frame, aligned_embedding);
                if embeddings.append(all_embeddings.to_vec()).is_err() {
                    return Err(Error::UserError(UserError::InvalidVectorDimensions {
                        expected: *dimensions,
                        found: all_embeddings.len(),
                    }));
                }
                writer.del_items(wtxn, *dimensions, docid)?;
                writer.add_items(wtxn, docid, &embeddings)?;
            }
        }
    }

    Ok(())
}