Skip to main content
benchmarkedInspired by Bark-gleaning birds (treecreepers, nuthatches)

Gleaning Policy

Counterpart to Fixed retrieval budgets / static RAG pipelines

Key Properties

  • Marginal value theorem: leave a patch when yield drops below the habitat average
  • Multi-dimensional energy budget (LLM calls, retrieval ops, wall-clock time) with independent depletion
  • Path memory: learned source preferences decay over time, bias future patch ordering
  • Adaptive exploration: cold-start scaffold rate (50%) transitions to configured tissue rate as memory fills
  • Sufficiency integration: stops foraging when cumulative evidence meets threshold
  • Patch-agnostic: works over any retrieval source via the RetrievalPatch trait

Operation Complexity

Side-by-side comparison with the classical counterpart.

Operation complexity comparison
OperationGleaning PolicyFixed retrieval budgets / static RAG pipelines
forage (per query)O(P x S)Fixed pipeline
patch orderingO(P log P)N/A (static ordering)
tick (memory decay)O(M)N/A
record_outcomeO(R)N/A
energy budget checkO(1)O(1) (simple counter)

Interface Preview

gleaning_policy.rs
rust
1pub struct GleaningPolicy { /* ... */ }
2
3impl GleaningPolicy {
4    pub fn new(config: GleaningConfig) -> Result<Self, GleaningError>;
5    pub fn with_defaults() -> Self;
6
7    // Patch management
8    pub fn add_patch(&mut self, patch: Box<dyn RetrievalPatch>);
9    pub fn patch_count(&self) -> usize;
10
11    // Foraging
12    pub fn forage(&mut self, query: &str) -> Result<GleaningResult, GleaningError>;
13    pub fn record_outcome(&mut self, query: &str, quality: f32);
14
15    // Introspection
16    pub fn memory_stats(&self) -> MemoryStats;
17}
18
19impl Maintainable for GleaningPolicy {
20    fn tick(&mut self) -> MaintenanceReport;
21}
22
gleaning_policy.ts
typescript
1class GleaningPolicy {
2  constructor(options?: GleaningPolicyOptions);
3  async init(): Promise<GleaningPolicy>;
4
5  // Patch management
6  addKeywordPatch(name: string, docs: [string, string][]): void;
7  readonly patchCount: number;
8
9  // Foraging
10  forage(query: string): GleaningResult;
11  recordOutcome(query: string, quality: number): void;
12
13  // Maintenance
14  tick(): Record<string, unknown>;
15
16  // Introspection
17  memoryStats(): GleaningMemoryStats;
18}
19

Where This Matters

LangChain / LlamaIndex

RAG Retrieval Pipeline

Improvement comparison
TodayWith Gleaning PolicyHow
Fixed top-k retrieval from all sourcesAdaptive effort allocation via marginal value theoremEasy queries are cheap; hard queries go deep; sources that underperform are abandoned early
No learning from query historyPath memory biases future source orderingSource yield tracked per query signature; decays to prevent staleness
No concept of retrieval budgetMulti-dimensional energy budget with independent depletionLLM calls, retrieval ops, and wall time tracked separately; foraging stops when any is exhausted

Interactive Simulation

Discussion

Questions, ideas, or experiences with Gleaning Policy? Join the discussion.