<?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('keyword_embeddings', function (Blueprint $table) {
            $table->id();
            $table->text('keyword')->unique()->index();
            $table->vector('embedding', 384);
            $table->string('tag')->nullable();
            $table->timestamps();

            // Add indexes for performance
            $table->index(['keyword']);
            $table->index(['tag']);
        });

        // Add HNSW index for fast vector similarity search
        DB::statement('CREATE INDEX keyword_embeddings_embedding_hnsw_idx ON keyword_embeddings USING hnsw (embedding vector_cosine_ops)');
    }

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