fr3on / laravel-sage
A drop-in semantic cache for the Laravel AI SDK.
0.0.1
2026-04-10 13:59 UTC
Requires
- php: ^8.3
- illuminate/database: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
- laravel/ai: *
Requires (Dev)
- laravel/pint: ^1.15
- orchestra/testbench: ^9.0|^10.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
README
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.