pgvector / pgvector-php

pgvector support for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Seeking Advice on Handling Model Changes and Embedding Dimensions

alnutile opened this issue · comments

I've recently transitioned from using the "text-similarity-babbage-001" model to "text-embedding-ada-002" and encountered the following error:

PDOException: SQLSTATE[22000]: Data exception: 7 ERROR: expected 2048 dimensions, not 1536 in /home/forge/larachain.io/releases/20240326200550/vendor/laravel/framework/src/Illuminate/Database/Connection.php:603

Considering I have done 2 other updates before this

First:

        Schema::create('documents', function (Blueprint $table) {
            $table->id();
            ////stuff here
            $table->vector('embedding', 1536)->nullable()l
        });

then:

        Schema::table('messages', function (Blueprint $table) {
            $table->integer('token_count')->nullable();
            $table->vector('embedding', 2048)->nullable();
        });

It seems I am now going back 🤪

Is there a better way I should be using this library to be more flexible with LLM model changes?

Thanks!

Hi @alnutile, the two main ways to handle multiple embedding models are:

  1. Add a new column for each model - embedding vector(2048), ada_embedding vector(1536), etc.
  2. Create a separate message_embeddings (or embeddings) table with message_id (or a polymorphic relationship), model, and embedding vector (example)

Makes sense thanks!