MnemosynePostgres.Migrations (mnemosyne_postgres v0.1.1)

Copy Markdown View Source

Migrations for the MnemosynePostgres tables and indexes.

Usage

Create a migration in your application:

defmodule MyApp.Repo.Migrations.AddMnemosyne do
  use Ecto.Migration

  def up, do: MnemosynePostgres.Migrations.up(version: 1, embedding_dimensions: 1536)
  def down, do: MnemosynePostgres.Migrations.down(version: 1)
end

When a new version is released, generate a new migration:

defmodule MyApp.Repo.Migrations.UpgradeMnemosyneV2 do
  use Ecto.Migration

  def up, do: MnemosynePostgres.Migrations.up(version: 2, embedding_dimensions: 1536)
  def down, do: MnemosynePostgres.Migrations.down(version: 2)
end

Options

  • :version - the target migration version (defaults to 1)
  • :embedding_dimensions - (required for V1) the dimensionality of your embedding vectors
  • :index_type - :hnsw (default) or :ivfflat
  • :hnsw_m - max number of connections per layer for HNSW
  • :hnsw_ef_construction - size of the dynamic candidate list for HNSW
  • :ivfflat_lists - number of inverted lists for IVFFlat
  • :prefix - table name prefix, defaults to "mnemosyne_"

Summary

Functions

Returns the current migration version.

Runs the down migration for the given version.

Returns the version that has been migrated, based on the table comment. Returns 0 if no migrations have run.

Runs the up migration for the given version.

Functions

current_version()

@spec current_version() :: pos_integer()

Returns the current migration version.

down(opts \\ [])

@spec down(keyword()) :: :ok

Runs the down migration for the given version.

Rolls back from the currently migrated version down to the target version. When called with version: 1, it rolls back V1 (dropping all tables).

migrated_version(repo, prefix \\ "mnemosyne_")

@spec migrated_version(Ecto.Repo.t(), String.t()) :: non_neg_integer()

Returns the version that has been migrated, based on the table comment. Returns 0 if no migrations have run.

up(opts \\ [])

@spec up(keyword()) :: :ok

Runs the up migration for the given version.

Executes all migration versions from the currently migrated version up to the target version sequentially.