{"record":{"id":"c2d4f8c269019996","repo":"cocoindex-io/cocoindex","slug":"invalid-vector-dimension-dimension-c2d4f8","errorCode":null,"errorMessage":"Invalid vector dimension: {dimension}","messagePattern":"Invalid vector dimension: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/neo4j/_cypher.py","lineNumber":255,"sourceCode":"    \"\"\"``DROP CONSTRAINT <name> IF EXISTS``.\"\"\"\n    return f\"DROP CONSTRAINT {_quote(name)} IF EXISTS\"\n\n\ndef build_vector_index_create(\n    name: str,\n    label: str,\n    field: str,\n    dimension: int,\n    metric: str,\n) -> str:\n    \"\"\"``CREATE VECTOR INDEX <name> IF NOT EXISTS FOR (n:`Label`) ON n.`field` OPTIONS {...}``.\n\n    ``metric`` is the Neo4j ``vector.similarity_function`` value\n    (``\"cosine\"`` or ``\"euclidean\"``). Caller is responsible for translating\n    user-facing names into the Neo4j vocabulary before invoking.\n    \"\"\"\n    if dimension <= 0:\n        raise ValueError(f\"Invalid vector dimension: {dimension}\")\n    return (\n        f\"CREATE VECTOR INDEX {_quote(name)} IF NOT EXISTS \"\n        f\"FOR (n:{_quote(label)}) ON n.{_quote(field)} \"\n        f\"OPTIONS {{ indexConfig: {{ \"\n        f\"`vector.dimensions`: {int(dimension)}, \"\n        f\"`vector.similarity_function`: '{metric}' }} }}\"\n    )\n\n\ndef build_vector_index_drop(name: str) -> str:\n    \"\"\"``DROP INDEX <name> IF EXISTS``.\n\n    Vector indexes share the index namespace; the same DROP works.\n    \"\"\"\n    return f\"DROP INDEX {_quote(name)} IF EXISTS\"\n","sourceCodeStart":237,"sourceCodeEnd":271,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/neo4j/_cypher.py#L237-L271","documentation":"This ValueError is raised by build_vector_index_create when the vector dimension is zero or negative. Neo4j vector indexes require vector.dimensions to be a positive integer in the indexConfig options. The library rejects invalid dimensions before emitting the CREATE VECTOR INDEX statement.","triggerScenarios":"Calling build_vector_index_create with dimension=0 or a negative value — e.g. a dimension read from an uninitialized embedding config, a defaulted-to-zero variable, or a VectorSchemaProvider whose size was never set.","commonSituations":"Embedding model dimension not yet configured (placeholder 0); reading dimension from a config file with a missing/zero value; arithmetic computing dimension (e.g. dim * scale) yielding 0 or negative.","solutions":["Pass the actual embedding dimension, e.g. 384 or 1536.","Validate dimension > 0 at config load time before calling.","Ensure the VectorSchemaProvider/dimension source is initialized before index creation."],"exampleFix":"// before\nbuild_vector_index_create(\"vec_idx\", \"Document\", \"embedding\", 0, \"cosine\")\n// after\nbuild_vector_index_create(\"vec_idx\", \"Document\", \"embedding\", 768, \"cosine\")","handlingStrategy":"validation","validationCode":"if not isinstance(dimension, int) or dimension <= 0:\n    raise ValueError(f\"embedding dimension must be a positive int, got {dimension!r}\")\nbuild_vector_index_create(name, label, field, dimension, metric)","typeGuard":null,"tryCatchPattern":"try:\n    stmt = build_vector_index_create(name, label, field, dim, metric)\nexcept ValueError as e:\n    raise RuntimeError(\"vector index misconfigured: embedding dimension unset\") from e","preventionTips":["Load the embedding model before reading its dimension for config","Centralize the dimension constant rather than scattering literals","Validate dimension at app startup, not at index creation"],"tags":["neo4j","vector-index","validation","dimension"],"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"}