{"record":{"id":"3021df6e572873f3","repo":"cocoindex-io/cocoindex","slug":"partition-key-columns-not-in-schema-invalid-part","errorCode":null,"errorMessage":"Partition key columns not in schema: {invalid_partition}","messagePattern":"Partition key columns not in schema: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/sqlite/_target.py","lineNumber":1142,"sourceCode":"    managed_conn: ManagedConnection,\n) -> None:\n    \"\"\"Validate vec0 virtual table configuration.\"\"\"\n    if _VEC_EXTENSION not in managed_conn.loaded_extensions:\n        raise RuntimeError(\n            \"sqlite-vec extension must be loaded for vec0 virtual tables. \"\n            \"Use connect(..., load_vec=True)\"\n        )\n    has_vector_col = any(\n        col_def.type.startswith(\"float[\") for col_def in table_schema.columns.values()\n    )\n    if not has_vector_col:\n        raise ValueError(\n            \"vec0 virtual tables require at least one float[N] vector column\"\n        )\n    all_cols = set(table_schema.columns.keys())\n    invalid_partition = set(virtual_table_def.partition_key_columns) - all_cols\n    if invalid_partition:\n        raise ValueError(f\"Partition key columns not in schema: {invalid_partition}\")\n    invalid_aux = set(virtual_table_def.auxiliary_columns) - all_cols\n    if invalid_aux:\n        raise ValueError(f\"Auxiliary columns not in schema: {invalid_aux}\")\n    if len(table_schema.primary_key) != 1:\n        raise ValueError(\n            f\"vec0 virtual tables require exactly one primary key column, \"\n            f\"got {len(table_schema.primary_key)}: {table_schema.primary_key}\"\n        )\n    pk_col_name = table_schema.primary_key[0]\n    pk_col_type = table_schema.columns[pk_col_name].type\n    if pk_col_type != \"INTEGER\":\n        raise ValueError(\n            f\"vec0 virtual tables require INTEGER primary key, \"\n            f\"got {pk_col_type} for column '{pk_col_name}'\"\n        )\n\n\ndef table_target(","sourceCodeStart":1124,"sourceCodeEnd":1160,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/sqlite/_target.py#L1124-L1160","documentation":"The SQLite vec0 virtual table declares partition key columns, but the table schema does not contain columns with those names. CocoIndex validates the vec0 configuration against the declared schema before creating the virtual table, so a partition column that is not a real schema column is rejected up front instead of failing inside sqlite-vec.","triggerScenarios":"Calling table_target() for a SQLite vec0 table whose VirtualTableDef.partition_key_columns references a column name not present in the provided table schema's columns mapping (typo, renamed column, or column removed from the schema).","commonSituations":"Renaming or removing a partition column from the record schema but forgetting to update partition_key_columns; hand-building a VirtualTableDef with stale column names; mismatch between typed row model fields and the explicit schema passed to table_target.","solutions":["Add the missing column(s) to the table schema (or the record type it derives from) so every partition key column exists.","Fix partition_key_columns to reference only existing schema column names (check spelling).","Remove obsolete partition key column entries if the column is no longer needed."],"exampleFix":"// before\nschema = table_schema(columns=[\"id\", \"embedding\"], partition_key_columns=[\"folder\"])\n// after\nschema = table_schema(columns=[\"id\", \"embedding\", \"folder\"], partition_key_columns=[\"folder\"])","handlingStrategy":"validation","validationCode":"invalid = set(partition_key_columns) - set(schema.columns)\nif invalid:\n    raise ValueError(f\"partition columns missing from schema: {invalid}\")","typeGuard":"def valid_partition_keys(schema, keys) -> bool:\n    return all(k in schema.columns for k in keys)","tryCatchPattern":"try:\n    target = table_target(schema, virtual_table_def)\nexcept ValueError as e:\n    if \"Partition key columns not in schema\" in str(e):\n        # fix schema or partition_key_columns before retrying\n        ...","preventionTips":["Derive partition_key_columns programmatically from the schema fields rather than hardcoding strings.","Rename columns via a single source of truth so partition definitions stay in sync.","Add a unit test asserting schema consistency before table creation."],"tags":["sqlite","schema-validation","vec0","config"],"backgroundTag":"schema-validation-failed","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}