Expand description
Context Field Theory (CFT) – unified potential function for context items.
Combines information-theoretic, graph-based, and history signals into a single scalar potential Phi(i,t) per context item, enabling principled budget allocation and view selection.
Scientific basis: Phi(i,t) = w_RR + w_SS + w_GG + w_HH - w_CC - w_DD where R = task relevance (heat diffusion + PageRank), S = surprise (cross-entropy with Zipfian prior), G = graph proximity (weighted BFS distance), H = history signal (bandit feedback), C = token cost for the active view, D = redundancy with already-selected items (Jaccard).
Structs§
- Context
Field - The Context Field: computes Phi for a set of items given a task context.
- Context
Item Id - Stable, content-addressed identifier for a context item.
Derived from
kind + source_pathso the same file always maps to the same ID within a session, regardless of content changes. - Field
Potential - Combined potential for a context item.
- Field
Signals - Raw signal components for a single context item before combination.
- Field
Weights - Weights for the potential function components. Adapted via Thompson Sampling (bandit.rs) over time.
- Provenance
- Token
Budget - Token budget parameters for compilation.
- View
Costs - Token-cost estimates for each available view of a context item.
Enums§
Functions§
- compute_
signals_ for_ path - Compute real signals for a file path using existing scoring modules. Bridges CFT with the information-theoretic, graph-based, and history subsystems already in lean-ctx.
- efficiency
- Compute efficiency ratio: Phi per token. Used by the greedy knapsack in the compiler.
- normalize_
graph_ proximity - Normalize graph proximity (inverse of distance) to [0, 1]. Distance 0 = same file = 1.0, distance N = 1/(1+N).
- normalize_
relevance - Normalize a relevance score from task_relevance.rs to [0, 1].
- normalize_
surprise - Normalize a surprise score from surprise.rs to [0, 1]. Surprise range is typically 5.0 (common) to 17.0+ (rare).
- normalize_
token_ cost - Normalize token cost relative to budget.