5
5
6
6
from onyx .chat .turn .models import MyContext
7
7
from onyx .db .engine .sql_engine import get_session_with_current_tenant
8
+ from onyx .server .query_and_chat .streaming_models import Packet
9
+ from onyx .server .query_and_chat .streaming_models import SavedSearchDoc
10
+ from onyx .server .query_and_chat .streaming_models import SearchToolDelta
11
+ from onyx .server .query_and_chat .streaming_models import SearchToolStart
12
+ from onyx .server .query_and_chat .streaming_models import SectionEnd
8
13
from onyx .tools .models import SearchToolOverrideKwargs
9
14
from onyx .tools .tool_implementations .search .search_tool import (
10
15
SEARCH_RESPONSE_SUMMARY_ID ,
13
18
14
19
15
20
@function_tool
16
- def internal_search (context_wrapper : RunContextWrapper [MyContext ], query : str ) -> str :
21
+ def internal_search (run_context : RunContextWrapper [MyContext ], query : str ) -> str :
17
22
"""
18
23
Search the internal knowledge base and documents.
19
24
@@ -24,10 +29,23 @@ def internal_search(context_wrapper: RunContextWrapper[MyContext], query: str) -
24
29
Args:
25
30
query: The natural-language search query.
26
31
"""
27
- context_wrapper .context .run_dependencies .emitter .emit (
28
- kind = "tool-progress" , data = {"query" : query }
32
+ run_context .context .run_dependencies .emitter .emit (
33
+ Packet (
34
+ ind = run_context .context .current_run_step + 1 ,
35
+ obj = SearchToolStart (
36
+ type = "internal_search_tool_start" , is_internet_search = False
37
+ ),
38
+ )
39
+ )
40
+ run_context .context .run_dependencies .emitter .emit (
41
+ Packet (
42
+ ind = run_context .context .current_run_step + 1 ,
43
+ obj = SearchToolDelta (
44
+ type = "internal_search_tool_delta" , queries = [query ], documents = None
45
+ ),
46
+ )
29
47
)
30
- search_tool = context_wrapper .context .run_dependencies .search_tool
48
+ search_tool = run_context .context .run_dependencies .search_tool
31
49
if search_tool is None :
32
50
raise RuntimeError ("Search tool not available in context" )
33
51
@@ -45,6 +63,46 @@ def internal_search(context_wrapper: RunContextWrapper[MyContext], query: str) -
45
63
if tool_response .id == SEARCH_RESPONSE_SUMMARY_ID :
46
64
response = cast (SearchResponseSummary , tool_response .response )
47
65
retrieved_docs = response .top_sections
48
-
66
+ run_context .context .run_dependencies .emitter .emit (
67
+ Packet (
68
+ ind = run_context .context .current_run_step + 1 ,
69
+ obj = SearchToolDelta (
70
+ type = "internal_search_tool_delta" ,
71
+ queries = None ,
72
+ documents = [
73
+ SavedSearchDoc (
74
+ db_doc_id = 0 ,
75
+ document_id = doc .center_chunk .document_id ,
76
+ chunk_ind = 0 ,
77
+ semantic_identifier = doc .center_chunk .semantic_identifier ,
78
+ link = doc .center_chunk .semantic_identifier ,
79
+ blurb = doc .center_chunk .blurb ,
80
+ source_type = doc .center_chunk .source_type ,
81
+ boost = doc .center_chunk .boost ,
82
+ hidden = doc .center_chunk .hidden ,
83
+ metadata = doc .center_chunk .metadata ,
84
+ score = doc .center_chunk .score ,
85
+ is_relevant = doc .center_chunk .is_relevant ,
86
+ relevance_explanation = doc .center_chunk .relevance_explanation ,
87
+ match_highlights = doc .center_chunk .match_highlights ,
88
+ updated_at = doc .center_chunk .updated_at ,
89
+ primary_owners = doc .center_chunk .primary_owners ,
90
+ secondary_owners = doc .center_chunk .secondary_owners ,
91
+ is_internet = False ,
92
+ )
93
+ for doc in retrieved_docs
94
+ ],
95
+ ),
96
+ )
97
+ )
49
98
break
99
+ run_context .context .run_dependencies .emitter .emit (
100
+ Packet (
101
+ ind = run_context .context .current_run_step + 1 ,
102
+ obj = SectionEnd (
103
+ type = "section_end" ,
104
+ ),
105
+ )
106
+ )
107
+ run_context .context .current_run_step += 2
50
108
return retrieved_docs
0 commit comments