{"record":{"id":"c50d89c109d0cb55","repo":"litedb-org/LiteDB","slug":"vector-operations-require-litedb-s-default-queryab","errorCode":null,"errorMessage":"Vector operations require LiteDB's default queryable implementation.","messagePattern":"Vector operations require LiteDB's default queryable implementation\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Vector/LiteQueryableVectorExtensions.cs","lineNumber":60,"sourceCode":"\n        public static ILiteQueryableResult<T> TopKNear<T>(this ILiteQueryable<T> source, BsonExpression fieldExpr, float[] target, int k)\n        {\n            return Unwrap(source).VectorTopKNear(fieldExpr, target, k);\n        }\n\n        private static LiteQueryable<T> Unwrap<T>(ILiteQueryable<T> source)\n        {\n            if (source is null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (source is LiteQueryable<T> liteQueryable)\n            {\n                return liteQueryable;\n            }\n\n            throw new ArgumentException(\"Vector operations require LiteDB's default queryable implementation.\", nameof(source));\n        }\n    }\n}\n","sourceCodeStart":42,"sourceCodeEnd":64,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Vector/LiteQueryableVectorExtensions.cs#L42-L64","documentation":"Thrown by Unwrap in LiteQueryableVectorExtensions when the ILiteQueryable<T> is not a LiteQueryable<T>. Vector search depends on internal engine APIs exposed only by the default queryable, so an alternate implementation cannot service the request.","triggerScenarios":"Passing a custom ILiteQueryable<T> (a decorator, a projected wrapper, or a test double) to TopKNear; using a third-party LINQ provider that implements the interface without subclassing LiteQueryable<T>.","commonSituations":"Composition wrappers that add Where/Select clauses and re-wrap the queryable; mocking frameworks generating interface stubs; adapters that proxy LiteDB queries.","solutions":["Call TopKNear on the unwrapped LiteQueryable<T> obtained directly from collection.Query().","If decorating, keep a reference to the original LiteQueryable<T> and expose it for vector operations.","Replace interface stubs in tests with a real LiteQueryable<T> backed by an in-memory LiteDatabase."],"exampleFix":"// before\nvar r = projectedQuery.TopKNear(\"Embedding\", vec, 5);\n\n// after\nvar rawQuery = collection.Query() as LiteQueryable<MyDoc>;\nvar r = rawQuery.TopKNear(\"Embedding\", vec, 5);","handlingStrategy":"type-guard","validationCode":"if (query is not LiteQueryable<MyDoc> raw)\n    throw new InvalidOperationException(\"Vector search requires the default LiteQueryable<T>.\");\nvar results = raw.TopKNear(\"Embedding\", vec, 5);","typeGuard":"static bool IsDefaultQueryable<T>(ILiteQueryable<T> q) => q is LiteQueryable<T>;","tryCatchPattern":null,"preventionTips":["Call TopKNear on the queryable obtained directly from collection.Query().","Keep a reference to the original LiteQueryable<T> inside decorators.","Use real LiteQueryable<T> instances in tests backed by an in-memory database."],"tags":["argument-validation","vector","type-check","queryable","wrapper"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}