type `vector` can not be handled by the types module Postgrex.DefaultTypes

It seems when I try to save embeddings into db, it shows this error. Here are my settings: 1. lib/postgrex_types.ex
Postgrex.Types.define(
Masque.PostgrexTypes,
[AshPostgres.Extensions.Vector] ++ Ecto.Adapters.Postgres.extensions(),
[]
)
Postgrex.Types.define(
Masque.PostgrexTypes,
[AshPostgres.Extensions.Vector] ++ Ecto.Adapters.Postgres.extensions(),
[]
)
2. lib/masque/repo.ex
use AshPostgres.Repo,
types: Masque.PostgrexTypes,
otp_app: :masque

@impl true
def installed_extensions do
# Add extensions here, and the migration generator will install them.
["ash-functions", "uuid-ossp", "citext", "pg_trgm", "vector"]
end
use AshPostgres.Repo,
types: Masque.PostgrexTypes,
otp_app: :masque

@impl true
def installed_extensions do
# Add extensions here, and the migration generator will install them.
["ash-functions", "uuid-ossp", "citext", "pg_trgm", "vector"]
end
3. deps in mix.ex
{:pgvector, "~> 0.3.0"}
{:pgvector, "~> 0.3.0"}
4. docker-compose setup for pgvector
services:
postgres:
image: pgvector/pgvector:pg16
restart: always
container_name: postgres
environment:
- POSTGRES_DB=masque
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- "5432:5432"
volumes:
- masque_postgres_data:/var/lib/postgresql/data
services:
postgres:
image: pgvector/pgvector:pg16
restart: always
container_name: postgres
environment:
- POSTGRES_DB=masque
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- "5432:5432"
volumes:
- masque_postgres_data:/var/lib/postgresql/data
Is there anyone else has encoutered this problem?
Solution:
just the relevant parts for now
Jump to solution
12 Replies
hyperion_zw
hyperion_zwOP•4mo ago
I also execute CREATE EXTENSION IF NOT EXISTS vector; and the result shows: Query executed OK, 0 rows affected. . So, I think the extension is installed. Full error message:
[error] Error occurred for Masque.Documents.Post: %{"id" => "924f89b3-ece1-4b5b-8283-69513fbc8e77"}!

Error occurred on action: ash_ai_update_embeddings.

"** (Ash.Error.Unknown) \nBread Crumbs:\n > Error returned from: Masque.Documents.Post.ash_ai_update_embeddings\n\nUnknown Error\n\n* ** (Postgrex.QueryError) type `vector` can not be handled by the types module Postgrex.DefaultTypes\n (ecto_sql 3.13.1) lib/ecto/adapters/sql.ex:1098: Ecto.Adapters.SQL.raise_sql_call_error/1\n (ecto_sql 3.13.1) lib/ecto/adapters/sql.ex:996: Ecto.Adapters.SQL.execute/6\n (ecto 3.13.1) lib/ecto/repo/queryable.ex:241: Ecto.Repo.Queryable.execute/4\n (ash_postgres 2.6.8) lib/data_layer.ex:1534: AshPostgres.DataLayer.update_query/4\n ....
[error] Error occurred for Masque.Documents.Post: %{"id" => "924f89b3-ece1-4b5b-8283-69513fbc8e77"}!

Error occurred on action: ash_ai_update_embeddings.

"** (Ash.Error.Unknown) \nBread Crumbs:\n > Error returned from: Masque.Documents.Post.ash_ai_update_embeddings\n\nUnknown Error\n\n* ** (Postgrex.QueryError) type `vector` can not be handled by the types module Postgrex.DefaultTypes\n (ecto_sql 3.13.1) lib/ecto/adapters/sql.ex:1098: Ecto.Adapters.SQL.raise_sql_call_error/1\n (ecto_sql 3.13.1) lib/ecto/adapters/sql.ex:996: Ecto.Adapters.SQL.execute/6\n (ecto 3.13.1) lib/ecto/repo/queryable.ex:241: Ecto.Repo.Queryable.execute/4\n (ash_postgres 2.6.8) lib/data_layer.ex:1534: AshPostgres.DataLayer.update_query/4\n ....
ZachDaniel
ZachDaniel•4mo ago
hyperion_zw
hyperion_zwOP•4mo ago
yes I have cnfigured that. I am currently suspect it is my docker yaml file: previouly I define - masque_postgres_data:/var/lib/postgresql/data when use postgres docker image, I forget to update it. So, after I use pgvector, it still use the same volume. could it be the cause?
I am testing new volume with fresh migration.
ZachDaniel
ZachDaniel•4mo ago
🤔 I wouldn't think so TBH That looks like a code-level issue to me
hyperion_zw
hyperion_zwOP•4mo ago
That doesn't work. It still get: same error, " (Ash.Error.Unknown) \nBread Crumbs:\n > Error returned from: Masque.Documents.Post.ash_ai_update_embeddings\n\nUnknown Error\n\n* (Postgrex.QueryError) type vector can not be handled by the types module Postgrex.DefaultTypes\n
ZachDaniel
ZachDaniel•4mo ago
Can you show me your config?
hyperion_zw
hyperion_zwOP•4mo ago
sure, it is too long. how to post it across the limit...for now I will post multiple parts
Solution
ZachDaniel
ZachDaniel•4mo ago
just the relevant parts for now
ZachDaniel
ZachDaniel•4mo ago
Like where you've configured your types module in your repo ah, this:
use AshPostgres.Repo,
types: Masque.PostgrexTypes,
otp_app: :masque
use AshPostgres.Repo,
types: Masque.PostgrexTypes,
otp_app: :masque
is not correct This goes in your config.exs:
config :masque, Masque.Repo,
types: Masque.PostgrexTypes
config :masque, Masque.Repo,
types: Masque.PostgrexTypes
hyperion_zw
hyperion_zwOP•4mo ago
for relating with config :masque, Masque.Repo, there are 3 places: 1. dev.exs
# Configure your database
config :masque, Masque.Repo,
username: "postgres",
password: "postgres",
hostname: "localhost",
database: "masque_dev",
stacktrace: true,
show_sensitive_data_on_connection_error: true,
pool_size: 10
# Configure your database
config :masque, Masque.Repo,
username: "postgres",
password: "postgres",
hostname: "localhost",
database: "masque_dev",
stacktrace: true,
show_sensitive_data_on_connection_error: true,
pool_size: 10
another is runtime.exs and test. in runtime.exs, it shows:
config :masque, Masque.Repo,
# ssl: true,
url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
# For machines with several cores, consider starting multiple pools of `pool_size`
# pool_count: 4,
socket_options: maybe_ipv6
config :masque, Masque.Repo,
# ssl: true,
url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
# For machines with several cores, consider starting multiple pools of `pool_size`
# pool_count: 4,
socket_options: maybe_ipv6
so, I need to put that in config.exs?
ZachDaniel
ZachDaniel•4mo ago
yes
hyperion_zw
hyperion_zwOP•4mo ago
Ok, I have added following to config.exs
config :masque, Masque.Repo, types: Masque.PostgrexTypes
config :masque, Masque.Repo, types: Masque.PostgrexTypes
I also update the repo.ex to remove types: Masque.PostgrexTypes
defmodule Masque.Repo do
use AshPostgres.Repo,
otp_app: :masque
defmodule Masque.Repo do
use AshPostgres.Repo,
otp_app: :masque
let me retry It works now. Thanks a lot for your detailed support. It is my mistake to mis-config it to set it up repo.ex. Thanks a lot!

Did you find this page helpful?