{"record":{"id":"f6b9a6a56f1ac556","repo":"cocoindex-io/cocoindex","slug":"invalid-vector-dimension-dimension","errorCode":null,"errorMessage":"Invalid vector dimension: {dimension}","messagePattern":"Invalid vector dimension: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/falkordb/_cypher.py","lineNumber":187,"sourceCode":"        raise ValueError(\"build_relationship_index_drop requires at least one field\")\n    field_list = \", \".join(f\"e.{_quote(f)}\" for f in fields)\n    return f\"DROP INDEX FOR ()-[e:{_quote(rel_type)}]-() ON ({field_list})\"\n\n\ndef build_vector_index_create(\n    label: str,\n    field: str,\n    dimension: int,\n    metric: str,\n) -> str:\n    \"\"\"``CREATE VECTOR INDEX FOR (e:`Label`) ON (e.`field`) OPTIONS {...}``.\n\n    ``metric`` is the FalkorDB-side ``similarityFunction`` value\n    (e.g. ``\"cosine\"``, ``\"euclidean\"``). Caller is responsible for translating\n    user-facing names into the FalkorDB vocabulary before invoking.\n    \"\"\"\n    if dimension <= 0:\n        raise ValueError(f\"Invalid vector dimension: {dimension}\")\n    return (\n        f\"CREATE VECTOR INDEX FOR (e:{_quote(label)}) ON (e.{_quote(field)}) \"\n        f\"OPTIONS {{dimension: {int(dimension)}, similarityFunction: '{metric}'}}\"\n    )\n\n\ndef build_vector_index_drop(label: str, field: str) -> str:\n    \"\"\"``DROP VECTOR INDEX FOR (e:`Label`) ON (e.`field`)``.\n\n    Confirmed via spike against FalkorDB latest: the DROP statement does NOT\n    take an index name — it identifies the index by (label, field).\n    \"\"\"\n    return f\"DROP VECTOR INDEX FOR (e:{_quote(label)}) ON (e.{_quote(field)})\"\n","sourceCodeStart":169,"sourceCodeEnd":201,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/falkordb/_cypher.py#L169-L201","documentation":"build_vector_index_create() validates that the vector index dimension is a positive integer and raises for dimension <= 0. FalkorDB's VECTOR index requires a positive dimension option; a non-positive value would produce an invalid or meaningless index, so the library rejects it up front.","triggerScenarios":"Calling build_vector_index_create with dimension=0, a negative number, or a dimension resolved from an uninitialized variable — e.g. embedding model metadata that hasn't been loaded yet.","commonSituations":"Embedding dimension not yet known when the index is declared (model loaded lazily, dimension defaults to 0); misconfigured vector field spec; copying a template and leaving dimension unset.","solutions":["Set dimension to the embedding model's output size (e.g. 384 for all-MiniLM-L6-v2, 1536 for OpenAI text-embedding-3-small).","Ensure the embedding model is initialized before declaring the vector index so its dimension is available.","Add a caller-side check that dimension is a positive int before invoking the builder."],"exampleFix":"// before\ndimension = 0  # not yet known\nbuild_vector_index_create(label=\"Doc\", field=\"embedding\", dimension=dimension, metric=\"cosine\")\n// after\ndimension = model.get_sentence_embedding_dimension()  # e.g. 384\nbuild_vector_index_create(label=\"Doc\", field=\"embedding\", dimension=dimension, metric=\"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}')\ncypher = build_vector_index_create(label=label, field=field, dimension=dimension, metric=metric)","typeGuard":"def valid_dimension(d: object) -> bool:\n    return isinstance(d, int) and not isinstance(d, bool) and d > 0","tryCatchPattern":"try:\n    cypher = build_vector_index_create(label, field, dimension, metric)\nexcept ValueError as e:\n    logger.error('vector index misconfigured: %s', e)\n    raise ConfigError('initialize the embedding model to resolve its dimension before declaring a vector index') from e","preventionTips":["Resolve the embedding dimension from the loaded model (e.g. model.get_sentence_embedding_dimension()) before declaring the index.","Never hardcode dimension=0 as a placeholder; defer index creation until the real dimension is known.","Add a startup assertion that every vector field spec has a positive integer dimension."],"tags":["cypher","falkordb","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"}