Skip to content

Commit 09f1252

Browse files
committed
update search options
1 parent f6cc671 commit 09f1252

File tree

4 files changed

+44
-28
lines changed

4 files changed

+44
-28
lines changed

core/lib/canary/index/trieve/client.ex

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

core/lib/canary/interface/ask.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ defmodule Canary.Interface.Ask.Default do
1515

1616
def run(project, query, handle_delta, opts) do
1717
client = Trieve.client(project)
18+
opts = opts |> Keyword.put(:rag, true)
1819

1920
{:ok, groups} = client |> Trieve.search(query, opts)
2021

core/lib/canary/interface/controller.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ defmodule CanaryWeb.Interface.Controller do
4242
def search(conn, %{"query" => %{"text" => query, "tags" => tags}} = params) do
4343
try do
4444
matches =
45-
Canary.Interface.Search.run!(conn.assigns.project, query, tags: tags, cache: cache?())
45+
conn.assigns.project
46+
|> Canary.Interface.Search.run!(query, tags: tags, cache: cache?())
4647

4748
data = %{
4849
matches: matches,

core/lib/canary/interface/search.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ defmodule Canary.Interface.Search do
77
end
88

99
def run(_, _, opts \\ [])
10-
def run(nil, _, _), do: {:ok, []}
1110
def run(_, "", _), do: {:ok, []}
1211

1312
def run(project, query, opts) do

0 commit comments

Comments
 (0)