{"record":{"id":"87a5d5b1335d78fb","repo":"cocoindex-io/cocoindex","slug":"invalid-collection-name-name-r-zvec-requires-at","errorCode":null,"errorMessage":"Invalid collection name {name!r}: zvec requires at least {_MIN_COLLECTION_NAME_LEN} characters.","messagePattern":"Invalid collection name (.+?): zvec requires at least (.+?) characters\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/zvec/_target.py","lineNumber":93,"sourceCode":"# zvec rejects names that don't match its internal rule. We guard with a\n# conservative identifier allow-list before handing the name to zvec, which\n# mirrors the input-safety guidance for other connectors and gives a clear error\n# early.\n_IDENTIFIER_RE = re.compile(r\"^[A-Za-z_][A-Za-z0-9_]*$\")\n\n# zvec additionally rejects collection names shorter than 3 characters.\n_MIN_COLLECTION_NAME_LEN = 3\n\n\ndef _validate_identifier(name: str, kind: str = \"identifier\") -> None:\n    if not isinstance(name, str) or not _IDENTIFIER_RE.match(name):\n        raise ValueError(f\"Invalid {kind}: {name!r}\")\n\n\ndef _validate_collection_name(name: str) -> None:\n    _validate_identifier(name, \"collection name\")\n    if len(name) < _MIN_COLLECTION_NAME_LEN:\n        raise ValueError(\n            f\"Invalid collection name {name!r}: zvec requires at least \"\n            f\"{_MIN_COLLECTION_NAME_LEN} characters.\"\n        )\n\n\n# =============================================================================\n# Connection\n# =============================================================================\n\n\ndef _collection_option(enable_mmap: bool, *, read_only: bool = False) -> Any:\n    return _zvec.CollectionOption(read_only=read_only, enable_mmap=enable_mmap)\n\n\n@dataclass\nclass ManagedConnection:\n    \"\"\"A handle to a base directory holding zvec collections.\n","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/zvec/_target.py#L75-L111","documentation":"Pre-flight guard before handing a collection name to the zvec engine. zvec silently rejects names violating its internal rules, so the connector applies a conservative identifier allow-list (^[A-Za-z_][A-Za-z0-9_]*$) and a minimum length of 3 to fail early with a clear message. This specific error fires when the name passes the regex but is shorter than 3 characters (e.g. 'ab'). Pick a longer, alphanumeric/underscore collection name.","triggerScenarios":"Creating a collection whose name is 1-2 characters long, e.g. collection_target(name=\"a\") or name=\"db\".","commonSituations":"Using short aliases, single-letter test names, or truncated identifiers generated from other data.","solutions":["Use a collection name of at least 3 characters","Prefix short names, e.g. f\"col_{name}\"","Add a length check before creating collections"],"exampleFix":"// before\nthis.collection_target(name=\"a\")\n// after\nthis.collection_target(name=\"docs_a\")","handlingStrategy":"validation","validationCode":"if len(name) < 3:\n    name = name.ljust(3, \"_\")  # or choose a longer name","typeGuard":"def is_valid_collection_name(name: object) -> TypeGuard[str]:\n    return isinstance(name, str) and len(name) >= 3 and bool(re.match(r\"[A-Za-z_]\", name))","tryCatchPattern":"try:\n    target = zvec.collection_target(name=name, ...)\nexcept ValueError as e:\n    if \"at least 3 characters\" in str(e):\n        name = f\"col_{name}\"\n        target = zvec.collection_target(name=name, ...)\n    else:\n        raise","preventionTips":["Enforce min length 3 when generating collection names","Avoid single-letter or 2-char aliases for collections","Check name length in config validation"],"tags":["python","validation","naming","zvec"],"backgroundTag":"invalid-identifier-format","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"}