{"record":{"id":"01a3833ae2798c6d","repo":"litedb-org/LiteDB","slug":"vector-index-operations-require-litedb-s-default-r","errorCode":null,"errorMessage":"Vector index operations require LiteDB's default repository implementation.","messagePattern":"Vector index operations require LiteDB's default repository implementation\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Vector/LiteRepositoryVectorExtensions.cs","lineNumber":43,"sourceCode":"\n        public static bool EnsureIndex<T, K>(this ILiteRepository repository, string name, Expression<Func<T, K>> keySelector, VectorIndexOptions options, string collectionName = null)\n        {\n            return Unwrap(repository).EnsureVectorIndex<T, K>(name, keySelector, options, collectionName);\n        }\n\n        private static LiteRepository Unwrap(ILiteRepository repository)\n        {\n            if (repository is null)\n            {\n                throw new ArgumentNullException(nameof(repository));\n            }\n\n            if (repository is LiteRepository liteRepository)\n            {\n                return liteRepository;\n            }\n\n            throw new ArgumentException(\"Vector index operations require LiteDB's default repository implementation.\", nameof(repository));\n        }\n    }\n}\n","sourceCodeStart":25,"sourceCodeEnd":47,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Vector/LiteRepositoryVectorExtensions.cs#L25-L47","documentation":"Thrown by Unwrap in LiteRepositoryVectorExtensions when the ILiteRepository is not the concrete LiteRepository. Vector index creation uses internal repository members not exposed on the interface, so a custom implementation is rejected.","triggerScenarios":"Passing a wrapped/mocked ILiteRepository (decorator, audit proxy, or test stub) to a vector EnsureIndex extension; a third-party repository abstraction implementing the interface without subclassing LiteRepository.","commonSituations":"Repository decorators for logging/caching; unit tests with manual ILiteRepository stubs; abstraction layers that re-implement the interface.","solutions":["Register and inject the concrete LiteRepository (or obtain via new LiteRepository(...)) for vector operations.","If decorating, route vector calls to the inner LiteRepository instance.","Replace test stubs with a real LiteRepository over an in-memory stream."],"exampleFix":"// before\ndecorated.EnsureVectorIndex<MyDoc, float[]>(x => x.Embedding, opts);\n\n// after\nvar liteRepo = decorated as LiteRepository ?? new LiteRepository(connString);\nliteRepo.EnsureVectorIndex<MyDoc, float[]>(x => x.Embedding, opts);","handlingStrategy":"type-guard","validationCode":"if (repo is not LiteRepository raw)\n    throw new InvalidOperationException(\"Vector operations require the default LiteRepository.\");\nraw.EnsureVectorIndex<MyDoc, float[]>(x => x.Embedding, opts);","typeGuard":"static bool IsDefaultRepository(ILiteRepository r) => r is LiteRepository;","tryCatchPattern":null,"preventionTips":["Inject the concrete LiteRepository for vector operations.","Route vector calls to the inner LiteRepository from decorators.","Use real LiteRepository instances over in-memory streams in tests."],"tags":["argument-validation","vector","type-check","repository","wrapper"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}