init project

This commit is contained in:
2026-05-10 13:21:24 +03:30
parent 5f210c6c73
commit dc36701c9d
26 changed files with 2149 additions and 69 deletions

View File

@@ -0,0 +1,54 @@
<?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
{
$driver = Schema::getConnection()->getDriverName();
$dimensions = (int) config('ai.providers.ollama.models.embeddings.dimensions', 768);
if ($driver === 'pgsql') {
Schema::ensureVectorExtensionExists();
}
Schema::create('embedding_entries', function (Blueprint $table) use ($dimensions, $driver) {
$table->id();
$table->text('source_text');
$table->string('content_hash', 64);
$table->string('provider');
$table->string('model');
$table->unsignedSmallInteger('embedding_dimensions')->default($dimensions);
$table->unsignedInteger('tokens')->nullable();
if ($driver === 'pgsql') {
$table->vector('embedding', dimensions: $dimensions);
$table->vectorIndex('embedding');
} else {
$table->json('embedding');
}
$table->timestamps();
$table->unique(
['content_hash', 'provider', 'model', 'embedding_dimensions'],
'embedding_entries_unique_embedding'
);
$table->index(['provider', 'model', 'embedding_dimensions']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('embedding_entries');
}
};

View File

@@ -0,0 +1,39 @@
<?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('embedding_usage_events', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('tool', 32);
$table->string('provider');
$table->string('model');
$table->unsignedSmallInteger('embedding_dimensions');
$table->unsignedInteger('input_count')->default(0);
$table->unsignedInteger('result_count')->default(0);
$table->unsignedInteger('tokens')->nullable();
$table->timestamps();
$table->index(['user_id', 'created_at']);
$table->index(['user_id', 'tool', 'created_at']);
$table->index(['user_id', 'model']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('embedding_usage_events');
}
};