Skip to content

Commit

Permalink
Troubleshoot vector indexing
Browse files Browse the repository at this point in the history
Need to figure out what's going on while e2e testing
  • Loading branch information
michaeljguarino committed Mar 3, 2025
1 parent 3b0aa68 commit ff4f485
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/console/ai/pubsub/vector/consumer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Console.AI.PubSub.Vector.Consumer do
end
end

defp insert({:ok, [_ | _] = resources}), do: Enum.each(resources, &VectorStore.insert/1)
defp insert({:ok, resources}) when is_list(resources), do: Enum.each(resources, &VectorStore.insert/1)
defp insert({:ok, res}), do: VectorStore.insert(res)
defp insert(pass), do: pass
end
6 changes: 4 additions & 2 deletions lib/console/ai/pubsub/vector/protocol.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ defimpl Console.AI.PubSub.Vectorizable, for: Console.PubSub.ScmWebhook do
alias Console.AI.Tool
alias Console.Deployments.Pr.Dispatcher
alias Console.Schema.{ScmWebhook, ScmConnection}
require Logger

def resource(%@for{
item: %{"action" => "pull_request", "pull_request" => %{"merged" => true} = pr},
item: %{"action" => "closed", "pull_request" => %{"merged" => true} = pr},
actor: %ScmWebhook{type: :github}
}) do
with %ScmConnection{} = conn <- Tool.scm_connection(),
do: Dispatcher.files(conn, pr)
do: Dispatcher.files(conn, pr) |> IO.inspect(label: "files response:")
end

def resource(_), do: :ok
end

Expand Down
3 changes: 2 additions & 1 deletion lib/console/ai/vector/elastic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ defmodule Console.AI.Vector.Elastic do

def insert(%__MODULE__{conn: %Elastic{} = es}, data) do
with {datatype, text} <- Content.content(data),
{:ok, embeddings} <- Provider.embeddings(text) do
{:ok, embeddings} <- Provider.embeddings(text) |> IO.inspect(label: "embeddings response") do
url(es, "#{es.index}/_doc")
|> HTTPoison.post(Jason.encode!(%{
passages: Enum.map(embeddings, fn {passage, vector} -> %{vector: vector, text: passage} end),
datatype: datatype,
"#{datatype}": Console.mapify(data)
}), headers(es))
|> IO.inspect(label: "es response:")
|> handle_response("could not insert vector into elasticsearch:")
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/console/deployments/pr/impl/github.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ defmodule Console.Deployments.Pr.Impl.Github do
end

defp get_content(client, url) when is_binary(url) do
case HTTPoison.get(url, [{"authorization", "Token #{client.auth.access_token}"}]) do
case HTTPoison.get(url, [{"authorization", "Token #{client.auth.access_token}"}], follow_redirect: true) do
{:ok, %HTTPoison.Response{status_code: code, body: content}}
when code >= 200 and code < 300 -> content
_ -> nil
Expand Down
4 changes: 2 additions & 2 deletions test/console/ai/pubsub/vector/consumer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ defmodule Console.AI.PubSub.Vector.ConsumerTest do
"patch" => "example diff",
}], %HTTPoison.Response{status_code: 200}}
end)
expect(HTTPoison, :get, fn "https://test.url", _ -> {:ok, %HTTPoison.Response{status_code: 200, body: "terraform"}} end)
expect(HTTPoison, :get, fn "https://test.url", _, [follow_redirect: true] -> {:ok, %HTTPoison.Response{status_code: 200, body: "terraform"}} end)

event = %PubSub.ScmWebhook{
item: %{
"action" => "pull_request",
"action" => "closed",
"pull_request" => %{"merged" => true, "html_url" => "https://github.com/owner/repo/pull/1"},
},
actor: hook
Expand Down

0 comments on commit ff4f485

Please sign in to comment.