Skip to content

Commit be1a222

Browse files
joachim-danswerpablonyx
authored andcommitted
Simpler approach
1 parent b7ece29 commit be1a222

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

backend/onyx/context/search/pipeline.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
from sqlalchemy.orm import Session
77

8+
from onyx.chat.models import ContextualPruningConfig
89
from onyx.chat.models import PromptConfig
910
from onyx.chat.models import SectionRelevancePiece
1011
from onyx.chat.prune_and_merge import _merge_sections
1112
from onyx.chat.prune_and_merge import ChunkRange
1213
from onyx.chat.prune_and_merge import merge_chunk_intervals
14+
from onyx.chat.prune_and_merge import prune_and_merge_sections
1315
from onyx.configs.chat_configs import DISABLE_LLM_DOC_RELEVANCE
1416
from onyx.context.search.enums import LLMEvaluationType
1517
from onyx.context.search.enums import QueryFlow
@@ -61,6 +63,7 @@ def __init__(
6163
| None = None,
6264
rerank_metrics_callback: Callable[[RerankMetricsContainer], None] | None = None,
6365
prompt_config: PromptConfig | None = None,
66+
contextual_pruning_config: ContextualPruningConfig | None = None,
6467
):
6568
# NOTE: The Search Request contains a lot of fields that are overrides, many of them can be None
6669
# and typically are None. The preprocessing will fetch default values to replace these empty overrides.
@@ -77,6 +80,9 @@ def __init__(
7780
self.search_settings = get_current_search_settings(db_session)
7881
self.document_index = get_default_document_index(self.search_settings, None)
7982
self.prompt_config: PromptConfig | None = prompt_config
83+
self.contextual_pruning_config: ContextualPruningConfig | None = (
84+
contextual_pruning_config
85+
)
8086

8187
# Preprocessing steps generate this
8288
self._search_query: SearchQuery | None = None
@@ -420,7 +426,26 @@ def final_context_sections(self) -> list[InferenceSection]:
420426
if self._final_context_sections is not None:
421427
return self._final_context_sections
422428

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+
)
424449
return self._final_context_sections
425450

426451
@property

backend/onyx/tools/tool_implementations/search/search_tool.py

+2
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ def run(
376376
db_session=alternate_db_session or self.db_session,
377377
prompt_config=self.prompt_config,
378378
retrieved_sections_callback=retrieved_sections_callback,
379+
contextual_pruning_config=self.contextual_pruning_config,
379380
)
380381

381382
search_query_info = SearchQueryInfo(
@@ -447,6 +448,7 @@ def _run_ordering_only_search(
447448
db_session=self.db_session,
448449
bypass_acl=self.bypass_acl,
449450
prompt_config=self.prompt_config,
451+
contextual_pruning_config=self.contextual_pruning_config,
450452
)
451453

452454
# Log what we're doing

0 commit comments

Comments
 (0)