@@ -196,26 +196,42 @@ defmodule Canary.Index.Trieve.Actual do
196196 end
197197
198198 def search ( client , query , opts \\ [ ] ) do
199- tags = opts [ :tags ]
200- search_type = if ( question? ( query ) , do: :hybrid , else: :fulltext )
201- receive_timeout = if ( question? ( query ) , do: 3_000 , else: 1_500 )
202- score_threshold = if ( question? ( query ) , do: 0.0 , else: 0.05 )
199+ rag? = Keyword . get ( opts , :rag , false )
200+ tags = Keyword . get ( opts , :tags , nil )
201+
202+ search_type = if ( rag? or question? ( query ) , do: :hybrid , else: :fulltext )
203+ receive_timeout = if ( rag? or question? ( query ) , do: 3_000 , else: 1_500 )
204+ remove_stop_words = not ( rag? or question? ( query ) )
205+ page_size = if ( rag? , do: 10 , else: 24 )
206+ group_size = if ( rag? , do: 5 , else: 3 )
207+
208+ score_threshold =
209+ cond do
210+ rag? -> 0.0
211+ question? ( query ) -> 0.0
212+ true -> 0.05
213+ end
203214
204215 highlight_options =
205- if question? ( query ) do
206- % {
207- highlight_window: 8 ,
208- highlight_max_length: 5 ,
209- highlight_threshold: 0.5 ,
210- highlight_strategy: :v1
211- }
212- else
213- % {
214- highlight_window: 8 ,
215- highlight_max_length: 2 ,
216- highlight_threshold: 0.9 ,
217- highlight_strategy: :exactmatch
218- }
216+ cond do
217+ rag? ->
218+ % { highlight_results: false }
219+
220+ question? ( query ) ->
221+ % {
222+ highlight_window: 8 ,
223+ highlight_max_length: 5 ,
224+ highlight_threshold: 0.5 ,
225+ highlight_strategy: :v1
226+ }
227+
228+ true ->
229+ % {
230+ highlight_window: 8 ,
231+ highlight_max_length: 2 ,
232+ highlight_threshold: 0.9 ,
233+ highlight_strategy: :exactmatch
234+ }
219235 end
220236
221237 filters = % {
@@ -244,32 +260,31 @@ defmodule Canary.Index.Trieve.Actual do
244260 query: query ,
245261 filters: filters ,
246262 page: 1 ,
247- page_size: 24 ,
248- group_size: 3 ,
263+ page_size: page_size ,
264+ group_size: group_size ,
249265 search_type: search_type ,
250266 score_threshold: score_threshold ,
251- remove_stop_words: true ,
252- slim_chunks: false ,
267+ remove_stop_words: remove_stop_words ,
253268 typo_options: % {
254269 correct_typos: true ,
255270 one_typo_word_range: % {
256271 min: 3 ,
257- max: 9
272+ max: 3 * 3
258273 } ,
259274 two_typo_word_range: % {
260275 min: 4 ,
261- max: 12
276+ max: 4 * 3
262277 }
263278 } ,
264279 highlight_options:
265280 Map . merge (
266- highlight_options ,
267281 % {
268282 highlight_results: true ,
269283 highlight_max_num: 1 ,
270284 pre_tag: "<mark>" ,
271285 post_tag: "</mark>"
272- }
286+ } ,
287+ highlight_options
273288 )
274289 }
275290 ) do
0 commit comments