Skip to content

Commit eddc998

Browse files
committed
index github issue/discussion body as chunk
1 parent 792bc7f commit eddc998

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

core/lib/canary/sources/document_create.ex

+14-8
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,18 @@ defmodule Canary.Sources.Document.Create do
9595

9696
defp transform_fetcher_result(%GithubIssue.FetcherResult{} = data) do
9797
local_chunks =
98-
data.items
98+
[data.root | data.items]
9999
|> Enum.map(fn _ -> %Chunk{index_id: Ecto.UUID.generate()} end)
100100

101101
remote_chunks =
102-
data.items
103-
|> Enum.map(fn item ->
102+
[data.root | data.items]
103+
|> Enum.with_index(0)
104+
|> Enum.map(fn {item, index} ->
104105
%{
105106
content: item.content,
106107
url: data.root.url,
107-
title: data.root.title <> "\n" <> data.root.content,
108+
title:
109+
if(index == 0, do: item.title, else: data.root.title <> "\n" <> data.root.content),
108110
created_at: item.created_at,
109111
weight: clamp(1, 5, item.num_reactions),
110112
meta: %{}
@@ -136,16 +138,18 @@ defmodule Canary.Sources.Document.Create do
136138

137139
defp transform_fetcher_result(%GithubDiscussion.FetcherResult{} = data) do
138140
local_chunks =
139-
data.items
141+
[data.root | data.items]
140142
|> Enum.map(fn _ -> %Chunk{index_id: Ecto.UUID.generate()} end)
141143

142144
remote_chunks =
143-
data.items
144-
|> Enum.map(fn item ->
145+
[data.root | data.items]
146+
|> Enum.with_index(0)
147+
|> Enum.map(fn {item, index} ->
145148
%{
146149
url: item.url,
147150
content: item.content,
148-
title: data.root.title <> "\n" <> data.root.content,
151+
title:
152+
if(index == 0, do: item.title, else: data.root.title <> "\n" <> data.root.content),
149153
created_at: item.created_at,
150154
weight: clamp(1, 5, item.num_reactions),
151155
meta: %{}
@@ -177,6 +181,8 @@ defmodule Canary.Sources.Document.Create do
177181
end
178182

179183
@impl true
184+
def after_batch([], _opts, _context), do: []
185+
180186
def after_batch(changesets_and_results, opts, _context) do
181187
with :ok = create_groups(changesets_and_results, opts),
182188
:ok = create_chunks(changesets_and_results, opts) do

0 commit comments

Comments
 (0)