{"record":{"id":"586cac4c44e27d5f","repo":"pola-rs/polars","slug":"arr-dot-query-vector-must-be-one-dimensional","errorCode":null,"errorMessage":"arr.dot query vector must be one-dimensional","messagePattern":"arr\\.dot query vector must be one-dimensional","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/expr/array.py","lineNumber":380,"sourceCode":"\n        Cast both inputs before ``dot`` to perform multiplication and accumulation in\n        a type that can represent the result.\n\n        >>> wide = pl.Array(pl.Int64, 2)\n        >>> a.cast(wide).arr.dot(b.cast(wide))\n        shape: (1,)\n        Series: 'a' [i64]\n        [\n            400\n        ]\n        \"\"\"\n        if isinstance(other, Sequence) and not isinstance(other, (str, bytes)):\n            other = list(other)\n            other = F.lit(other).list.to_array(len(other))\n        elif _check_for_numpy(other) and isinstance(other, np.ndarray):\n            if other.ndim != 1:\n                msg = \"arr.dot query vector must be one-dimensional\"\n                raise ValueError(msg)\n            other = F.lit(other).implode().list.to_array(other.size)\n\n        other_pyexpr = parse_into_expression(other)\n        return wrap_expr(self._pyexpr.arr_dot(other_pyexpr))\n\n    def std(self, ddof: int = 1) -> Expr:\n        \"\"\"\n        Compute the std of the values of the sub-arrays.\n\n        .. engine-support:: in-memory, streaming, distributed\n\n        Examples\n        --------\n        >>> df = pl.DataFrame(\n        ...     data={\"a\": [[1, 2], [4, 3]]},\n        ...     schema={\"a\": pl.Array(pl.Int64, 2)},\n        ... )\n        >>> df.select(pl.col(\"a\").arr.std())","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/expr/array.py#L362-L398","documentation":"Expr.arr.dot computes a dot product between each array row and a query vector. When the query is a numpy array it must be 1-D; a 2-D (or higher) ndarray cannot be interpreted as a single query vector, so a ValueError is raised.","triggerScenarios":"Calling df.select(pl.col('a').arr.dot(np_2d_array)) with an ndarray whose ndim != 1, e.g. a matrix of shape (n, m) or a batch of query vectors passed in one call.","commonSituations":"Passing embedding matrices or batched query vectors straight from numpy; forgetting to index/select one row of a 2-D array; reshaping changes elsewhere in the pipeline altering ndim.","solutions":["Flatten or select a single row: pass arr[0] or arr.reshape(-1) so ndim == 1","Loop over rows of a 2-D numpy array and call arr.dot once per query vector","Use the Sequence branch instead (a plain Python list is converted via list.to_array)","Assert other.ndim == 1 before the call"],"exampleFix":"// before\ncol.arr.dot(embedding_matrix)  # shape (768, 10)\n// after\ncol.arr.dot(embedding_matrix[:, 0])","handlingStrategy":"validation","validationCode":"if isinstance(q, np.ndarray) and q.ndim != 1:\n    raise ValueError('query vector must be 1-D')","typeGuard":"def is_1d_array(x) -> bool:\n    return isinstance(x, np.ndarray) and x.ndim == 1","tryCatchPattern":"try:\n    out = df.select(pl.col('a').arr.dot(q))\nexcept ValueError as e:\n    if 'one-dimensional' in str(e):\n        q = np.asarray(q).reshape(-1)\n        out = df.select(pl.col('a').arr.dot(q))\n    else:\n        raise","preventionTips":["Assert query.ndim == 1 before vector search calls","Index a specific row when working with batched embedding matrices","Prefer Python lists for single query vectors to get automatic conversion"],"tags":["python","polars","value-error","numpy","arrays"],"backgroundTag":"shape-mismatch","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}