{"record":{"id":"a05188ed16f73ac6","repo":"mem0ai/mem0","slug":"invalid-collection-name-collection-name-r-must","errorCode":null,"errorMessage":"Invalid collection_name: {collection_name!r}. Must start with a letter or underscore and contain only letters, digits, and underscores.","messagePattern":"Invalid collection_name: (.+?)\\. Must start with a letter or underscore and contain only letters, digits, and underscores\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/neptune_analytics.py","lineNumber":78,"sourceCode":"        collection_name: str,\n    ):\n        \"\"\"\n        Initialize the Neptune Analytics vector store.\n\n        Args:\n            endpoint (str): Neptune Analytics endpoint in format 'neptune-graph://<graphid>'.\n            collection_name (str): Name of the collection to store vectors.\n            \n        Raises:\n            ValueError: If endpoint format is invalid.\n            ImportError: If langchain_aws is not installed.\n        \"\"\"\n\n        if not endpoint.startswith(\"neptune-graph://\"):\n            raise ValueError(\"Please provide 'endpoint' with the format as 'neptune-graph://<graphid>'.\")\n\n        if not _VALID_IDENTIFIER.match(collection_name):\n            raise ValueError(\n                f\"Invalid collection_name: {collection_name!r}. Must start with a letter or underscore and \"\n                \"contain only letters, digits, and underscores.\"\n            )\n\n        graph_id = endpoint.replace(\"neptune-graph://\", \"\")\n        self.graph = NeptuneAnalyticsGraph(graph_id)\n        self.collection_name = self._COLLECTION_PREFIX + collection_name\n\n    \n    def create_col(self, name, vector_size, distance):\n        \"\"\"\n        Create a collection (no-op for Neptune Analytics).\n        \n        Neptune Analytics supports dynamic indices that are created implicitly\n        when vectors are inserted, so this method performs no operation.\n        \n        Args:\n            name: Collection name (unused).","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/neptune_analytics.py#L60-L96","documentation":"The collection_name is embedded into openCypher node labels (prefixed with the store's COLLECTION_PREFIX), so it must match ^[A-Za-z_][A-Za-z0-9_]*$. This error fires at construction when the name contains dots, dashes, spaces, starts with a digit, or is not a valid identifier — otherwise the generated Cypher would be malformed or injectable.","triggerScenarios":"collection_name=\"my-memories\", \"app.v2\", \"0default\", \"user memories\" passed in the Neptune Analytics vector store config.","commonSituations":"Reusing default collection names from other backends (mem0 / default often fine, but names like memory-store are not); auto-generating collection names from user/org slugs with dashes.","solutions":["Use only letters, digits, underscores, starting with a letter or underscore: \"my_memories\", \"app_v2\"","If names are generated, slugify to snake_case before config time","Keep the name short and stable — it becomes the node label for the graph"],"exampleFix":"# before\n\"collection_name\": \"prod-memories\"\n\n# after\n\"collection_name\": \"prod_memories\"","handlingStrategy":"validation","validationCode":"import re\n\ndef safe_collection_name(name: str) -> str:\n    s = re.sub(r\"[^A-Za-z0-9_]\", \"_\", name)\n    if not re.match(r\"^[A-Za-z_]\", s):\n        s = \"c_\" + s\n    return s\n\nconfig[\"collection_name\"] = safe_collection_name(config[\"collection_name\"])","typeGuard":"def is_valid_collection_name(name) -> bool:\n    return isinstance(name, str) and bool(re.match(r\"^[A-Za-z_][A-Za-z0-9_]*$\", name))","tryCatchPattern":"try:\n    store = NeptuneAnalytics(...)\nexcept ValueError as e:\n    if \"Invalid collection_name\" in str(e):\n        raise ConfigError(\"collection_name must be a snake_case identifier\")\n    raise","preventionTips":["Generate collection names via slugify-to-snake_case when derived from slugs","Fail fast on config load with the identifier regex","Keep the name identical across restarts — it is the graph node label"],"tags":["neptune","aws","configuration","cypher-injection","validation"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}