{"record":{"id":"4797efb808c3a96c","repo":"litedb-org/LiteDB","slug":"vectorfield","errorCode":null,"errorMessage":"vectorField","messagePattern":"vectorField","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Database/LiteQueryable.cs","lineNumber":259,"sourceCode":"        {\n            if (target == null || target.Length == 0) throw new ArgumentException(\"Target vector must be provided.\", nameof(target));\n            // Dot-product queries interpret \"maxDistance\" as a minimum similarity score and may therefore pass negative values.\n            if (double.IsNaN(maxDistance)) throw new ArgumentOutOfRangeException(nameof(maxDistance), \"Similarity threshold must be a valid number.\");\n        }\n\n        private static BsonExpression CreateVectorSimilarityFilter(BsonExpression fieldExpr, float[] target, double maxDistance)\n        {\n            if (fieldExpr == null) throw new ArgumentNullException(nameof(fieldExpr));\n\n            ValidateVectorArguments(target, maxDistance);\n\n            var targetArray = new BsonArray(target.Select(v => new BsonValue(v)));\n            return BsonExpression.Create($\"{fieldExpr.Source} VECTOR_SIM @0 <= @1\", targetArray, new BsonValue(maxDistance));\n        }\n\n        internal ILiteQueryable<T> VectorWhereNear(string vectorField, float[] target, double maxDistance)\n        {\n            if (string.IsNullOrWhiteSpace(vectorField)) throw new ArgumentNullException(nameof(vectorField));\n\n            var fieldExpr = BsonExpression.Create($\"$.{vectorField}\");\n            return this.VectorWhereNear(fieldExpr, target, maxDistance);\n        }\n\n        internal ILiteQueryable<T> VectorWhereNear(BsonExpression fieldExpr, float[] target, double maxDistance)\n        {\n            var filter = CreateVectorSimilarityFilter(fieldExpr, target, maxDistance);\n\n            _query.Where.Add(filter);\n\n            _query.VectorField = fieldExpr.Source;\n            _query.VectorTarget = target?.ToArray();\n            _query.VectorMaxDistance = maxDistance;\n\n            return this;\n        }\n","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Database/LiteQueryable.cs#L241-L277","documentation":"Thrown by VectorWhereNear(string vectorField, ...) when vectorField is null, empty, or whitespace. The string is used to build the field path $.{vectorField}; a blank name yields an invalid path. This is the friendly string overload that delegates to the BsonExpression version.","triggerScenarios":"Calling VectorWhereNear(\"\", vec, dist), VectorWhereNear(null, vec, dist), or VectorWhereNear(\"   \", vec, dist). Also when the field name comes from a config variable that is unset.","commonSituations":"Hardcoding a field name that was later renamed, reading the field name from configuration that is missing, or passing a property name constant that resolved to empty.","solutions":["Validate the field name with string.IsNullOrWhiteSpace at the call site.","Use a constant for the embedding field name to avoid typos and empty strings.","Cross-check the field name against the schema used when documents were inserted."],"exampleFix":"// before\nvar q = col.Query().VectorWhereNear(fieldName, vec, dist);\n\n// after\nconst string EmbeddingField = \"embedding\";\nif (string.IsNullOrWhiteSpace(fieldName))\n    fieldName = EmbeddingField;\nvar q = col.Query().VectorWhereNear(fieldName, vec, dist);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(vectorField))\n    throw new ArgumentException(\"Vector field name is required.\", nameof(vectorField));","typeGuard":"static bool IsValidFieldName(string s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":null,"preventionTips":["Use a named constant for the embedding field.","Validate field names from config before issuing vector queries."],"tags":["vector","vector-search","argument-null","field-name"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}