litedb-org/LiteDB · error · ArgumentException
Vector index operations require LiteDB's default repository
Error message
Vector index operations require LiteDB's default repository implementation.
What it means
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.
Source
Thrown at LiteDB/Client/Vector/LiteRepositoryVectorExtensions.cs:43
public static bool EnsureIndex<T, K>(this ILiteRepository repository, string name, Expression<Func<T, K>> keySelector, VectorIndexOptions options, string collectionName = null)
{
return Unwrap(repository).EnsureVectorIndex<T, K>(name, keySelector, options, collectionName);
}
private static LiteRepository Unwrap(ILiteRepository repository)
{
if (repository is null)
{
throw new ArgumentNullException(nameof(repository));
}
if (repository is LiteRepository liteRepository)
{
return liteRepository;
}
throw new ArgumentException("Vector index operations require LiteDB's default repository implementation.", nameof(repository));
}
}
}
View on GitHub (pinned to f906a5f850)
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.
Example fix
// before decorated.EnsureVectorIndex<MyDoc, float[]>(x => x.Embedding, opts); // after var liteRepo = decorated as LiteRepository ?? new LiteRepository(connString); liteRepo.EnsureVectorIndex<MyDoc, float[]>(x => x.Embedding, opts);
Defensive patterns
Strategy: type-guard
Validate before calling
if (repo is not LiteRepository raw)
throw new InvalidOperationException("Vector operations require the default LiteRepository.");
raw.EnsureVectorIndex<MyDoc, float[]>(x => x.Embedding, opts); Type guard
static bool IsDefaultRepository(ILiteRepository r) => r is LiteRepository;
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Repository decorators for logging/caching; unit tests with manual ILiteRepository stubs; abstraction layers that re-implement the interface.
Related errors
- Vector index operations require LiteDB's default collection
- Vector operations require LiteDB's default queryable impleme
- Value cannot be null. (Parameter 'repository')
- The current collection implementation does not support vecto
- Value cannot be null. (Parameter 'collection')
AI-assisted analysis of litedb-org/LiteDB@f906a5f850 (2026-08-13).
Data as JSON: /api/errors/01a3833ae2798c6d.
Report an issue: GitHub.