Ash FrameworkAF
Ash Framework7mo ago
16 replies
hyperion_zw

"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(),
  []
) 


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

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


Is there some step is missing? ❓
Solution
And then delete the migrations and snapshots you just generated
Was this page helpful?