MoonRAGBench is a MoonBit-native toolkit for retrieval and RAG benchmark evaluation.
Dependencies
eval --qrels FILE --run FILE [--format text|markdown|json|csv|jsonl]
validate --qrels FILE --run FILE [--format text|markdown|json]
inspect --qrels FILE --run FILE
compare --qrels FILE --baseline FILE --candidate FILE [--cutoff N]
sample-negatives --qrels FILE --run FILE [--pool FILE]moon run cmd/main --target native -- validate \
--qrels examples/benchmark/qrels.tsv \
--run examples/benchmark/run_reranked.tsv
moon run cmd/main --target native -- compare \
--qrels examples/benchmark/qrels.tsv \
--baseline examples/benchmark/run_baseline.tsv \
--candidate examples/benchmark/run_reranked.tsv \
--cutoff 3
moon run cmd/main --target native -- sample-negatives \
--qrels examples/benchmark/qrels.tsv \
--run examples/benchmark/run_baseline.tsv \
--pool examples/benchmark/pool.tsv \
--count 2 --strategy hard --window 3query_id<TAB>doc_id<TAB>relevancequery_id<TAB>doc_id<TAB>scorequery_id<TAB>doc_idqrels/run/pool TSV
│
├── parse + strict validation + normalization
│
├── metrics / comparison / dataset statistics / sampling
│
└── reports: text · Markdown · CSV · JSON · JSONL · HTML./scripts/benchmark.ps1moon fmt --check
moon check --target all --deny-warn
moon test --target wasm --deny-warn
moon test --target wasm-gc --deny-warn
moon test --target js --deny-warn
moon info
moon run cmd/main --target native -- demomoon publishfn BenchmarkCase::new(name~ : String, qrels~ : Array[JudgedDoc], run~ : Array[RetrievedDoc]) -> BenchmarkCasefn BenchmarkManifest::new(name~ : String, version~ : String, license~ : String, qrels~ : Array[JudgedDoc], run~ : Array[RetrievedDoc]) -> BenchmarkManifestpub struct BenchmarkReport {
cutoffs : Array[Int]
relevant_threshold : Int
query_count : Int
queries : Array[QueryEvaluation]
summary : Array[AggregateMetric]
} derive(ToJson, Debug)pub struct BenchmarkResult {
name : String
report : BenchmarkReport
validation : ValidationSummary
} derive(ToJson, Debug)pub enum CliRequest {
Demo
Eval(qrels_path~ : String, run_path~ : String, format~ : CliFormat, cutoffs~ : Array[Int], threshold~ : Int, gain~ : GainScheme)
Validate(qrels_path~ : String, run_path~ : String, format~ : CliFormat)
Compare(qrels_path~ : String, baseline_path~ : String, candidate_path~ : String, cutoff~ : Int)
Inspect(qrels_path~ : String, run_path~ : String)
} derive(ToJson, Debug)pub struct CorpusProfile {
query_count : Int
qrels_rows : Int
run_rows : Int
unique_document_count : Int
relevant_document_count : Int
max_relevance : Int
unjudged_retrievals : Int
mean_judgments_per_query : Double
mean_run_length : Double
mean_score : Double
score_stddev : Double
} derive(ToJson, Debug)pub struct DatasetProfile {
query_count : Int
judged_count : Int
retrieved_count : Int
relevant_count : Int
run_query_coverage : Double
qrels_query_coverage : Double
mean_run_length : Double
mean_score : Double
score_stddev : Double
unjudged_retrievals : Int
empty_query_count : Int
duplicate_query_count : Int
} derive(ToJson, Debug)pub struct EvalConfig {
cutoffs : Array[Int]
relevant_threshold : Int
gain_scheme : GainScheme
missing_relevance : Int
} derive(ToJson, Debug)fn EvalConfig::new(cutoffs~ : Array[Int], relevant_threshold? : Int, gain_scheme? : GainScheme, missing_relevance? : Int) -> EvalConfigpub struct EvaluationPlan {
name : String
cutoffs : Array[Int]
threshold : Int
gain : GainScheme
} derive(ToJson, Debug)fn EvaluationPlan::new(name~ : String, cutoffs~ : Array[Int], threshold~ : Int, gain~ : GainScheme) -> EvaluationPlanpub struct NegativeSampleConfig {
per_query : Int
relevant_threshold : Int
skip_judged : Bool
strategy : NegativeStrategy
} derive(ToJson, Debug)fn NegativeSampleConfig::new(per_query~ : Int, relevant_threshold? : Int, skip_judged? : Bool, strategy? : NegativeStrategy) -> NegativeSampleConfigpub struct PlanResult {
name : String
report : BenchmarkReport
validation : ValidationSummary
} derive(ToJson, Debug)pub struct RunComparison {
cutoff : Int
query_count : Int
wins : Int
losses : Int
ties : Int
mean_delta : Double
queries : Array[QueryComparison]
} derive(ToJson, Debug)pub struct ValidationIssue {
code : String
level : ValidationLevel
message : String
query_id : String
doc_id : String
} derive(Eq, ToJson, Debug)pub struct ValidationSummary {
error_count : Int
warning_count : Int
query_count : Int
judged_count : Int
retrieved_count : Int
issues : Array[ValidationIssue]
} derive(ToJson, Debug)fn average_precision_at(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], cutoff : Int, threshold : Int) -> Doublefn blend_runs(left : Array[RetrievedDoc], right : Array[RetrievedDoc], left_weight? : Double) -> Array[RetrievedDoc]fn bpref_at(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], cutoff : Int, threshold : Int) -> Doublefn compare_benchmark_cases(baseline : BenchmarkCase, candidate : BenchmarkCase, cutoff~ : Int) -> RunComparisonfn compare_runs(qrels : Array[JudgedDoc], baseline : Array[RetrievedDoc], candidate : Array[RetrievedDoc], cutoff~ : Int) -> RunComparisonfn err_at(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], cutoff : Int, threshold : Int) -> Doublefn evaluate_benchmark(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], config? : EvalConfig) -> BenchmarkReportfn evaluate_metric_family(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], cutoff : Int, threshold : Int, gain_scheme : GainScheme) -> Map[String, Double]fn evaluate_query(query_id : String, qrels : Array[JudgedDoc], run : Array[RetrievedDoc], config? : EvalConfig) -> QueryEvaluationfn evaluate_with_preset(name : String, qrels : Array[JudgedDoc], run : Array[RetrievedDoc]) -> Result[BenchmarkReport, String]fn execute_plan(plan : EvaluationPlan, qrels : Array[JudgedDoc], run : Array[RetrievedDoc]) -> PlanResultfn execute_plan_with_profile(plan : EvaluationPlan, qrels : Array[JudgedDoc], run : Array[RetrievedDoc]) -> Stringfn f1_at(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], cutoff : Int, threshold : Int) -> Doublefn f1_from_counts(relevant_retrieved : Int, retrieved : Int, relevant : Int) -> Doublefn fallout_at(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], cutoff : Int, threshold : Int) -> Doublefn filter_run_by_queries(run : Array[RetrievedDoc], query_ids : Array[String]) -> Array[RetrievedDoc]fn graded_precision_at(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], cutoff : Int, threshold : Int, gain_scheme : GainScheme) -> Doublefn jaccard_at(left : Array[RetrievedDoc], right : Array[RetrievedDoc], query_id : String, cutoff : Int) -> Doublefn manifest_with_pools(name~ : String, version~ : String, license~ : String, qrels~ : Array[JudgedDoc], run~ : Array[RetrievedDoc], pools~ : Array[CandidatePool]) -> BenchmarkManifestfn merge_candidate_pools(left : Array[CandidatePool], right : Array[CandidatePool]) -> Array[CandidatePool]fn metric_rank_delta(baseline : BenchmarkReport, candidate : BenchmarkReport, metric : String, query_id : String) -> Intfn metric_wins(baseline : BenchmarkReport, candidate : BenchmarkReport, name : String) -> (Int, Int, Int)fn ndcg_at(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], cutoff : Int, threshold : Int, gain_scheme : GainScheme) -> Doublefn normalize_inputs(qrels : Array[JudgedDoc], run : Array[RetrievedDoc]) -> (Array[JudgedDoc], Array[RetrievedDoc])fn overlap_at(baseline : Array[RetrievedDoc], candidate : Array[RetrievedDoc], query_id : String, cutoff : Int) -> Intfn plan_sampling(qrels : Array[JudgedDoc], pools : Array[CandidatePool], total_budget~ : Int) -> Stringfn precision_at(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], cutoff : Int, threshold : Int) -> Doublefn precision_curve(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], cutoff : Int, threshold : Int) -> Array[Double]fn precision_from_counts(relevant_retrieved : Int, retrieved : Int) -> Doublefn precision_recall_area(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], cutoff : Int, threshold : Int) -> Doublefn rank_biased_overlap(left : Array[RetrievedDoc], right : Array[RetrievedDoc], query_id : String, cutoff : Int, persistence? : Double) -> Doublefn rank_movement(baseline : Array[RetrievedDoc], candidate : Array[RetrievedDoc], query_id : String, cutoff : Int) -> Intfn rbp_at(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], cutoff : Int, threshold : Int, persistence? : Double) -> Doublefn recall_at(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], cutoff : Int, threshold : Int) -> Doublefn recall_curve(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], cutoff : Int, threshold : Int) -> Array[Double]fn reciprocal_rank_at(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], cutoff : Int, threshold : Int) -> Doublefn relevant_rank_positions(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], threshold : Int) -> Array[Int]fn safe_compare(qrels : Array[JudgedDoc], baseline : Array[RetrievedDoc], candidate : Array[RetrievedDoc]) -> Result[RunComparison, String]fn safe_evaluate(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], config? : EvalConfig) -> Result[BenchmarkReport, String]fn safe_parse_and_evaluate(qrels_source : String, run_source : String, config : EvalConfig) -> Result[BenchmarkReport, String]fn safe_report_json(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], config? : EvalConfig) -> Result[String, String]fn safe_sample(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], config : NegativeSampleConfig) -> Result[Array[NegativeSample], String]fn sample_hard_and_tail(qrels : Array[JudgedDoc], pools : Array[CandidatePool], per_query~ : Int, window~ : Int) -> Array[NegativeSample]fn sample_negatives(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], pools? : Array[CandidatePool], config? : NegativeSampleConfig) -> Array[NegativeSample]fn sample_pool_negatives(qrels : Array[JudgedDoc], pools : Array[CandidatePool], config? : NegativeSampleConfig) -> Array[NegativeSample]fn sample_pool_negatives_tsv(qrels : Array[JudgedDoc], pools : Array[CandidatePool], config? : NegativeSampleConfig) -> Stringfn sample_with_budget(qrels : Array[JudgedDoc], pools : Array[CandidatePool], total_budget~ : Int) -> Array[NegativeSample]fn sampling_plan(qrels : Array[JudgedDoc], pools : Array[CandidatePool], config? : NegativeSampleConfig) -> Stringfn sampling_yield(qrels : Array[JudgedDoc], pools : Array[CandidatePool], samples : Array[NegativeSample]) -> Doublefn score_order_correlation(left : Array[RetrievedDoc], right : Array[RetrievedDoc], query_id : String, cutoff : Int) -> Doublefn select_queries_by_score(report : BenchmarkReport, metric : String, minimum : Double) -> Array[String]fn threshold_sweep(qrels : Array[JudgedDoc], run : Array[RetrievedDoc], thresholds~ : Array[Int], cutoffs~ : Array[Int]) -> Array[ThresholdEvaluation]MoonRAGBench is a MoonBit-native toolkit for retrieval and RAG benchmark evaluation.
Dependencies