5
5
6
6
from sqlalchemy .orm import Session
7
7
8
+ from onyx .chat .models import ContextualPruningConfig
8
9
from onyx .chat .models import PromptConfig
9
10
from onyx .chat .models import SectionRelevancePiece
10
11
from onyx .chat .prune_and_merge import _merge_sections
11
12
from onyx .chat .prune_and_merge import ChunkRange
12
13
from onyx .chat .prune_and_merge import merge_chunk_intervals
14
+ from onyx .chat .prune_and_merge import prune_and_merge_sections
13
15
from onyx .configs .chat_configs import DISABLE_LLM_DOC_RELEVANCE
14
16
from onyx .context .search .enums import LLMEvaluationType
15
17
from onyx .context .search .enums import QueryFlow
@@ -61,6 +63,7 @@ def __init__(
61
63
| None = None ,
62
64
rerank_metrics_callback : Callable [[RerankMetricsContainer ], None ] | None = None ,
63
65
prompt_config : PromptConfig | None = None ,
66
+ contextual_pruning_config : ContextualPruningConfig | None = None ,
64
67
):
65
68
# NOTE: The Search Request contains a lot of fields that are overrides, many of them can be None
66
69
# and typically are None. The preprocessing will fetch default values to replace these empty overrides.
@@ -77,6 +80,9 @@ def __init__(
77
80
self .search_settings = get_current_search_settings (db_session )
78
81
self .document_index = get_default_document_index (self .search_settings , None )
79
82
self .prompt_config : PromptConfig | None = prompt_config
83
+ self .contextual_pruning_config : ContextualPruningConfig | None = (
84
+ contextual_pruning_config
85
+ )
80
86
81
87
# Preprocessing steps generate this
82
88
self ._search_query : SearchQuery | None = None
@@ -420,7 +426,26 @@ def final_context_sections(self) -> list[InferenceSection]:
420
426
if self ._final_context_sections is not None :
421
427
return self ._final_context_sections
422
428
423
- self ._final_context_sections = _merge_sections (sections = self .reranked_sections )
429
+ if (
430
+ self .contextual_pruning_config is not None
431
+ and self .prompt_config is not None
432
+ ):
433
+ self ._final_context_sections = prune_and_merge_sections (
434
+ sections = self .reranked_sections ,
435
+ section_relevance_list = None ,
436
+ prompt_config = self .prompt_config ,
437
+ llm_config = self .llm .config ,
438
+ question = self .search_query .query ,
439
+ contextual_pruning_config = self .contextual_pruning_config ,
440
+ )
441
+
442
+ else :
443
+ logger .error (
444
+ "Contextual pruning or prompt config not set, using default merge"
445
+ )
446
+ self ._final_context_sections = _merge_sections (
447
+ sections = self .reranked_sections
448
+ )
424
449
return self ._final_context_sections
425
450
426
451
@property
0 commit comments