mem0ai/mem0 · error · ValueError

Invalid collection_name: {collection_name!r}. Must start wit

Error message

Invalid collection_name: {collection_name!r}. Must start with a letter or underscore and contain only letters, digits, and underscores.

What it means

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.

Source

Thrown at mem0/vector_stores/neptune_analytics.py:78

        collection_name: str,
    ):
        """
        Initialize the Neptune Analytics vector store.

        Args:
            endpoint (str): Neptune Analytics endpoint in format 'neptune-graph://<graphid>'.
            collection_name (str): Name of the collection to store vectors.
            
        Raises:
            ValueError: If endpoint format is invalid.
            ImportError: If langchain_aws is not installed.
        """

        if not endpoint.startswith("neptune-graph://"):
            raise ValueError("Please provide 'endpoint' with the format as 'neptune-graph://<graphid>'.")

        if not _VALID_IDENTIFIER.match(collection_name):
            raise ValueError(
                f"Invalid collection_name: {collection_name!r}. Must start with a letter or underscore and "
                "contain only letters, digits, and underscores."
            )

        graph_id = endpoint.replace("neptune-graph://", "")
        self.graph = NeptuneAnalyticsGraph(graph_id)
        self.collection_name = self._COLLECTION_PREFIX + collection_name

    
    def create_col(self, name, vector_size, distance):
        """
        Create a collection (no-op for Neptune Analytics).
        
        Neptune Analytics supports dynamic indices that are created implicitly
        when vectors are inserted, so this method performs no operation.
        
        Args:
            name: Collection name (unused).

View on GitHub (pinned to 001c235229)

Solutions

  1. Use only letters, digits, underscores, starting with a letter or underscore: "my_memories", "app_v2"
  2. If names are generated, slugify to snake_case before config time
  3. Keep the name short and stable — it becomes the node label for the graph

Example fix

# before
"collection_name": "prod-memories"

# after
"collection_name": "prod_memories"
Defensive patterns

Strategy: validation

Validate before calling

import re

def safe_collection_name(name: str) -> str:
    s = re.sub(r"[^A-Za-z0-9_]", "_", name)
    if not re.match(r"^[A-Za-z_]", s):
        s = "c_" + s
    return s

config["collection_name"] = safe_collection_name(config["collection_name"])

Type guard

def is_valid_collection_name(name) -> bool:
    return isinstance(name, str) and bool(re.match(r"^[A-Za-z_][A-Za-z0-9_]*$", name))

Try / catch

try:
    store = NeptuneAnalytics(...)
except ValueError as e:
    if "Invalid collection_name" in str(e):
        raise ConfigError("collection_name must be a snake_case identifier")
    raise

Prevention

When it happens

Trigger: collection_name="my-memories", "app.v2", "0default", "user memories" passed in the Neptune Analytics vector store config.

Common situations: 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.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/a05188ed16f73ac6. Report an issue: GitHub.