cocoindex-io/cocoindex · error · ValueError

Column '{column}' not found in table schema: {list(self._tab

Error message

Column '{column}' not found in table schema: {list(self._table_schema.columns.keys())}

What it means

Raised by `declare_vector_index` when the requested column does not exist in the table's declared schema. The lookup `self._table_schema.columns.get(column)` returns None, and the error lists the valid column names to help identify the mistake.

Source

Thrown at python/cocoindex/connectors/postgres/_target.py:1347

        """
        Declare a pgvector index on a column of this table.

        The actual Postgres index will be named ``{table_name}__vector__{name}``.

        Args:
            name: Logical index name (defaults to ``column``).
            column: Column to index.
            metric: Distance metric ("cosine", "l2", or "ip").
            method: Index method ("ivfflat" or "hnsw").
            lists: Number of lists (ivfflat only).
            m: Maximum number of connections per layer (hnsw only).
            ef_construction: Size of the dynamic candidate list (hnsw only).
        """
        if name is None:
            name = column
        col_def = self._table_schema.columns.get(column)
        if col_def is None:
            raise ValueError(
                f"Column '{column}' not found in table schema: {list(self._table_schema.columns.keys())}"
            )
        spec = _VectorIndexSpec(
            column=column,
            metric=metric,
            op_class=_pgvector_op_class(column, col_def.type, metric),
            method=method,
            lists=lists,
            m=m,
            ef_construction=ef_construction,
        )
        att_provider = self._provider.attachment("vector_index")
        coco.declare_target_state(att_provider.target_state(name, spec))

    def declare_sql_command_attachment(
        self: "TableTarget[RowT]",
        *,
        name: str,

View on GitHub (pinned to e84aa99b32)

Solutions

  1. Read the valid column names from the error message and use one of them exactly.
  2. Add the embedding field to the table/row schema so the column is declared before declaring the index.
  3. Fix typos and match the case of the declared column name.
  4. Ensure declare_vector_index is called after the table schema (row type) is finalized, not on a modified copy.

Example fix

// before
table.declare_vector_index(column="embedding_vec", metric="cosine")
// after
table.declare_vector_index(column="embedding", metric="cosine")
Defensive patterns

Strategy: validation

Validate before calling

# before calling:
# if column not in table_schema.columns:
#     raise KeyError(f"{column} not in {list(table_schema.columns)}")

Type guard

def column_exists(schema, column: str) -> bool:
    return column in schema.columns

Try / catch

try:
    table.declare_vector_index(column=col, metric="cosine")
except ValueError as e:
    if "not found in table schema" in str(e):
        logger.error("Available columns: %s", str(e).rsplit(':', 1)[-1])
    else:
        raise

Prevention

When it happens

Trigger: Calling `table.declare_vector_index(column='embeddings', ...)` where 'embeddings' is not among the declared column names — typo, wrong singular/plural, or the vector column was never declared in the row dataclass/table schema.

Common situations: Renaming a field in the row dataclass but not in the index declaration; referencing the raw embedding column before it was declared; case mismatch on the column name.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of cocoindex-io/cocoindex@e84aa99b32 (2026-09-08). Data as JSON: /api/errors/99123cc74b6e0e66. Report an issue: GitHub.