<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('meme_media_embeddings', function (Blueprint $table) {
            $table->id();
            $table->foreignId('meme_media_id')->references('id')->on('meme_medias');
            $table->text('keyword')->index();
            $table->vector('embedding', 384);
            $table->string('tag')->nullable();
            $table->timestamps();

            $table->index('tag');
        });

        DB::statement('CREATE INDEX meme_media_embeddings_embedding_hnsw_idx ON meme_media_embeddings USING hnsw (embedding vector_cosine_ops)');
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('meme_media_embeddings');
    }
};
