{"record":{"id":"0cc2ba200c351e0a","repo":"xai-org/x-algorithm","slug":"rows-must-contain-only-1-dim-uint8-numpy-arrays","errorCode":null,"errorMessage":"rows must contain only 1-dim uint8 numpy arrays","messagePattern":"rows must contain only 1-dim uint8 numpy arrays","errorType":"validation","errorClass":"PyTypeError","httpStatus":null,"severity":"error","filePath":"phoenix/crates/serving/xai-recsys-engine/src/emb_table.rs","lineNumber":414,"sourceCode":"    Ok(())\n}\n\n#[pyfunction]\npub fn embedding_gather<'py>(\n    py: Python<'py>,\n    table: PyReadonlyArray1<'py, u8>,\n    row_indexes: PyReadonlyArray1<'py, u32>,\n    rows: Bound<'py, PyTuple>,\n    row_size: usize,\n    num_threads: usize,\n) -> PyResult<()> {\n    let table_slice = table.as_slice()?;\n    let row_index_slice = row_indexes.as_slice()?;\n\n    let mut arrs: Vec<PyReadwriteArray1<'py, u8>> = Vec::with_capacity(rows.len());\n    let err = || PyTypeError::new_err(\"rows must contain only 1-dim uint8 numpy arrays\");\n    for item in rows.iter() {\n        arrs.push(item.extract().map_err(|_| err())?);\n    }\n    let mut row_slices: Vec<&mut [u8]> = Vec::with_capacity(arrs.len());\n    for item in arrs.iter_mut() {\n        row_slices.push(item.as_slice_mut()?);\n    }\n\n    py.detach(|| {\n        embedding_gather_into(\n            table_slice,\n            row_index_slice,\n            &mut row_slices,\n            row_size,\n            num_threads,\n        )\n    })\n    .map_err(|e| PyValueError::new_err(e.0))\n}\n","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/phoenix/crates/serving/xai-recsys-engine/src/emb_table.rs#L396-L432","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nrows = [emb.numpy() for emb in embs]  # float32\n# after\nrows = [np.asarray(emb, dtype=np.uint8) for emb in embs]","handlingStrategy":"type-guard","validationCode":"import numpy as np\nrows = [np.asarray(r, dtype=np.uint8) for r in rows]","typeGuard":"def is_valid_rows(rows) -> bool:\n    return all(isinstance(r, np.ndarray) and r.dtype == np.uint8 and r.ndim == 1 for r in rows)","tryCatchPattern":"try: embedding_gather(rows, ...) except TypeError as e: raise ValueError('rows must be 1-D uint8 arrays') from e","preventionTips":["Standardize a to_uint8_vector() helper for all embedding preparation","Add asserts on dtype/ndim in data pipeline tests"],"tags":["numpy","dtype","pyo3","rust-extension"],"backgroundTag":"numpy-dtype-mismatch","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}