dotnet/efcore · error · InvalidOperationException

Only one ordering using scoring function is allowed. Use…

Error message

Only one ordering using scoring function is allowed. Use 'EF.Functions.{rrf}' method to combine multiple scoring functions.

What it means

AppendOrdering in Cosmos SelectExpression throws OrderByMultipleScoringFunctionWithoutRrf when both the existing ordering and the appended ordering are scoring functions (VectorDistance/FullTextScore). Cosmos allows only one scoring-function ordering; to fuse multiple scoring signals you must combine them with EF.Functions.Rrf (reciprocal rank fusion) into a single score expression.

Solutions

  1. Fuse the scoring functions with EF.Functions.Rrf into a single ordering.
  2. Drop all but one of the scoring-function orderings.

Example fix

// before
var q = db.Items
    .OrderBy(i => EF.Functions.VectorDistance(i.Embedding, v))
    .ThenBy(i => EF.Functions.FullTextScore(i.Text, "term"));

// after - fuse with Rrf
var q = db.Items
    .OrderBy(i => EF.Functions.Rrf(
        EF.Functions.VectorDistance(i.Embedding, v),
        EF.Functions.FullTextScore(i.Text, "term")));
Defensive patterns

Strategy: validation

Validate before calling

// Detect two scoring-function orderings and require Rrf fusion.
static int ScoringOrderings(IQueryable q) => /* count OrderBy/ThenBy scoring calls */ 0;
if (ScoringOrderings(query) > 1) throw new InvalidOperationException("Combine scoring orderings with EF.Functions.Rrf");

Prevention

When it happens

Trigger: Two OrderBy/ThenBy clauses each calling a scoring function, e.g. .OrderBy(i => EF.Functions.VectorDistance(...)).ThenBy(i => EF.Functions.FullTextScore(...)).

Common situations: Combining vector similarity with full-text relevance as separate ordering clauses; layering multiple vector indexes as separate ThenBy.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/aae4ba30806e6047. Report an issue: GitHub.

Appendix: source

Thrown at src/EFCore.Cosmos/Query/Internal/Expressions/SelectExpression.cs:484

        _orderings.Clear();
        _orderings.Add(orderingExpression);
    }

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    public void AppendOrdering(OrderingExpression orderingExpression)
    {
        if (_orderings.Count > 0)
        {
            var existingScoringFunctionOrdering = _orderings is [{ Expression: SqlFunctionExpression { IsScoringFunction: true } }];
            var appendingScoringFunctionOrdering = orderingExpression.Expression is SqlFunctionExpression { IsScoringFunction: true };
            if (appendingScoringFunctionOrdering || existingScoringFunctionOrdering)
            {
                throw new InvalidOperationException(
                    appendingScoringFunctionOrdering && existingScoringFunctionOrdering
                        ? CosmosStrings.OrderByMultipleScoringFunctionWithoutRrf(nameof(CosmosDbFunctionsExtensions.Rrf))
                        : CosmosStrings.OrderByScoringFunctionMixedWithRegularOrderby);
            }
        }

        if (_orderings.FirstOrDefault(o => o.Expression.Equals(orderingExpression.Expression)) == null)
        {
            _orderings.Add(orderingExpression);
        }
    }

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>

View on GitHub (pinned to 3a2006ef56)