From 353cd2572b5b376888597538478114b0821ff322 Mon Sep 17 00:00:00 2001 From: Karol Wilk Date: Wed, 5 Jun 2024 15:22:40 +0200 Subject: [PATCH] Move the embedding process outside of transaction to preven timeout errors in postgres --- lib/search/embeddings/bumblebee_provider.ex | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/search/embeddings/bumblebee_provider.ex b/lib/search/embeddings/bumblebee_provider.ex index fc5972f..1f5ff2b 100644 --- a/lib/search/embeddings/bumblebee_provider.ex +++ b/lib/search/embeddings/bumblebee_provider.ex @@ -59,19 +59,19 @@ defmodule Search.Embeddings.BumblebeeProvider do now = DateTime.utc_now(:second) - Repo.transaction(fn -> - embeddings_params = - [fragments, embeddings] - |> Stream.zip() - |> Enum.map(fn {fragment, embedding} -> - %{ - embedding: embedding, - doc_fragment_id: fragment.id, - inserted_at: now, - updated_at: now - } - end) + embeddings_params = + [fragments, embeddings] + |> Stream.zip() + |> Enum.map(fn {fragment, embedding} -> + %{ + embedding: embedding, + doc_fragment_id: fragment.id, + inserted_at: now, + updated_at: now + } + end) + Repo.transaction(fn -> {inserted, embeddings} = Repo.insert_all( {table_name, Embeddings.Embedding},