Skip to content

Commit

Permalink
tune search & ask
Browse files Browse the repository at this point in the history
  • Loading branch information
yujonglee committed Oct 29, 2024
1 parent cf31223 commit 3c5d973
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
18 changes: 6 additions & 12 deletions core/lib/canary/index/trieve/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule Canary.Index.Trieve.Actual do
if(not is_nil(dataset), do: {"TR-Dataset", dataset}, else: nil)
]
|> Enum.reject(&is_nil/1),
receive_timeout: 2 * 15_000
receive_timeout: 4_000
)
end

Expand Down Expand Up @@ -207,16 +207,11 @@ defmodule Canary.Index.Trieve.Actual do
tags = Keyword.get(opts, :tags, nil)
source_ids = Keyword.get(opts, :source_ids, nil)

search_type = if(rag? or question?(query), do: :hybrid, else: :fulltext)
search_type = if(rag? or question?(query), do: :fulltext, else: :fulltext)
remove_stop_words = not (rag? or question?(query))
group_size = if(rag?, do: 5, else: 3)
page_size = 8

score_threshold =
case search_type do
:fulltext -> 1
_ -> 0.3
end
page_size = if(rag?, do: 12, else: 8)
score_threshold = 0.3

highlight_options =
cond do
Expand Down Expand Up @@ -281,7 +276,7 @@ defmodule Canary.Index.Trieve.Actual do
})
end)
end)
|> Task.await_many(2_500)
|> Task.await_many(5_000)

if Enum.all?(result, &match?({:error, _}, &1)) do
{:error, result}
Expand Down Expand Up @@ -329,7 +324,6 @@ defmodule Canary.Index.Trieve.Actual do
# https://docs.trieve.ai/api-reference/chunk-group/search-over-groups
case client
|> Req.post(
receive_timeout: 2_000,
url: "/chunk_group/group_oriented_search",
json: data
) do
Expand Down Expand Up @@ -370,7 +364,7 @@ defmodule Canary.Index.Trieve.Actual do
end
end)
end)
|> Task.await_many(3_000)
|> Task.await_many(5_000)

if Enum.all?(result, &match?({:error, _}, &1)) do
{:error, result}
Expand Down
2 changes: 1 addition & 1 deletion core/lib/canary/interface/ask.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule Canary.Interface.Ask.Default do

results =
groups
|> Enum.take(6)
|> Enum.take(8)
|> Enum.map(fn %{"chunks" => chunks, "group" => %{"tracking_id" => group_id}} ->
Task.async(fn ->
chunk_indices =
Expand Down
4 changes: 2 additions & 2 deletions core/lib/canary/sources/document_create.ex
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ defmodule Canary.Sources.Document.Create do
title:
if(index == 0, do: item.title, else: data.root.title <> "\n" <> data.root.content),
created_at: item.created_at,
weight: 1 + clamp(0, 3, item.num_reactions / 2) / 10,
weight: 1 + clamp(0, 3, floor(item.num_reactions / 3)) / 10,
meta: %{index: index}
}
end)
Expand Down Expand Up @@ -153,7 +153,7 @@ defmodule Canary.Sources.Document.Create do
title:
if(index == 0, do: item.title, else: data.root.title <> "\n" <> data.root.content),
created_at: item.created_at,
weight: 1 + clamp(0, 3, item.num_reactions / 2) / 10,
weight: 1 + clamp(0, 3, floor(item.num_reactions / 3)) / 10,
meta: %{index: index}
}
end)
Expand Down

0 comments on commit 3c5d973

Please sign in to comment.