{"record":{"id":"063fc0104f1bcfda","repo":"cocoindex-io/cocoindex","slug":"invalid-vector-dimension-dimension-063fc0","errorCode":null,"errorMessage":"Invalid vector dimension: {dimension}","messagePattern":"Invalid vector dimension: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/neo4j/_target.py","lineNumber":1284,"sourceCode":"            return dict(row)\n        record_info = RecordType(type(row))\n        return {f.name: getattr(row, f.name) for f in record_info.fields}\n\n    def declare_vector_index(\n        self: TableTarget[RowT],\n        *,\n        name: str | None = None,\n        field: str,\n        metric: Literal[\"cosine\", \"euclidean\"] = \"cosine\",\n        dimension: int,\n    ) -> None:\n        \"\"\"Declare a vector index on a column of this table.\"\"\"\n        _validate_identifier(field, \"vector index field\")\n        if name is None:\n            name = f\"vec_{self._table_name}__{field}\"\n        _validate_identifier(name, \"vector index name\")\n        if dimension <= 0:\n            raise ValueError(f\"Invalid vector dimension: {dimension}\")\n        spec = _VectorIndexSpec(field=field, metric=metric, dimension=dimension)\n        att_provider = self._provider.attachment(\"vector_index\")\n        coco.declare_target_state(att_provider.target_state(name, spec))\n\n    def __coco_memo_key__(self) -> str:\n        return self._provider.memo_key\n\n\n# ---------------------------------------------------------------------------\n# RelationTarget\n# ---------------------------------------------------------------------------\n\n\nclass RelationTarget(\n    Generic[RowT, coco.MaybePendingS], coco.ResolvesTo[\"RelationTarget[RowT]\"]\n):\n    \"\"\"A target for writing relation records (edges) to a Neo4j relationship type.\"\"\"\n","sourceCodeStart":1266,"sourceCodeEnd":1302,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/neo4j/_target.py#L1266-L1302","documentation":"declare_vector_index() validates that the vector dimension is a positive integer before creating the vector index target state; Neo4j vector indexes require a fixed positive dimension. A dimension <= 0 cannot map to any valid index.","triggerScenarios":"Calling table.declare_vector_index(field=..., dimension=0) or a negative value, typically when dimension is computed from an embedding config that failed to load or defaulted to 0.","commonSituations":"Embedding model dimension read from an uninitialized variable, config placeholder like dimension=0, or passing len([]) of an empty example embedding.","solutions":["Pass the actual embedding dimension, e.g. dimension=384 for all-MiniLM-L6-v2 or 1536 for OpenAI text-embedding-3-small.","Verify the value feeding `dimension` is not 0/None due to a failed config load before calling declare_vector_index."],"exampleFix":"// before\ntable.declare_vector_index(field=\"embedding\", metric=\"cosine\", dimension=0)\n// after\ntable.declare_vector_index(field=\"embedding\", metric=\"cosine\", dimension=384)","handlingStrategy":"validation","validationCode":"EMBED_DIM = 384  # must match your embedding model\nassert isinstance(EMBED_DIM, int) and EMBED_DIM > 0\ntable.declare_vector_index(field=\"embedding\", metric=\"cosine\", dimension=EMBED_DIM)","typeGuard":null,"tryCatchPattern":"try:\n    table.declare_vector_index(field=\"embedding\", metric=\"cosine\", dimension=dim)\nexcept ValueError as e:\n    raise ConfigError(f\"vector dimension must be positive, got {dim!r}\") from e","preventionTips":["Define the embedding dimension as a constant shared between the embedder config and declare_vector_index.","Never pass a computed/uninitialized value directly; assert it is a positive int first."],"tags":["neo4j","vector-index","validation"],"backgroundTag":"value-out-of-range","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"}