mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-23 08:13:49 +00:00
Fixed the retrieval context validation keeping unhelpful passages (#1217)
This commit is contained in:
1 parent
808b95b15d
commit
78f5066bfd
10 files changed
+454
-36
No files matched your search
@@ -77,11 +77,19 @@ public sealed class AugmentationOne : IAugmentationProcess
|
||||
//
|
||||
// Now, filter the retrieval contexts to the most relevant ones:
|
||||
//
|
||||
var targetWindow = validationResults.DetermineTargetWindow(TargetWindowStrategy.TOP10_BETTER_THAN_GUESSING);
|
||||
var threshold = validationResults.GetConfidenceThreshold(targetWindow);
|
||||
var validated = KeepFittingPassages(validationResults);
|
||||
usedContexts = validated.Contexts;
|
||||
LOGGER.LogInformation($"The check of which passages fit kept {validated.Contexts.Count:###,###,###,##0} of {validationResults.Count:###,###,###,##0} retrieved contexts: {validated.NumUnchecked:###,###,###,##0} without a usable judgment, {validated.NumRejected:###,###,###,##0} judged not to fit, {validated.NumBelowThreshold:###,###,###,##0} below the confidence threshold of {validated.Threshold:0.00}.");
|
||||
|
||||
// Filter the retrieval contexts:
|
||||
usedContexts = validationResults.Where(x => x.RetrievalContext is not null && x.Confidence >= threshold).Select(x => x.RetrievalContext!).ToList();
|
||||
//
|
||||
// The user switched this check on. When it failed for every passage, the answer
|
||||
// rests on unfiltered passages, just as when the check throws:
|
||||
//
|
||||
if (validated.IsUnchecked)
|
||||
{
|
||||
LOGGER.LogWarning("Retrieval context validation got no usable answer for any context. Continuing augmentation with all retrieved contexts.");
|
||||
await WarnThatTheCheckFailedAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException) when (token.IsCancellationRequested)
|
||||
@@ -96,7 +104,7 @@ public sealed class AugmentationOne : IAugmentationProcess
|
||||
// The user switched this check on. Continuing without it silently would hide
|
||||
// that the answer rests on unfiltered passages:
|
||||
//
|
||||
await MessageBus.INSTANCE.SendWarning(new(AppIcons.PASSAGE_RELEVANCE_CHECK, TA("The check of which passages fit your question failed. This answer uses all passages that were found.")));
|
||||
await WarnThatTheCheckFailedAsync();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -134,6 +142,35 @@ public sealed class AugmentationOne : IAugmentationProcess
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Keeps the passages which the check of which passages fit the user prompt let through.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A passage judged not to fit is left out, however confident the judgment. Of the passages judged to fit,
|
||||
/// those stay whose confidence reaches the threshold, which only they decide. A passage whose check failed
|
||||
/// stays: the failure says nothing about the passage, neither that it fits nor that it does not. It does not
|
||||
/// count for the threshold either, so that a failed check moves the line for none of the others.
|
||||
/// </remarks>
|
||||
/// <param name="validationResults">The results of the check, one for each passage.</param>
|
||||
/// <returns>The passages left, in the order of the results, and why the others were left out.</returns>
|
||||
internal static ValidatedPassages KeepFittingPassages(IReadOnlyList<RetrievalContextValidationResult> validationResults)
|
||||
{
|
||||
var numJudged = validationResults.Count(result => result.IsAnswered);
|
||||
var fitting = validationResults.Where(result => result.IsAnswered && result.Decision).ToList();
|
||||
|
||||
//
|
||||
// Without a passage which fits, there is no threshold to find; asking for one would only log a warning:
|
||||
//
|
||||
var threshold = fitting.Count is 0 ? 0f : fitting.GetConfidenceThreshold(fitting.DetermineTargetWindow(TargetWindowStrategy.TOP10_BETTER_THAN_GUESSING));
|
||||
var contexts = validationResults.Where(result => !result.IsAnswered || (result.Decision && result.Confidence >= threshold)).Select(result => result.RetrievalContext).ToList();
|
||||
return new(contexts, numJudged, validationResults.Count - numJudged, numJudged - fitting.Count, fitting.Count(result => result.Confidence < threshold), threshold);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tells the user that the check of which passages fit failed, so that the answer uses all passages found.
|
||||
/// </summary>
|
||||
private static Task WarnThatTheCheckFailedAsync() => MessageBus.INSTANCE.SendWarning(new(AppIcons.PASSAGE_RELEVANCE_CHECK, TA("The check of which passages fit your question failed. This answer uses all passages that were found.")));
|
||||
|
||||
/// <summary>
|
||||
/// Writes what the model reads along with the user prompt: the passages which fit, and how many did not.
|
||||
/// </summary>
|
||||
|
||||
Reference in new issue
Block a user