litedb-org/LiteDB · error · ArgumentException
Vector operations require LiteDB's default queryable impleme
Error message
Vector operations require LiteDB's default queryable implementation.
What it means
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.
Source
Thrown at LiteDB/Client/Vector/LiteQueryableVectorExtensions.cs:60
public static ILiteQueryableResult<T> TopKNear<T>(this ILiteQueryable<T> source, BsonExpression fieldExpr, float[] target, int k)
{
return Unwrap(source).VectorTopKNear(fieldExpr, target, k);
}
private static LiteQueryable<T> Unwrap<T>(ILiteQueryable<T> source)
{
if (source is null)
{
throw new ArgumentNullException(nameof(source));
}
if (source is LiteQueryable<T> liteQueryable)
{
return liteQueryable;
}
throw new ArgumentException("Vector operations require LiteDB's default queryable implementation.", nameof(source));
}
}
}
View on GitHub (pinned to f906a5f850)
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.
Example fix
// before
var r = projectedQuery.TopKNear("Embedding", vec, 5);
// after
var rawQuery = collection.Query() as LiteQueryable<MyDoc>;
var r = rawQuery.TopKNear("Embedding", vec, 5); Defensive patterns
Strategy: type-guard
Validate before calling
if (query is not LiteQueryable<MyDoc> raw)
throw new InvalidOperationException("Vector search requires the default LiteQueryable<T>.");
var results = raw.TopKNear("Embedding", vec, 5); Type guard
static bool IsDefaultQueryable<T>(ILiteQueryable<T> q) => q is LiteQueryable<T>;
Prevention
- 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.
When it happens
Trigger: 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>.
Common situations: Composition wrappers that add Where/Select clauses and re-wrap the queryable; mocking frameworks generating interface stubs; adapters that proxy LiteDB queries.
Related errors
- Vector index operations require LiteDB's default collection
- Vector index operations require LiteDB's default repository
- Value cannot be null. (Parameter 'source')
- Value cannot be null. (Parameter 'collection')
- Value cannot be null. (Parameter 'repository')
AI-assisted analysis of litedb-org/LiteDB@f906a5f850 (2026-08-13).
Data as JSON: /api/errors/c50d89c109d0cb55.
Report an issue: GitHub.