fr3on/laravel-sage

A drop-in semantic cache for the Laravel AI SDK.

Maintainers

Package info

github.com/fr3on/laravel-sage

pkg:composer/fr3on/laravel-sage

Statistics

Installs: 10

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

0.0.1 2026-04-10 13:59 UTC

This package is auto-updated.

Last update: 2026-04-11 15:28:24 UTC


README

Latest Version on Packagist GitHub Tests Action Status Total Downloads PHP Version Support Laravel Version Support License

A drop-in semantic cache for the Laravel AI SDK — serve cached LLM responses for meaning-similar prompts, not just exact matches.

Sage matched prompts by meaning using vector embeddings. "How do I reset my password?" and "I forgot my login, how to change it?" return the same cached response — instantly, at zero API cost.

Features

  • Semantic Matching: Matches on intent, not just string equality.
  • Zero Infra Latency: Works with your existing Postgres (pgvector) or Redis database.
  • One-Line Integration: Hooks natively into Laravel AI SDK agent middleware.
  • Automatic Token Savings: Significant reduction in LLM API costs.
  • Pulse Integration: Includes a built-in Pulse card to track hit rates and cost savings.

Installation

You can install the package via composer:

composer require fr3on/laravel-sage

You can publish and run the migrations with:

php artisan vendor:publish --tag="sage-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="sage-config"

Usage

Sage hooks into the Laravel AI SDK's native agent middleware system. Add SemanticCache to your agent's middleware stack:

use Fr3on\Sage\Middleware\SemanticCache;

class SupportAgent implements Agent, HasMiddleware
{
    public function middleware(): array
    {
        return [
            new SemanticCache(threshold: 0.92, ttl: 86400),
        ];
    }
}

License

The MIT License (MIT). Please see License File for more information.