{"record":{"id":"8a543a8640f706e0","repo":"headroomlabs-ai/headroom","slug":"vector-dimension-must-be-positive-got-self-vecto","errorCode":null,"errorMessage":"vector_dimension must be positive, got {self.vector_dimension}","messagePattern":"vector_dimension must be positive, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"headroom/memory/config.py","lineNumber":137,"sourceCode":"\n    # Embedder\n    embedder_backend: EmbedderBackend = EmbedderBackend.LOCAL\n    embedder_model: str = field(default_factory=lambda: ML_MODEL_DEFAULTS.sentence_transformer)\n    openai_api_key: str | None = None\n    ollama_base_url: str = \"http://localhost:11434\"\n\n    # Cache\n    cache_enabled: bool = True\n    cache_max_size: int = 1000\n\n    # Bubbling defaults\n    auto_bubble: bool = True\n    bubble_threshold: float = 0.7  # Minimum importance for bubbling\n\n    def __post_init__(self) -> None:\n        \"\"\"Validate configuration after initialization.\"\"\"\n        if self.vector_dimension < 1:\n            raise ValueError(f\"vector_dimension must be positive, got {self.vector_dimension}\")\n\n        if self.hnsw_ef_construction < 1:\n            raise ValueError(\n                f\"hnsw_ef_construction must be positive, got {self.hnsw_ef_construction}\"\n            )\n\n        if self.hnsw_m < 1:\n            raise ValueError(f\"hnsw_m must be positive, got {self.hnsw_m}\")\n\n        if self.hnsw_ef_search < 1:\n            raise ValueError(f\"hnsw_ef_search must be positive, got {self.hnsw_ef_search}\")\n\n        if self.cache_max_size < 1:\n            raise ValueError(f\"cache_max_size must be positive, got {self.cache_max_size}\")\n\n        if self.embedder_backend == EmbedderBackend.OPENAI and not self.openai_api_key:\n            raise ValueError(\"openai_api_key is required when using OpenAI embedder backend\")\n","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/headroom/memory/config.py#L119-L155","documentation":"ValueError raised in MemoryConfig.__post_init__ (vector memory system config) when vector_dimension < 1. The vector_dimension must match the embedder's output size (e.g. 1536 for OpenAI text-embedding-3-small) and index stores keyed on it, so zero/negative dimensions are rejected at construction.","triggerScenarios":"MemoryConfig(vector_dimension=0) or a negative value, typically from an env var defaulting to 0 or a config template placeholder never filled in.","commonSituations":"Optional config left as 0 meaning 'unset'; .env with VECTOR_DIMENSION= for later override that never happens; switching embedders without updating the dimension.","solutions":["Set the dimension to your embedder's output size: 1536 for text-embedding-3-small, 3072 for -large, 384 for all-MiniLM-L6-v2","Fail loudly at config load time if the env var is empty rather than coercing to 0","If unsure, check len(embedding) from one sample embed call"],"exampleFix":"# before\ncfg = MemoryConfig(vector_dimension=0)  # ValueError: vector_dimension must be positive\n\n# after\ncfg = MemoryConfig(vector_dimension=1536)  # match your embedder","handlingStrategy":"validation","validationCode":"def check_dimension(dim: int) -> int:\n    if dim < 1:\n        raise ValueError(f'vector_dimension must be >= 1, got {dim}')\n    return dim\n\ndim = int(os.environ.get('VECTOR_DIMENSION') or 1536)  # never default to 0\ncfg = MemoryConfig(vector_dimension=check_dimension(dim))","typeGuard":"def is_valid_dimension(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool) and v >= 1","tryCatchPattern":"try:\n    cfg = MemoryConfig(vector_dimension=dim)\nexcept ValueError as e:\n    raise SystemExit(f'Bad memory config: {e}') from e","preventionTips":["Set vector_dimension from the embedder spec, never guessed","Treat 0 in external config as 'unset' and substitute a real default","After switching embedder models, update the dimension and rebuild the index"],"tags":["python","config","validation","vector","embeddings","range-check"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}