Ash FrameworkAF
Ash Framework7mo ago
3 replies
bhelms

Using Pgvector and Ash.Vector

Greetings!
I have a few Ecto schemas using Pgvector.Ecto.Type. I've been attempting to slowly move them over to Ash resources using the Ash.Type.Vector but I've been unable to get both extensions to coexist.
I tried globally defining both: Pgvector.extensions() ++ [AshPostgres.Extensions.Vector] ++ Ecto.Adapters.Postgres.extensions() , but depending on that list order one or the other breaks.
I also tried matching on type to get around it in a custom extension, which works for encoding:
  def encode(_) do
    quote do
      %Pgvector{} = vec ->
        data = vec |> Pgvector.new() |> Pgvector.to_binary()
        [<<IO.iodata_length(data)::int32()>> | data]

      vec when is_struct(vec, Ash.Vector) ->
        data = vec |> Ash.Vector.to_binary()
        [<<IO.iodata_length(data)::int32()>> | data]
etc...

But I've found no way to determine which type to return on decoding:
  def decode(:copy) do
    quote do
      <<len::int32(), bin::binary-size(len)>> ->
        # bin |> :binary.copy() |> Ash.Vector.from_binary()
        # OR ??
        # bin |> :binary.copy() |> Pgvector.from_binary()
    end
  end

I've decided the only thing to do is replace all instances of Pgvector.Ecto.Type with Ash.Type.Vector in one fell swoop, so only the Ash type is in use.
Has anybody run into this? I wanted to ask before I pull the "destroy all" lever on Pgvector.
Was this page helpful?