{"record":{"id":"a260615b87ea8d9d","repo":"pathwaycom/pathway","slug":"primary-key-column-name-r-has-unsupported-type","errorCode":null,"errorMessage":"primary_key column {name!r} has unsupported type {dtype}; a Pinecone record id must be int or str.","messagePattern":"primary_key column (.+?) has unsupported type (.+?); a Pinecone record id must be int or str\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/io/pinecone/__init__.py","lineNumber":49,"sourceCode":"\ndef _check_primary_key_dtype(name: str, dtype: dt.DType) -> None:\n    \"\"\"Reject a ``primary_key`` whose type can never be a Pinecone record id.\n\n    The id must always be present and must be an ``int`` or ``str`` (a pointer\n    is accepted too, since the engine stringifies it). The matching runtime\n    guard (``PineconeError::InvalidId``) only fires once an offending row reaches\n    the sink, so catch the statically-known cases at ``write()`` time.\n    \"\"\"\n    if _is_statically_unknown(dtype):\n        return\n    if isinstance(dtype, dt.Optional):\n        raise ValueError(\n            f\"primary_key column {name!r} is nullable (type {dtype}); a Pinecone \"\n            \"record id must always be present, so the column cannot be optional.\"\n        )\n    if dtype in (dt.INT, dt.STR) or isinstance(dtype, dt.Pointer):\n        return\n    raise ValueError(\n        f\"primary_key column {name!r} has unsupported type {dtype}; a Pinecone \"\n        \"record id must be int or str.\"\n    )\n\n\ndef _is_sparse_pair(dtype: dt.DType) -> bool:\n    \"\"\"Whether ``dtype`` is the ``tuple[int, float]`` of a sparse (index, weight) pair.\"\"\"\n    return (\n        isinstance(dtype, dt.Tuple)\n        and len(dtype.args) == 2\n        and dtype.args[0] == dt.INT\n        and dtype.args[1] == dt.FLOAT\n    )\n\n\ndef _check_vector_dtype(name: str, dtype: dt.DType) -> None:\n    \"\"\"Reject a ``vector`` that is neither a dense nor a sparse vector column.\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/io/pinecone/__init__.py#L31-L67","documentation":"Pinecone record ids must be int or str (pointers are accepted because the engine stringifies them). pw.io.pinecone.write checks the primary_key column's dtype at call time and raises this ValueError for any other concrete type, mirroring the runtime PineconeError::InvalidId guard so a wrong column fails immediately rather than once data flows. Statically-unknown dtypes are not rejected here.","triggerScenarios":"Passing primary_key=table.col where col has a non-int/str dtype, e.g. float, bool, datetime, or a tuple/list column, to pw.io.pinecone.write.","commonSituations":"Using a UUID column typed as anything other than str; pointing primary_key at a timestamp or numeric-measure column by mistake; ids stored as float from JSON ingestion.","solutions":["Cast the id column to str before the sink, e.g. table.with_columns(id=table.id.astype(str)) or apply_windowed-free pw.this.transform.","Pick a column that is already int or str as the primary key.","If the id is a pointer column, that is fine as-is; otherwise convert floats/datetimes to their canonical string form."],"exampleFix":"# before\npw.io.pinecone.write(docs, \"idx\", primary_key=docs.float_id, vector=docs.vec)\n\n# after\ndocs = docs.with_columns(str_id=docs.float_id.astype(str))\npw.io.pinecone.write(docs, \"idx\", primary_key=docs.str_id, vector=docs.vec)","handlingStrategy":"type-guard","validationCode":"import pathway as pw\n\ndef ensure_pinecone_id_dtype(table, col_name: str):\n    dtype = table.schema[col_name].dtype\n    if dtype in (pw.dt.INT, pw.dt.STR) or isinstance(dtype, pw.dt.Pointer):\n        return table\n    return table.with_columns(**{col_name: table[col_name].astype(str)})","typeGuard":"import pathway as pw\n\ndef is_pinecone_id_dtype(dtype: pw.dt.DType) -> bool:\n    return dtype in (pw.dt.INT, pw.dt.STR) or isinstance(dtype, pw.dt.Pointer)","tryCatchPattern":"try:\n    pw.io.pinecone.write(docs, \"idx\", primary_key=docs.float_id, vector=docs.vec)\nexcept ValueError as e:\n    if \"unsupported type\" in str(e) and \"record id\" in str(e):\n        docs = docs.with_columns(id=docs.float_id.astype(str))\n        pw.io.pinecone.write(docs, \"idx\", primary_key=docs.id, vector=docs.vec)\n    else:\n        raise","preventionTips":["Standardize Pinecone ids as str (or int) at ingestion time.","Cast non-str ids (UUIDs, floats, datetimes) to their canonical string form before the sink.","Print table.schema.dtype for the key column when wiring a new sink to catch dtype surprises."],"tags":["pinecone","primary-key","dtype","vector-db","pathway"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}