-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRagFinalSelectionOptions.cs
More file actions
57 lines (51 loc) · 1.85 KB
/
Copy pathRagFinalSelectionOptions.cs
File metadata and controls
57 lines (51 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
namespace Mythosia.AI.Rag
{
/// <summary>
/// Controls how the pipeline chooses final references after optional re-ranking.
/// </summary>
public enum RagFinalSelectionMode
{
/// <summary>
/// Preserve the current behavior: trust reranker scores as the final decision when reranking is enabled.
/// </summary>
RerankerOnly = 0,
/// <summary>
/// Preserve retrieval evidence by blending retrieval and reranker scores.
/// </summary>
WeightedBlend = 1
}
/// <summary>
/// Final selection policy applied after retrieval and optional re-ranking.
/// </summary>
public sealed class RagFinalSelectionOptions
{
public const double DefaultRetrievalWeight = 0.65d;
/// <summary>
/// Selection mode. Defaults to <see cref="RagFinalSelectionMode.RerankerOnly"/>
/// to preserve backward compatibility.
/// </summary>
public RagFinalSelectionMode Mode { get; set; } = RagFinalSelectionMode.RerankerOnly;
/// <summary>
/// Retrieval-score weight used when <see cref="Mode"/> is
/// <see cref="RagFinalSelectionMode.WeightedBlend"/>.
/// </summary>
public double RetrievalWeight { get; set; } = DefaultRetrievalWeight;
public double GetClampedRetrievalWeight()
{
if (RetrievalWeight < 0d) return 0d;
if (RetrievalWeight > 1d) return 1d;
return RetrievalWeight;
}
/// <summary>
/// Returns a copy of this <see cref="RagFinalSelectionOptions"/> with the same field values.
/// </summary>
public RagFinalSelectionOptions Clone()
{
return new RagFinalSelectionOptions
{
Mode = Mode,
RetrievalWeight = RetrievalWeight
};
}
}
}