{"record":{"id":"ebb7848ade47b851","repo":"litedb-org/LiteDB","slug":"dimensions-must-be-greater-than-zero","errorCode":null,"errorMessage":"Dimensions must be greater than zero.","messagePattern":"Dimensions must be greater than zero\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Vector/VectorIndexOptions.cs","lineNumber":24,"sourceCode":"    /// Options used when creating a vector-aware index.\n    /// </summary>\n    public sealed class VectorIndexOptions\n    {\n        /// <summary>\n        /// Gets the expected dimensionality of the indexed vectors.\n        /// </summary>\n        public ushort Dimensions { get; }\n\n        /// <summary>\n        /// Gets the distance metric used when comparing vectors.\n        /// </summary>\n        public VectorDistanceMetric Metric { get; }\n\n        public VectorIndexOptions(ushort dimensions, VectorDistanceMetric metric = VectorDistanceMetric.Cosine)\n        {\n            if (dimensions == 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(dimensions), dimensions, \"Dimensions must be greater than zero.\");\n            }\n\n            this.Dimensions = dimensions;\n            this.Metric = metric;\n        }\n    }\n}\n","sourceCodeStart":6,"sourceCodeEnd":32,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Vector/VectorIndexOptions.cs#L6-L32","documentation":"Thrown by the VectorIndexOptions constructor when dimensions is 0. A vector index requires a positive, fixed dimensionality to allocate storage and compute distances; zero is meaningless and would corrupt index geometry.","triggerScenarios":"Constructing new VectorIndexOptions(0); passing a dimensions value read from config that defaulted to 0; deriving dimensions from an empty or uninitialized embedding vector.","commonSituations":"Loading dimension count from appsettings where the key is missing (defaulting to 0); creating options before the embedding model is selected; off-by-one or unset ushort fields.","solutions":["Compute dimensions from the actual embedding model output length and assert it is > 0 before constructing options.","Validate config-sourced dimensions against a positive bound at startup.","Default to the model's known dimension (e.g., 1536) rather than 0."],"exampleFix":"// before\nvar opts = new VectorIndexOptions((ushort)dims, VectorDistanceMetric.Cosine);\n\n// after\nif (dims <= 0)\n    throw new InvalidOperationException($\"Invalid vector dimensions: {dims}\");\nvar opts = new VectorIndexOptions((ushort)dims, VectorDistanceMetric.Cosine);","handlingStrategy":"validation","validationCode":"if (dimensions <= 0)\n    throw new InvalidOperationException($\"Invalid vector dimensions: {dimensions}\");\nvar opts = new VectorIndexOptions((ushort)dimensions, metric);","typeGuard":"static bool IsValidDimensions(int d) => d > 0 && d <= ushort.MaxValue;","tryCatchPattern":null,"preventionTips":["Derive dimensions from the embedding model's output size at startup.","Validate config-sourced dimensions against a positive bound before use.","Default to the model's known dimension rather than 0."],"tags":["argument-validation","vector","range-check","configuration"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}