"ERROR 42704 (undefined_object) type "vector" does not exist" during migration.

Hello, has someone tried the vectorization on a resource? I encounter a migration error problem. Current setup for vectorization of Post resource: 1. First, created setup_vectorization.ex in folder lib
# do not put it in module
Postgrex.Types.define(
Masque.PostgrexTypes,
[AshPostgres.Extensions.Vector] ++ Ecto.Adapters.Postgres.extensions(),
[]
)
# do not put it in module
Postgrex.Types.define(
Masque.PostgrexTypes,
[AshPostgres.Extensions.Vector] ++ Ecto.Adapters.Postgres.extensions(),
[]
)
2. modify Post resource to add clause vectorize, ref: vectorization
vectorize do
full_text do
text fn post ->
"""
Title: #{post.title}
Content: #{post.content}
"""
end

used_attributes [:title, :content]
end

strategy :ash_oban
ash_oban_trigger_name :post_vectorize_trigger
attributes title: :vectorized_title, content: :vectorized_content

embedding_model Masque.AiAgentEmbeddingModel
end
vectorize do
full_text do
text fn post ->
"""
Title: #{post.title}
Content: #{post.content}
"""
end

used_attributes [:title, :content]
end

strategy :ash_oban
ash_oban_trigger_name :post_vectorize_trigger
attributes title: :vectorized_title, content: :vectorized_content

embedding_model Masque.AiAgentEmbeddingModel
end
The document doesn't say about mix ash.codegen xxx, but it is needed. Then I run mix ash.migrate, it shows error: ERROR 42704 (undefined_object) type "vector" does not exist. The generated migration file is:
defmodule Masque.Repo.Migrations.CreateVectorizationForPost do
@moduledoc """
Updates resources based on their most recent snapshots.

This file was autogenerated with `mix ash_postgres.generate_migrations`
"""

use Ecto.Migration

def up do
alter table(:posts) do
add :is_public, :boolean, null: false, default: false
add :vectorized_title, :vector, size: 3072
add :vectorized_content, :vector, size: 3072
add :full_text_vector, :vector, size: 3072
end
end

def down do
alter table(:posts) do
remove :full_text_vector
remove :vectorized_content
remove :vectorized_title
remove :is_public
end
end
end
defmodule Masque.Repo.Migrations.CreateVectorizationForPost do
@moduledoc """
Updates resources based on their most recent snapshots.

This file was autogenerated with `mix ash_postgres.generate_migrations`
"""

use Ecto.Migration

def up do
alter table(:posts) do
add :is_public, :boolean, null: false, default: false
add :vectorized_title, :vector, size: 3072
add :vectorized_content, :vector, size: 3072
add :full_text_vector, :vector, size: 3072
end
end

def down do
alter table(:posts) do
remove :full_text_vector
remove :vectorized_content
remove :vectorized_title
remove :is_public
end
end
end
Is there some step is missing? ❓
Solution:
And then delete the migrations and snapshots you just generated
Jump to solution
10 Replies
ZachDaniel
ZachDaniel4mo ago
What does your repo module look like?
hyperion_zw
hyperion_zwOP4mo ago
My repo module is:
defmodule Masque.Repo do
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"]
end

# Don't open unnecessary transactions
# will default to `false` in 4.0
@impl true
def prefer_transaction? do
false
end

@impl true
def min_pg_version do
%Version{major: 16, minor: 0, patch: 0}
end
end
defmodule Masque.Repo do
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"]
end

# Don't open unnecessary transactions
# will default to `false` in 4.0
@impl true
def prefer_transaction? do
false
end

@impl true
def min_pg_version do
%Version{major: 16, minor: 0, patch: 0}
end
end
ZachDaniel
ZachDaniel4mo ago
Add vector to the list of extensions
Solution
ZachDaniel
ZachDaniel4mo ago
And then delete the migrations and snapshots you just generated
ZachDaniel
ZachDaniel4mo ago
GitHub
ash_ai/test/support/test_repo.ex at main · ash-project/ash_ai
Structured outputs, vectorization and tool calling for your Ash application - ash-project/ash_ai
ZachDaniel
ZachDaniel4mo ago
Like that
hyperion_zw
hyperion_zwOP4mo ago
The problem still exist:
zw@wei:~/code/elixir_programming/masque_in_ash$ mix ash.setup
Getting extensions in current project...
Running setup for AshPostgres.DataLayer...
The database for Masque.Repo has already been created

11:06:25.039 [info] Migrations already up


