1616from .file_importance import compute_file_importance
1717from .fragmentation import _process_files_for_fragments
1818from .git import CatFileBatch , GitError , split_diff_range
19+ from .mode import PipelineConfig , ScoringMode
1920from .postpass import _coherence_post_pass , _ensure_changed_files_represented
2021from .render import build_diff_context_output
21- from .scoring import DiscoveryContext , EgoGraphScoring , EnsembleDiscovery , PPRScoring , ScoringStrategy
22+ from .scoring import (
23+ BM25Discovery ,
24+ DefaultDiscovery ,
25+ DiscoveryContext ,
26+ DiscoveryStrategy ,
27+ EgoGraphScoring ,
28+ EnsembleDiscovery ,
29+ PPRScoring ,
30+ ScoringStrategy ,
31+ )
2232from .select import lazy_greedy_select
2333from .signatures import _generate_signature_variants
2434from .types import Fragment , FragmentId
@@ -151,6 +161,12 @@ def _log_ppr_mode(
151161 )
152162
153163
164+ def _create_discovery (config : PipelineConfig ) -> DiscoveryStrategy :
165+ if config .discovery == "ensemble" :
166+ return EnsembleDiscovery ([DefaultDiscovery (), BM25Discovery (top_k = config .bm25_top_k )])
167+ return DefaultDiscovery ()
168+
169+
154170def _empty_tree (root_dir : Path ) -> dict [str , Any ]:
155171 return {
156172 "name" : root_dir .name ,
@@ -171,6 +187,7 @@ def build_diff_context(
171187 no_default_ignores : bool = False ,
172188 full : bool = False ,
173189 whitelist_file : Path | None = None ,
190+ scoring_mode : str = "auto" ,
174191) -> dict [str , Any ]:
175192 _validate_inputs (root_dir , alpha , tau , budget_tokens )
176193 root_dir = root_dir .resolve ()
@@ -217,6 +234,9 @@ def build_diff_context(
217234 except (OSError , UnicodeDecodeError ):
218235 continue
219236
237+ mode = ScoringMode (os .environ .get ("DIFFCTX_SCORING" , scoring_mode ))
238+ config = PipelineConfig .from_mode (mode , n_fragments = len (all_fragments ))
239+
220240 discovery_ctx = DiscoveryContext (
221241 root_dir = root_dir ,
222242 changed_files = changed_files ,
@@ -225,8 +245,7 @@ def build_diff_context(
225245 expansion_concepts = frozenset (expansion_concepts ),
226246 file_cache = file_cache ,
227247 )
228- discovery_strategy = EnsembleDiscovery ()
229- discovered_files = discovery_strategy .discover (discovery_ctx )
248+ discovered_files = _create_discovery (config ).discover (discovery_ctx )
230249 discovered_files = [_normalize_path (p , root_dir ) for p in discovered_files ]
231250 all_fragments .extend (
232251 _process_files_for_fragments (discovered_files , root_dir , preferred_revs , seen_frag_ids , batch_reader )
@@ -275,7 +294,9 @@ def build_diff_context(
275294 hunks = hunks ,
276295 repo_root = root_dir ,
277296 seed_weights = seed_weights ,
278- scoring_strategy = EgoGraphScoring () if os .environ .get ("DIFFCTX_SCORING" ) == "ego" else PPRScoring (alpha = alpha ),
297+ scoring_strategy = (
298+ EgoGraphScoring (max_depth = config .ego_depth ) if config .scoring == "ego" else PPRScoring (alpha = config .ppr_alpha )
299+ ),
279300 discovered_paths = set (discovered_files ),
280301 )
281302 effective_budget = budget_tokens if budget_tokens is not None else _UNLIMITED_BUDGET
0 commit comments