All skills
asyrafhussin avatar

/laravel-ai-sdk

@7221662

Laravel AI SDK for building AI-powered features. Use when creating agents, generating images or audio, working with embeddings, vector search, or testing AI features. Triggers on tasks involving laravel/ai, AI agents, tool-calling, structured output, streaming, embeddings, reranking, or AI faking in tests.

Use this Skill: https://skilld.dev/gh/asyrafhussin/agent-skills/laravel-ai-sdk

This session only. Nothing lands on disk.

rulesembed-generate-cache.md

≈753 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Generate and Cache Embeddings

Impact: HIGH (Foundation for semantic search and RAG features)

Generate vector embeddings from text, store them in pgvector columns, and cache to avoid redundant API calls.

Bad Example

// Generating embeddings on every request — wasteful and slow
class SearchController extends Controller
{
    public function search(Request $request)
    {
        // Calls embedding API every time, even for identical queries
        $embedding = Http::post('https://api.openai.com/v1/embeddings', [
            'input' => $request->input('query'),
            'model' => 'text-embedding-3-small',
        ])->json('data.0.embedding');

        // Manual similarity calculation
        // ...
    }
}

Good Example

// Generate embeddings with Stringable helper
use Illuminate\Support\Str;

$embeddings = Str::of('Napa Valley has great wine.')->toEmbeddings();
// Batch generation for multiple inputs
use Laravel\Ai\Embeddings;

$response = Embeddings::for([
    'Napa Valley has great wine.',
    'Laravel is a PHP framework.',
])->generate();

$response->embeddings; // [[0.123, 0.456, ...], [0.789, 0.012, ...]]
// Specify dimensions and provider
use Laravel\Ai\Enums\Lab;

$response = Embeddings::for(['Napa Valley has great wine.'])
    ->dimensions(1536)
    ->generate(Lab::OpenAI, 'text-embedding-3-small');
// Cache embeddings to avoid redundant API calls
$response = Embeddings::for(['Napa Valley has great wine.'])
    ->cache()
    ->generate();

// Cache with custom duration
$response = Embeddings::for(['Napa Valley has great wine.'])
    ->cache(seconds: 3600)
    ->generate();

// Cache via Stringable
$embeddings = Str::of('Napa Valley has great wine.')->toEmbeddings(cache: true);
$embeddings = Str::of('Napa Valley has great wine.')->toEmbeddings(cache: 3600);
// Enable global caching in config/ai.php
'caching' => [
    'embeddings' => [
        'cache' => true,
        'store' => env('CACHE_STORE', 'database'),
    ],
],
// Store and query embeddings — see laravel-best-practices/eloquent-vector-search
use App\Models\Document;

Document::create([
    'title' => 'Wine Guide',
    'content' => $content,
    'embedding' => Str::of($content)->toEmbeddings(),
]);

$results = Document::query()
    ->whereVectorSimilarTo('embedding', 'best wineries in Napa Valley')
    ->limit(10)
    ->get();

Why

  • Simple API: Str::of(...)->toEmbeddings() — one line to generate
  • Caching: Avoid paying for identical embedding requests
  • Batch support: Generate multiple embeddings in a single API call
  • Provider-agnostic: OpenAI, Gemini, Azure, Cohere, Mistral, Jina, VoyageAI

Reference: Laravel AI SDK — Embeddings

Source: SKILL.md on GitHub

1 warning16d4 checks · Risk MEDIUM
  • Gen Agent Trust Hub16d

    The skill provides a comprehensive guide for the Laravel AI SDK but contains deceptive metadata claiming authorship by the 'Laravel Community' despite being associated with the user 'asyrafhussin'. It also presents an indirect prompt injection surface by documenting patterns for ingesting untrusted data (such as transcripts and external URLs) while granting agents capabilities like file system storage and network access.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 7221662. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 7 months ago
Other metadata
metadata
{
  "author": "Laravel Community",
  "version": "1.0.0",
  "laravelVersion": "13.x",
  "phpVersion": "8.3+"
}

README badge

README badge for asyrafhussin/agent-skills/laravel-ai-sdk