xai-org/x-algorithm · error · PyTypeError
rows must contain only 1-dim uint8 numpy arrays
Error message
rows must contain only 1-dim uint8 numpy arrays
What it means
PyTypeError raised by embedding_gather in the xai-recsys-engine Rust extension when one of the rows passed in is not a 1-dimensional numpy array of dtype uint8. Each element of rows is extracted to PyReadwriteArray1<'py, u8>; anything else (list, wrong dtype, 2-D array) fails extraction and triggers this error.
Source
Thrown at phoenix/crates/serving/xai-recsys-engine/src/emb_table.rs:414
Ok(())
}
#[pyfunction]
pub fn embedding_gather<'py>(
py: Python<'py>,
table: PyReadonlyArray1<'py, u8>,
row_indexes: PyReadonlyArray1<'py, u32>,
rows: Bound<'py, PyTuple>,
row_size: usize,
num_threads: usize,
) -> PyResult<()> {
let table_slice = table.as_slice()?;
let row_index_slice = row_indexes.as_slice()?;
let mut arrs: Vec<PyReadwriteArray1<'py, u8>> = Vec::with_capacity(rows.len());
let err = || PyTypeError::new_err("rows must contain only 1-dim uint8 numpy arrays");
for item in rows.iter() {
arrs.push(item.extract().map_err(|_| err())?);
}
let mut row_slices: Vec<&mut [u8]> = Vec::with_capacity(arrs.len());
for item in arrs.iter_mut() {
row_slices.push(item.as_slice_mut()?);
}
py.detach(|| {
embedding_gather_into(
table_slice,
row_index_slice,
&mut row_slices,
row_size,
num_threads,
)
})
.map_err(|e| PyValueError::new_err(e.0))
}
View on GitHub (pinned to 24c60942c5)
Solutions
- Ensure every element of rows is numpy 1-D with dtype uint8: np.asarray(row, dtype=np.uint8)
- Check for accidental 2-D arrays (shape (1, d)) — squeeze or index them to 1-D
- If you have float embeddings, quantize/cast them explicitly before calling
Example fix
# before rows = [emb.numpy() for emb in embs] # float32 # after rows = [np.asarray(emb, dtype=np.uint8) for emb in embs]
Defensive patterns
Strategy: type-guard
Validate before calling
import numpy as np rows = [np.asarray(r, dtype=np.uint8) for r in rows]
Type guard
def is_valid_rows(rows) -> bool:
return all(isinstance(r, np.ndarray) and r.dtype == np.uint8 and r.ndim == 1 for r in rows) Try / catch
try: embedding_gather(rows, ...) except TypeError as e: raise ValueError('rows must be 1-D uint8 arrays') from e Prevention
- Standardize a to_uint8_vector() helper for all embedding preparation
- Add asserts on dtype/ndim in data pipeline tests
When it happens
Trigger: Calling emb_table.embedding_gather(rows, ...) where rows contains a Python list, a numpy array with dtype != uint8 (e.g. float32/int64), or a multi-dimensional array instead of np.array(..., dtype=np.uint8) 1-D vectors.
Common situations: Feeding embeddings produced by a float model directly; converting from torch tensors with .numpy() without casting to uint8; accidentally passing row indexes or nested lists.
Related errors
- Unsupported emb_table dtype: {embeddings.dtype}
- {key}: got {arr.shape}/{arr.dtype}, manifest says {meta['sha
- Only bfloat16 is supported for keys.
- {name} must have dtype torch.int32
- Type mismatch: {self.q_dtype} != {self.k_dtype}
AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28).
Data as JSON: /api/errors/0cc2ba200c351e0a.
Report an issue: GitHub.