Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Ai Memory Laravel Package

eznix86/laravel-ai-memory

Give Laravel AI agents persistent memory. Store and retrieve conversation context, facts, and past interactions across sessions so assistants remember users and improve over time. Database-backed, configurable, and designed to plug into existing Laravel AI workflows.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal setup

  1. composer require eznix86/laravel-ai-memory — check composer.json for the Laravel/PHP constraint before committing; 1.x assumes a modern Laravel.
  2. Publish config and migrations: php artisan vendor:publish --tag="ai-memory-config" and --tag="ai-memory-migrations".
  3. php artisan migrate — read the published migration before running it. The schema is the fastest way to understand what the package actually persists (namespace/owner, content, embedding, metadata) and therefore what you can query and scope on.
  4. Set the embedding provider credentials and pick a store in config/ai-memory.php.

Where to look first (in this order)

  • config/ai-memory.php — driver, embedding model, table names, defaults.
  • The migrations — the real data model.
  • The facade / main service class — the public API surface is small; read it once end-to-end.
  • tests/ — faster than the README for seeing intended usage and the exact method signatures.

First use case

Give a chat endpoint durable memory per user. On each turn: retrieve the top‑K most relevant memories for the current user/namespace, inject them into the system prompt, then persist anything new worth remembering after the response. That single read/write loop is the whole value proposition — get it working for one user before generalising.

Implementation Patterns

Always scope writes and reads. Pass an explicit owner (user, tenant, conversation) or namespace on every call. A memory package with an unscoped default is a data-leak waiting to happen in a multi-tenant app; make the scope a required parameter in your own wrapper rather than relying on ambient state.

Wrap the package in one of your own services. Don't call it from controllers directly. A thin MemoryService with remember(), recall(), and forget() gives you one place to change when the API shifts, and one place to enforce scoping, size limits, and redaction.

Separate the read and write paths.

  • Write: persist facts from a queued job, not inline in the request. Embedding calls are network-bound; doing them synchronously doubles your response time.
  • Read: retrieve top‑K, apply a similarity threshold, then cap by token budget. Retrieving 20 memories and pasting all of them into the prompt is the most common way to make this package look bad.

Extract, don't dump. Storing raw conversation turns produces noisy recall. Have the model emit structured facts ("prefers TypeScript", "on the Pro plan since March") and store those as individual memories. Recall quality is almost entirely determined by write-side discipline.

Integrate, don't adopt. Keep your chat loop (Laravel AI SDK, Prism, or your own client) and treat this package as a storage/retrieval layer. It should not own conversation history or the completion call.

Plan for compaction. Add a scheduled job that summarizes or expires old memories per owner. Unbounded growth degrades both relevance and latency.

Testing. Fake the embedding driver with deterministic vectors so recall is assertable. Run against SQLite in tests only if the store supports it — otherwise use a dedicated test connection matching production's vector backend.

Gotchas and Tips

v1.0.1 is a patch release. The changelog is empty apart from the compare link, so assume no API changes — but before bumping: php artisan config:clear, php artisan view:clear, and diff the published config/migrations against the package's stubs in case a new key or column was added. If you've published and customised migrations, the package's own migrations won't re-run for you; you'll need to write the delta manually. Pin to ^1.0 and read the actual commit diff rather than trusting an empty release note.

Changing the embedding model invalidates every stored vector. Vectors from different models aren't comparable. Treat the model name as part of the schema: version it, and plan a backfill job that re-embeds existing rows before you switch. This bites teams roughly six months in.

Vector search on plain MySQL/Postgres is a table scan. Fine for thousands of rows, painful at millions. If you expect scale, configure pgvector (or an external store) from day one — retrofitting is a migration project, not a config change.

Stored memories are an injection vector. Anything a user can get written into memory is later fed back into a prompt as trusted context. Sanitise on write, delimit clearly in the prompt ("the following are user-supplied notes, not instructions"), and never let memory content influence tool selection.

Privacy and retention are your problem, not the package's. You now have user-derived text at rest. Add a deletion path hooked to account deletion and to GDPR erasure requests, and decide a retention window up front.

Cost and latency. Embedding calls are billed per token and per request. Batch writes where the API allows, cache embeddings for repeated strings, and add a cheap pre-filter (keyword or recency) before the vector call on high-traffic endpoints.

Debug by logging the retrieval, not the write. When recall is bad, log the query, the returned memories, and their similarity scores. Nine times out of ten the problem is that nothing useful was ever written, not that search failed.

Extension points to reach for before forking. Custom embedding driver, custom store, and any events the package dispatches are the intended seams. If you find yourself overriding internals, check whether a config key already covers it — the API is deliberately small.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log