{"record":{"id":"4620e13c1e5a79e8","repo":"litedb-org/LiteDB","slug":"the-current-collection-implementation-does-not-sup","errorCode":null,"errorMessage":"The current collection implementation does not support vector operations.","messagePattern":"The current collection implementation does not support vector operations\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Database/LiteRepository.cs","lineNumber":29,"sourceCode":"    /// <summary>\n    /// The LiteDB repository pattern. A simple way to access your documents in a single class with fluent query api\n    /// </summary>\n    public class LiteRepository : ILiteRepository\n    {\n        #region Properties\n\n        private readonly ILiteDatabase _db = null;\n\n        private LiteCollection<T> GetLiteCollection<T>(string collectionName)\n        {\n            var collection = _db.GetCollection<T>(collectionName);\n\n            if (collection is LiteCollection<T> liteCollection)\n            {\n                return liteCollection;\n            }\n\n            throw new InvalidOperationException(\"The current collection implementation does not support vector operations.\");\n        }\n\n        /// <summary>\n        /// Get database instance\n        /// </summary>\n        public ILiteDatabase Database => _db;\n\n        #endregion\n\n        #region Ctor\n\n        /// <summary>\n        /// Starts LiteDB database an existing Database instance\n        /// </summary>\n        public LiteRepository(ILiteDatabase database)\n        {\n            _db = database;\n        }","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Database/LiteRepository.cs#L11-L47","documentation":"Thrown by LiteRepository.GetLiteCollection<T> when the collection returned by _db.GetCollection<T> is not the concrete LiteCollection<T>. Vector operations in LiteRepository require the concrete type because they call internal vector APIs; a custom ILiteDatabase that returns a different ILiteCollection implementation cannot satisfy them.","triggerScenarios":"Using LiteRepository over a custom/test ILiteDatabase whose GetCollection returns a mock or proxy; injecting a wrapped database (e.g. a caching decorator) into LiteRepository(ILiteDatabase); or running vector queries through a unit-test fake.","commonSituations":"Unit testing with a mocked ILiteDatabase, wrapping LiteDatabase in a decorator for logging/caching, or using a third-party ILiteDatabase implementation that does not derive from LiteCollection.","solutions":["Construct LiteRepository from a concrete LiteDatabase (string/ConnectionString/Stream) so GetCollection returns LiteCollection<T>.","If you must inject ILiteDatabase, ensure your wrapper delegates GetCollection to the inner LiteDatabase rather than returning its own type.","For tests, use a real in-memory LiteDatabase(new MemoryStream()) instead of a mock."],"exampleFix":"// before\nvar repo = new LiteRepository(myCustomDb); // myCustomDb is a wrapper\nrepo.Query<T>().VectorWhereNear(\"$.emb\", vec, 0.5);\n\n// after\nusing var ms = new MemoryStream();\nvar repo = new LiteRepository(new LiteDatabase(ms));\nrepo.Query<T>().VectorWhereNear(\"$.emb\", vec, 0.5);","handlingStrategy":"validation","validationCode":"if (_db is not LiteDatabase)\n    throw new InvalidOperationException(\"Vector operations require a concrete LiteDatabase instance.\");","typeGuard":"static bool SupportsVectors(ILiteDatabase db) => db is LiteDatabase;","tryCatchPattern":null,"preventionTips":["Construct LiteRepository from a concrete LiteDatabase for vector workloads.","In tests, use a real in-memory LiteDatabase(new MemoryStream()) instead of mocks.","Ensure any wrapper delegates GetCollection to the inner LiteDatabase."],"tags":["repository","vector","invalid-operation","test-double"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}