|
| 1 | +using AiDotNet.Enums; |
| 2 | + |
| 3 | +namespace AiDotNet.Deployment.Configuration; |
| 4 | + |
| 5 | +/// <summary> |
| 6 | +/// Configuration for A/B testing - comparing multiple model versions by splitting traffic. |
| 7 | +/// </summary> |
| 8 | +/// <remarks> |
| 9 | +/// <para><b>For Beginners:</b> A/B testing lets you try out a new model version on a small percentage |
| 10 | +/// of users before fully deploying it. This helps you: |
| 11 | +/// - Test new models in production safely |
| 12 | +/// - Compare performance between versions with real users |
| 13 | +/// - Gradually roll out changes to minimize risk |
| 14 | +/// - Make data-driven decisions about which model is better |
| 15 | +/// |
| 16 | +/// How it works: |
| 17 | +/// You specify how to split traffic between versions. For example: |
| 18 | +/// - Version 1.0: 80% of traffic (current stable version) |
| 19 | +/// - Version 2.0: 20% of traffic (new experimental version) |
| 20 | +/// |
| 21 | +/// Then you monitor metrics like accuracy, latency, and user satisfaction to decide |
| 22 | +/// which version is better. |
| 23 | +/// |
| 24 | +/// Example: |
| 25 | +/// <code> |
| 26 | +/// var abConfig = new ABTestingConfig |
| 27 | +/// { |
| 28 | +/// Enabled = true, |
| 29 | +/// TrafficSplit = new Dictionary<string, double> |
| 30 | +/// { |
| 31 | +/// { "1.0.0", 0.9 }, |
| 32 | +/// { "2.0.0", 0.1 } |
| 33 | +/// }, |
| 34 | +/// ControlVersion = "1.0.0", |
| 35 | +/// AssignmentStrategy = AssignmentStrategy.Sticky |
| 36 | +/// }; |
| 37 | +/// </code> |
| 38 | +/// </para> |
| 39 | +/// </remarks> |
| 40 | +public class ABTestingConfig |
| 41 | +{ |
| 42 | + /// <summary> |
| 43 | + /// Gets or sets whether A/B testing is enabled (default: false). |
| 44 | + /// </summary> |
| 45 | + /// <remarks> |
| 46 | + /// <para><b>For Beginners:</b> Set to true to enable traffic splitting between model versions. |
| 47 | + /// False means all traffic goes to the default version. |
| 48 | + /// </para> |
| 49 | + /// </remarks> |
| 50 | + public bool Enabled { get; set; } = false; |
| 51 | + |
| 52 | + /// <summary> |
| 53 | + /// Gets or sets the traffic split configuration. |
| 54 | + /// </summary> |
| 55 | + /// <remarks> |
| 56 | + /// <para><b>For Beginners:</b> Dictionary mapping version name to traffic percentage (0.0 to 1.0). |
| 57 | + /// Example: { "1.0": 0.8, "2.0": 0.2 } means 80% on v1.0, 20% on v2.0. |
| 58 | + /// Percentages must sum to 1.0. |
| 59 | + /// </para> |
| 60 | + /// </remarks> |
| 61 | + public Dictionary<string, double> TrafficSplit { get; set; } = new(); |
| 62 | + |
| 63 | + /// <summary> |
| 64 | + /// Gets or sets the strategy for assigning users to versions (default: Random). |
| 65 | + /// </summary> |
| 66 | + /// <remarks> |
| 67 | + /// <para><b>For Beginners:</b> How to assign requests to versions: |
| 68 | + /// - Random: Each request randomly assigned based on traffic split |
| 69 | + /// - Sticky: Users consistently get the same version (based on user ID hash) |
| 70 | + /// - Gradual: Gradually shift traffic from old to new version over time |
| 71 | + /// </para> |
| 72 | + /// </remarks> |
| 73 | + public AssignmentStrategy AssignmentStrategy { get; set; } = AssignmentStrategy.Random; |
| 74 | + |
| 75 | + /// <summary> |
| 76 | + /// Gets or sets the duration in days for the A/B test (default: 7). |
| 77 | + /// </summary> |
| 78 | + /// <remarks> |
| 79 | + /// <para><b>For Beginners:</b> How long to run the test before analyzing results. |
| 80 | + /// 7 days is typical for gathering meaningful data. After this, choose a winner. |
| 81 | + /// </para> |
| 82 | + /// </remarks> |
| 83 | + public int TestDurationDays { get; set; } = 7; |
| 84 | + |
| 85 | + /// <summary> |
| 86 | + /// Gets or sets whether to track experiment assignment for each request (default: true). |
| 87 | + /// </summary> |
| 88 | + /// <remarks> |
| 89 | + /// <para><b>For Beginners:</b> Records which version was used for each request. |
| 90 | + /// Useful for analysis but adds slight overhead. Recommended for A/B testing. |
| 91 | + /// </para> |
| 92 | + /// </remarks> |
| 93 | + public bool TrackAssignments { get; set; } = true; |
| 94 | + |
| 95 | + /// <summary> |
| 96 | + /// Gets or sets the minimum sample size per version before comparing results (default: 1000). |
| 97 | + /// </summary> |
| 98 | + /// <remarks> |
| 99 | + /// <para><b>For Beginners:</b> Need at least this many samples before results are statistically significant. |
| 100 | + /// 1000 is a good minimum. Don't make decisions with fewer samples. |
| 101 | + /// </para> |
| 102 | + /// </remarks> |
| 103 | + public int MinSampleSize { get; set; } = 1000; |
| 104 | + |
| 105 | + /// <summary> |
| 106 | + /// Gets or sets the control group version (baseline for comparison). |
| 107 | + /// </summary> |
| 108 | + /// <remarks> |
| 109 | + /// <para><b>For Beginners:</b> The current production version to compare against. |
| 110 | + /// Typically your stable version. New versions are compared to this baseline. |
| 111 | + /// </para> |
| 112 | + /// </remarks> |
| 113 | + public string? ControlVersion { get; set; } |
| 114 | +} |
0 commit comments