AF
Ash Framework•4mo ago
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...
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
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.
2 Replies
ZachDaniel
ZachDaniel•4mo ago
🤔 yeah I think the only other option would be to use a separate repo for your Ash resources potentially
bhelms
bhelmsOP•4mo ago
Cool. I figured. Thanks!

Did you find this page helpful?