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

  1. Call TopKNear on the unwrapped LiteQueryable<T> obtained directly from collection.Query().
  2. If decorating, keep a reference to the original LiteQueryable<T> and expose it for vector operations.
  3. 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

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


AI-assisted analysis of litedb-org/LiteDB@f906a5f850 (2026-08-13). Data as JSON: /api/errors/c50d89c109d0cb55. Report an issue: GitHub.