From 8c649d8061a424852d8a040ed7726157c0dbcc19 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Thu, 9 Nov 2023 17:45:04 +0100 Subject: [PATCH] Throw error when the vector search is sent with the wrong size --- milli/src/search/new/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/milli/src/search/new/mod.rs b/milli/src/search/new/mod.rs index 361804426..6ceb78223 100644 --- a/milli/src/search/new/mod.rs +++ b/milli/src/search/new/mod.rs @@ -434,7 +434,18 @@ pub fn execute_search( let mut search = Search::default(); let docids = match ctx.index.vector_hnsw(ctx.txn)? { Some(hnsw) => { + if let Some(expected_size) = hnsw.iter().map(|(_, point)| point.len()).next() { + if vector.len() != expected_size { + return Err(UserError::InvalidVectorDimensions { + expected: expected_size, + found: vector.len(), + } + .into()); + } + } + let vector = NDotProductPoint::new(vector.clone()); + let neighbors = hnsw.search(&vector, &mut search); let mut docids = Vec::new();