{"record":{"id":"aae4ba30806e6047","repo":"dotnet/efcore","slug":"only-one-ordering-using-scoring-function-is-allowe","errorCode":null,"errorMessage":"Only one ordering using scoring function is allowed. Use 'EF.Functions.{rrf}' method to combine multiple scoring functions.","messagePattern":"Only one ordering using scoring function is allowed\\. Use 'EF\\.Functions\\.(.+?)' method to combine multiple scoring functions\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Query/Internal/Expressions/SelectExpression.cs","lineNumber":484,"sourceCode":"        _orderings.Clear();\n        _orderings.Add(orderingExpression);\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public void AppendOrdering(OrderingExpression orderingExpression)\n    {\n        if (_orderings.Count > 0)\n        {\n            var existingScoringFunctionOrdering = _orderings is [{ Expression: SqlFunctionExpression { IsScoringFunction: true } }];\n            var appendingScoringFunctionOrdering = orderingExpression.Expression is SqlFunctionExpression { IsScoringFunction: true };\n            if (appendingScoringFunctionOrdering || existingScoringFunctionOrdering)\n            {\n                throw new InvalidOperationException(\n                    appendingScoringFunctionOrdering && existingScoringFunctionOrdering\n                        ? CosmosStrings.OrderByMultipleScoringFunctionWithoutRrf(nameof(CosmosDbFunctionsExtensions.Rrf))\n                        : CosmosStrings.OrderByScoringFunctionMixedWithRegularOrderby);\n            }\n        }\n\n        if (_orderings.FirstOrDefault(o => o.Expression.Equals(orderingExpression.Expression)) == null)\n        {\n            _orderings.Add(orderingExpression);\n        }\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>","sourceCodeStart":466,"sourceCodeEnd":502,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Query/Internal/Expressions/SelectExpression.cs#L466-L502","documentation":"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.","triggerScenarios":"Two OrderBy/ThenBy clauses each calling a scoring function, e.g. .OrderBy(i => EF.Functions.VectorDistance(...)).ThenBy(i => EF.Functions.FullTextScore(...)).","commonSituations":"Combining vector similarity with full-text relevance as separate ordering clauses; layering multiple vector indexes as separate ThenBy.","solutions":["Fuse the scoring functions with EF.Functions.Rrf into a single ordering.","Drop all but one of the scoring-function orderings."],"exampleFix":"// before\nvar q = db.Items\n    .OrderBy(i => EF.Functions.VectorDistance(i.Embedding, v))\n    .ThenBy(i => EF.Functions.FullTextScore(i.Text, \"term\"));\n\n// after - fuse with Rrf\nvar q = db.Items\n    .OrderBy(i => EF.Functions.Rrf(\n        EF.Functions.VectorDistance(i.Embedding, v),\n        EF.Functions.FullTextScore(i.Text, \"term\")));","handlingStrategy":"validation","validationCode":"// Detect two scoring-function orderings and require Rrf fusion.\nstatic int ScoringOrderings(IQueryable q) => /* count OrderBy/ThenBy scoring calls */ 0;\nif (ScoringOrderings(query) > 1) throw new InvalidOperationException(\"Combine scoring orderings with EF.Functions.Rrf\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fuse multiple scoring signals with EF.Functions.Rrf.","Audit query helpers that compose ranking to ensure only one scoring ordering remains.","Provide a reusable Rank(...) helper that always returns a single Rrf ordering."],"tags":["cosmos","ordering","scoring-function","rrf"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}