AF
Ash Framework•4mo ago
teeang

Ash.Vector clashing with Pgvector

Hey, I need help with the following error. Is there a setup step that I'm missing with Ash.Vector?
Unknown Error
* ** (FunctionClauseError) no function clause matching in Pgvector.new/1
(pgvector 0.3.0) lib/pgvector.ex:11: Pgvector.new(Ash.Vector.new([0.003053617663681507, 1.4347572869155556e-4, 0.03219764307141304, -0.030739549547433853, -0.00840899720788002, -0.008372376672923565, 0.015835285186767578, -0.001286978367716074, -0.0236682016402483, 0.025776473805308342,
Unknown Error
* ** (FunctionClauseError) no function clause matching in Pgvector.new/1
(pgvector 0.3.0) lib/pgvector.ex:11: Pgvector.new(Ash.Vector.new([0.003053617663681507, 1.4347572869155556e-4, 0.03219764307141304, -0.030739549547433853, -0.00840899720788002, -0.008372376672923565, 0.015835285186767578, -0.001286978367716074, -0.0236682016402483, 0.025776473805308342,
I've setup the Pgvector types according to their documentation. So I have a lib/postgrex_types.ex file
Postgrex.Types.define(
ResidentialTenancyAct.PostgrexTypes,
Pgvector.extensions() ++ Ecto.Adapters.Postgres.extensions(),
[]
)
Postgrex.Types.define(
ResidentialTenancyAct.PostgrexTypes,
Pgvector.extensions() ++ Ecto.Adapters.Postgres.extensions(),
[]
)
And my database config which extends the default postgrex types
config :residential_tenancy_act, ResidentialTenancyAct.Repo,
types: ResidentialTenancyAct.PostgrexTypes
config :residential_tenancy_act, ResidentialTenancyAct.Repo,
types: ResidentialTenancyAct.PostgrexTypes
Solution:
Ah, I think I found it. Maybe there should be a link to the setup instructions in AshPostgres.Extensions.Vector documentation from the Ash.Vector docs. Ash Vector: https://hexdocs.pm/ash/Ash.Vector.html AshPostgres.Extensions.Vector: https://hexdocs.pm/ash_postgres/AshPostgres.Extensions.Vector.html...
Jump to solution
9 Replies
ZachDaniel
ZachDaniel•4mo ago
Do you have some other pgvector package installed?
teeang
teeangOP•4mo ago
Yeah, I'm using pgvector {:pgvector, "~> 0.3.0"}
ZachDaniel
ZachDaniel•4mo ago
🤔 Might be a problem I think that the pgvector extension might compete with ours.
teeang
teeangOP•4mo ago
Thanks for you help Zach. I've removed the pgvector package and it results in another error when I load records that have vectors. Is there an additional setup step that I'm missing?
[error] Postgrex.Protocol (#PID<0.1217.0>) disconnected: ** (Postgrex.QueryError) type `vector` can not be handled by the types module Postgrex.DefaultTypes
** (Ash.Error.Unknown)
Bread Crumbs:
> Error returned from: ResidentialTenancyAct.Acts.NSWRTASections.read

Unknown Error

* ** (Postgrex.QueryError) type `vector` can not be handled by the types module Postgrex.DefaultTypes
(ecto_sql 3.12.1) lib/ecto/adapters/sql.ex:1096: Ecto.Adapters.SQL.raise_sql_call_error/1
(ecto_sql 3.12.1) lib/ecto/adapters/sql.ex:994: Ecto.Adapters.SQL.execute/6
(ecto 3.12.6) lib/ecto/repo/queryable.ex:232: Ecto.Repo.Queryable.execute/4
(ecto 3.12.6) lib/ecto/repo/queryable.ex:19: Ecto.Repo.Queryable.all/3
(ash_postgres 2.6.7) lib/data_layer.ex:788: anonymous fn/3 in AshPostgres.DataLayer.run_query/2
(ash_postgres 2.6.7) lib/data_layer.ex:787: AshPostgres.DataLayer.run_query/2
(ash 3.5.21) lib/ash/actions/read/read.ex:3824: Ash.Actions.Read.run_query/4
(ash 3.5.21) lib/ash/actions/read/read.ex:635: anonymous fn/8 in Ash.Actions.Read.do_read/5
(ash 3.5.21) lib/ash/actions/read/read.ex:1366: Ash.Actions.Read.maybe_in_transaction/3
(ash 3.5.21) lib/ash/actions/read/read.ex:330: Ash.Actions.Read.do_run/3
[error] Postgrex.Protocol (#PID<0.1217.0>) disconnected: ** (Postgrex.QueryError) type `vector` can not be handled by the types module Postgrex.DefaultTypes
** (Ash.Error.Unknown)
Bread Crumbs:
> Error returned from: ResidentialTenancyAct.Acts.NSWRTASections.read

Unknown Error

* ** (Postgrex.QueryError) type `vector` can not be handled by the types module Postgrex.DefaultTypes
(ecto_sql 3.12.1) lib/ecto/adapters/sql.ex:1096: Ecto.Adapters.SQL.raise_sql_call_error/1
(ecto_sql 3.12.1) lib/ecto/adapters/sql.ex:994: Ecto.Adapters.SQL.execute/6
(ecto 3.12.6) lib/ecto/repo/queryable.ex:232: Ecto.Repo.Queryable.execute/4
(ecto 3.12.6) lib/ecto/repo/queryable.ex:19: Ecto.Repo.Queryable.all/3
(ash_postgres 2.6.7) lib/data_layer.ex:788: anonymous fn/3 in AshPostgres.DataLayer.run_query/2
(ash_postgres 2.6.7) lib/data_layer.ex:787: AshPostgres.DataLayer.run_query/2
(ash 3.5.21) lib/ash/actions/read/read.ex:3824: Ash.Actions.Read.run_query/4
(ash 3.5.21) lib/ash/actions/read/read.ex:635: anonymous fn/8 in Ash.Actions.Read.do_read/5
(ash 3.5.21) lib/ash/actions/read/read.ex:1366: Ash.Actions.Read.maybe_in_transaction/3
(ash 3.5.21) lib/ash/actions/read/read.ex:330: Ash.Actions.Read.do_run/3
Solution
teeang
teeang•4mo ago
Ah, I think I found it. Maybe there should be a link to the setup instructions in AshPostgres.Extensions.Vector documentation from the Ash.Vector docs. Ash Vector: https://hexdocs.pm/ash/Ash.Vector.html AshPostgres.Extensions.Vector: https://hexdocs.pm/ash_postgres/AshPostgres.Extensions.Vector.html
Ketupia (Kevin)
Ketupia (Kevin)•3mo ago
I am thinking about using vectors to prevent duplicate entries of people in our database. Are the queries suffuciently fast for 'real time' feedback - like 300ms debouncing a web form? I'm thinking that vectorizing the user input would be the slowest part.
ZachDaniel
ZachDaniel•3mo ago
You'd need a local model doing the vectorizing likely
Ketupia (Kevin)
Ketupia (Kevin)•3mo ago
A very small local model would probably do well on such a contained task
barnabasj
barnabasj•3mo ago
I used nomic-embed-text with ollama for embeddings recently

Did you find this page helpful?