-
Notifications
You must be signed in to change notification settings - Fork 0
CF benchmark remediation: honest evidence-selection fix + Foundry F-1 start #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e18d11f
Add expanded, un-marked corpus generator + open-extraction reader mode
hardcoreerik db5c3bc
Generate the 85 host-templated questions for the expanded corpus
hardcoreerik dcffd05
External authorship for the 65 remaining question categories, plus a …
hardcoreerik 0673278
Split the verified 150-question suite into development/held-out sets
hardcoreerik 01f3fd0
CF benchmark remediation: JSON recovery, baseline completion, admissi…
hardcoreerik 4497278
Add CF-7 gate re-run script and update bench help text
hardcoreerik 8590775
Clear two CS8601 nullable warnings and ignore publish-* variants
hardcoreerik ab7f364
docs: add TheOrc Warpath gamification whitepaper
hardcoreerik 9f1d830
Foundry F-1: frozen toolcaller-v0 tool inventory, capture schema, val…
hardcoreerik 18f45ea
Merge origin/master (Foundry F-0 docs, PR #33) into cf-benchmark-reme…
hardcoreerik 4e9c2ac
Link F-1 docs and CF-7 re-run script from their doc indexes
hardcoreerik 6dd6f48
Capture real toolcaller-v0 data from live swarm tool-call decisions
hardcoreerik c55e505
Rewrite B2 top-k RAG baseline: IDF-weighted scoring, budget-fill inst…
hardcoreerik c68e01c
Fix Context Fabric evidence-pack selection: IDF-weighted scoring, no …
hardcoreerik 3ef5fb0
Fix Exhaustive-answer over-inclusion: entity-scoped vs category-wide …
hardcoreerik 40d79e1
Address Grok adversarial review of the Exhaustive-answer fix
hardcoreerik 2e18805
Make Foundry F-1 dataset capture opt-in with a status bar indicator
hardcoreerik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
OrchestratorIDE.UnitTests/ContextFabricB2TopKRagTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| // Copyright (C) 2025-present hardcoreerik / TheOrc contributors | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
| using NUnit.Framework; | ||
| using OrchestratorIDE.Services.ContextFabric; | ||
|
|
||
| namespace OrchestratorIDE.UnitTests; | ||
|
|
||
| /// <summary> | ||
| /// Covers the B2 "conventional top-k RAG" baseline rewrite: IDF-weighted, stopword-aware segment | ||
| /// scoring, and greedy budget-filling selection instead of a fixed segment count. | ||
| /// </summary> | ||
| [TestFixture] | ||
| public sealed class ContextFabricB2TopKRagTests | ||
| { | ||
| // FabricContextBudget enforces ContextLimit >= 2048 and EvidenceLimit (ContextLimit minus its | ||
| // own 1536/512 reserves) > 0, so tests must keep ContextLimit comfortably above 2048 and | ||
| // instead tune AnswerMaxTokens (a separate FabricRunOptions field the runner's own budget | ||
| // math actually subtracts) to get a tight or exhausted effective budget. | ||
| private static FabricRunOptions Options(int answerMaxTokens) => | ||
| new(new FabricContextBudget(ContextLimit: 2200), AnswerMaxTokens: answerMaxTokens); | ||
|
|
||
| [Test] | ||
| public void BuildTopKText_PrefersSegmentWithRareDistinctiveTerm_OverCommonWordOverlap() | ||
| { | ||
| // "checksum" and "CK-991" are rare/distinctive; "the", "was", "and" appear everywhere and | ||
| // must not drive the ranking. | ||
| var target = new FabricSegment("seg-target", 1, "Target", | ||
| "The archive recorded the checksum CK-991 for this shipment.", | ||
| FabricHashing.Sha256("target"), 20); | ||
| var distractor = new FabricSegment("seg-distractor", 2, "Distractor", | ||
| "The archive and the depot were and the records were the same as the other archive.", | ||
| FabricHashing.Sha256("distractor"), 20); | ||
| var corpus = new FabricCorpus("corpus-1", "doc-1", "gen-1", "digest-1", "1.0", | ||
| [target, distractor], 40); | ||
| var question = new FabricBenchmarkQuestion( | ||
| "q-1", FabricQuestionKind.LocalFact, "What checksum was recorded for the shipment?", | ||
| ["CK-991"], ["seg-target"]); | ||
| var fixture = new FabricBenchmarkFixture(corpus, [question]); | ||
|
|
||
| // AnswerMaxTokens tuned so the effective budget (~25 tokens) fits one 20-token segment | ||
| // but not both (40 total) -- forces the ranking to actually decide, rather than both | ||
| // segments trivially fitting. | ||
| var runner = new ContextFabricBaselineRunner(new ScriptedFabricRuntime(), Options(answerMaxTokens: 1652)); | ||
| var text = runner.BuildTopKText(fixture, question); | ||
|
|
||
| Assert.That(text, Does.Contain("CK-991")); | ||
| Assert.That(text, Does.Not.Contain(distractor.Text)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void BuildTopKText_SelectsMoreThanFourSegments_WhenBudgetAllowsAndAllAreRelevant() | ||
| { | ||
| // Six short segments, each sharing a distinctive term with the question. The old | ||
| // implementation hard-capped at 4 regardless of budget; this must not. | ||
| var segments = Enumerable.Range(1, 6) | ||
| .Select(i => new FabricSegment($"seg-{i}", i, $"Section {i}", | ||
| $"Station Bravo logged a distinct reading labeled MARK-{i:D3} during this cycle.", | ||
| FabricHashing.Sha256($"seg-{i}"), 20)) | ||
| .ToArray(); | ||
| var corpus = new FabricCorpus("corpus-2", "doc-2", "gen-2", "digest-2", "1.0", segments, 120); | ||
| var question = new FabricBenchmarkQuestion( | ||
| "q-2", FabricQuestionKind.Exhaustive, | ||
| "What readings did Station Bravo log across the cycle?", | ||
| ["MARK-001"], ["seg-1"]); | ||
| var fixture = new FabricBenchmarkFixture(corpus, [question]); | ||
|
|
||
| // Generous budget: 8192 limit easily fits all six ~20-token segments plus overhead. | ||
| var runner = new ContextFabricBaselineRunner(new ScriptedFabricRuntime(), FabricRunOptions.Default); | ||
| var text = runner.BuildTopKText(fixture, question); | ||
|
|
||
| var includedCount = segments.Count(s => text.Contains(s.Text, StringComparison.Ordinal)); | ||
| Assert.That(includedCount, Is.GreaterThan(4)); | ||
| } | ||
|
|
||
| [Test] | ||
| public void BuildTopKText_ReturnsEmpty_WhenQuestionHasNoNonStopwordTerms() | ||
| { | ||
| var segment = new FabricSegment("seg-a", 1, "A", "Some genuinely distinctive content ABC-123.", | ||
| FabricHashing.Sha256("a"), 10); | ||
| var corpus = new FabricCorpus("corpus-3", "doc-3", "gen-3", "digest-3", "1.0", [segment], 10); | ||
| // Every word here is a stopword per the runner's list. | ||
| var question = new FabricBenchmarkQuestion( | ||
| "q-3", FabricQuestionKind.LocalFact, "What was this and that with the same?", | ||
| ["ABC-123"], ["seg-a"]); | ||
| var fixture = new FabricBenchmarkFixture(corpus, [question]); | ||
|
|
||
| var runner = new ContextFabricBaselineRunner(new ScriptedFabricRuntime(), Options(answerMaxTokens: 1500)); | ||
| var text = runner.BuildTopKText(fixture, question); | ||
|
|
||
| Assert.That(text, Is.Empty); | ||
| } | ||
|
|
||
| [Test] | ||
| public void BuildTopKText_ReturnsEmpty_WhenBudgetIsExhausted() | ||
| { | ||
| var segment = new FabricSegment("seg-a", 1, "A", "A checksum CK-500 was recorded here.", | ||
| FabricHashing.Sha256("a"), 20); | ||
| var corpus = new FabricCorpus("corpus-4", "doc-4", "gen-4", "digest-4", "1.0", [segment], 20); | ||
| var question = new FabricBenchmarkQuestion( | ||
| "q-4", FabricQuestionKind.LocalFact, "What checksum was recorded?", | ||
| ["CK-500"], ["seg-a"]); | ||
| var fixture = new FabricBenchmarkFixture(corpus, [question]); | ||
|
|
||
| // AnswerMaxTokens tuned so ContextLimit(2200) - AnswerMaxTokens - question - 512 is negative. | ||
| var runner = new ContextFabricBaselineRunner(new ScriptedFabricRuntime(), Options(answerMaxTokens: 1700)); | ||
| var text = runner.BuildTopKText(fixture, question); | ||
|
|
||
| Assert.That(text, Is.Empty); | ||
| } | ||
|
|
||
| [Test] | ||
| public void BuildTopKText_SkipsOverBudgetSegment_ButStillFitsShorterLowerRankedOne() | ||
| { | ||
| // The highest-scoring segment is too large to fit; a shorter, lower-scoring but still | ||
| // relevant segment should still be included rather than leaving the budget unused. | ||
| var big = new FabricSegment("seg-big", 1, "Big", | ||
| "checksum CK-777 checksum CK-777 checksum CK-777 padding padding padding padding padding padding padding", | ||
| FabricHashing.Sha256("big"), 500); | ||
| var small = new FabricSegment("seg-small", 2, "Small", "checksum CK-777 noted briefly.", | ||
| FabricHashing.Sha256("small"), 15); | ||
| var corpus = new FabricCorpus("corpus-5", "doc-5", "gen-5", "digest-5", "1.0", [big, small], 515); | ||
| var question = new FabricBenchmarkQuestion( | ||
| "q-5", FabricQuestionKind.LocalFact, "What checksum was noted?", ["CK-777"], ["seg-small"]); | ||
| var fixture = new FabricBenchmarkFixture(corpus, [question]); | ||
|
|
||
| // AnswerMaxTokens tuned so the effective budget (~50 tokens) fits "small" (15 tokens) but | ||
| // not "big" (500 tokens), even though "big" scores higher (three checksum mentions). | ||
| var runner = new ContextFabricBaselineRunner(new ScriptedFabricRuntime(), Options(answerMaxTokens: 1632)); | ||
| var text = runner.BuildTopKText(fixture, question); | ||
|
|
||
| Assert.That(text, Does.Contain("noted briefly")); | ||
| Assert.That(text, Does.Not.Contain("padding")); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Test doesn't actually exercise its stated scenario —
Tokenizededupes per segment, so "big" doesn't outscore "small".Tokenizereturns aHashSet<string>per segment (ContextFabricBaselineRunner.csline 478-483), so repeated occurrences of "checksum" inbigdon't increase its score — only presence matters. Computing IDF scores here:checksumhas document-frequency 2 (df across both segments),notedhas df 1 (only insmall). That givessmalla higher score (0.5 + 1.0 = 1.5) thanbig(0.5), not lower as the in-line comment claims ("even though 'big' scores higher"). The test still passes because the budget happens to only fitsmallregardless of ranking, but it never actually exercises the intended case — a higher-ranked-but-oversized segment being skipped in favor of a genuinely lower-ranked-but-smaller one that still fits.🧪 Suggested fix: make "big" genuinely outrank "small"
📝 Committable suggestion
🤖 Prompt for AI Agents