zw@wei:~/code/elixir_programming/masque_in_ash$ mix ash.codegen add_vector_for_post
Getting extensions in current project...
Running codegen for AshPostgres.DataLayer...

11:07:06.644 [debug] QUERY OK db=2.9ms queue=33.2ms idle=0.0ms
begin []
Ecto.Migrator.with_repo/3, at: lib/ecto/migrator.ex:170

11:07:06.687 [info] == Running 20250621053231 Masque.Repo.Migrations.MigrateResources1.down/0 forward

11:07:06.687 [info] alter table posts

11:07:06.768 [info] == Migrated 20250621053231 in 0.0s

11:07:06.786 [debug] QUERY OK db=1.5ms
commit []
Ecto.Migrator.with_repo/3, at: lib/ecto/migrator.ex:170
* creating priv/resource_snapshots/repo/extensions.json
* creating priv/repo/migrations/20250626030706_add_vector_for_post_extensions_1.exs
* creating priv/repo/migrations/20250626030708_add_vector_for_post.exs
* creating priv/resource_snapshots/repo/posts/20250626030708.json
zw@wei:~/code/elixir_programming/masque_in_ash$ mix ash.migrate
Getting extensions in current project...
Running migration for AshPostgres.DataLayer...

11:07:27.813 [info] == Running 20250626030706 Masque.Repo.Migrations.AddVectorForPostExtensions1.up/0 forward

11:07:27.816 [info] execute "CREATE EXTENSION IF NOT EXISTS \"vector\""
** (Postgrex.Error) ERROR 0A000 (feature_not_supported) extension "vector" is not available

hint: The extension must first be installed on the system where PostgreSQL is running.

Could not open extension control file "/usr/share/postgresql/16/extension/vector.control": No such file or directory.
(ecto_sql 3.13.1) lib/ecto/adapters/sql.ex:1098: Ecto.Adapters.SQL.raise_sql_call_error/1
zw@wei:~/code/elixir_programming/masque_in_ash$ mix ash.setup
Getting extensions in current project...
Running setup for AshPostgres.DataLayer...
The database for Masque.Repo has already been created

11:06:25.039 [info] Migrations already up


zw@wei:~/code/elixir_programming/masque_in_ash$ mix ash.codegen add_vector_for_post
Getting extensions in current project...
Running codegen for AshPostgres.DataLayer...

11:07:06.644 [debug] QUERY OK db=2.9ms queue=33.2ms idle=0.0ms
begin []
Ecto.Migrator.with_repo/3, at: lib/ecto/migrator.ex:170

11:07:06.687 [info] == Running 20250621053231 Masque.Repo.Migrations.MigrateResources1.down/0 forward

11:07:06.687 [info] alter table posts

11:07:06.768 [info] == Migrated 20250621053231 in 0.0s

11:07:06.786 [debug] QUERY OK db=1.5ms
commit []
Ecto.Migrator.with_repo/3, at: lib/ecto/migrator.ex:170
* creating priv/resource_snapshots/repo/extensions.json
* creating priv/repo/migrations/20250626030706_add_vector_for_post_extensions_1.exs
* creating priv/repo/migrations/20250626030708_add_vector_for_post.exs
* creating priv/resource_snapshots/repo/posts/20250626030708.json
zw@wei:~/code/elixir_programming/masque_in_ash$ mix ash.migrate
Getting extensions in current project...
Running migration for AshPostgres.DataLayer...

11:07:27.813 [info] == Running 20250626030706 Masque.Repo.Migrations.AddVectorForPostExtensions1.up/0 forward

11:07:27.816 [info] execute "CREATE EXTENSION IF NOT EXISTS \"vector\""
** (Postgrex.Error) ERROR 0A000 (feature_not_supported) extension "vector" is not available

hint: The extension must first be installed on the system where PostgreSQL is running.

Could not open extension control file "/usr/share/postgresql/16/extension/vector.control": No such file or directory.
(ecto_sql 3.13.1) lib/ecto/adapters/sql.ex:1098: Ecto.Adapters.SQL.raise_sql_call_error/1
my current postgres is defined as:
services:
postgres:
image: postgres:16
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: postgres:16
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
I may find the solution, it seems it is now related how to setup the environment. I will update it
ZachDaniel
ZachDaniel4mo ago
You can use the pgvector image https://hub.docker.com/r/pgvector/pgvector
hyperion_zw
hyperion_zwOP4mo ago
Thanks a lot, Zach 🙂 . I am newboo to the LLM domain, I though pgvector is just some parameter setting on existing postgres db. Thanks a lot for your patience.

Did you find this page helpful?