From 4bda6bb291bc1fd6a8cec7cc8b6f6a09662fd920 Mon Sep 17 00:00:00 2001 From: wycfirezdog Date: Fri, 21 Aug 2026 02:14:52 +0530 Subject: [PATCH] fix(router): raise ValueError for scalar embedding input instead of IndexError Fixes #69: Router.predict() raised IndexError when given a scalar embedding input. _to_embedding() returned a 0-D numpy array with shape=(), and accessing shape[-1] crashed with IndexError. Changes: - Add ndim == 0 check in _to_embedding() - Raise clear ValueError with helpful message for scalar inputs - Suggests reshaping to (1, -1) or passing a list --- src/tracer/runtime/router.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tracer/runtime/router.py b/src/tracer/runtime/router.py index e2dd959..fbe9428 100644 --- a/src/tracer/runtime/router.py +++ b/src/tracer/runtime/router.py @@ -101,7 +101,13 @@ def _to_embedding(self, input) -> np.ndarray: " router = tracer.load_router('.tracer', embedder=embedder)" ) return self.embedder.embed_one(input) - return np.asarray(input, dtype=np.float32) + arr = np.asarray(input, dtype=np.float32) + if arr.ndim == 0: + raise ValueError( + "embedding must be a 1-D array, got a scalar. " + "Reshape it to (1, -1) or pass a list." + ) + return arr def _to_embeddings(self, inputs) -> np.ndarray: """Convert inputs (list of texts or 2D array) to (n, dim) float32."""