PHPackages                             smart-memory/laravel-smart-thread-memory - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. smart-memory/laravel-smart-thread-memory

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

smart-memory/laravel-smart-thread-memory
========================================

Persistent semantic thread memory and related context retrieval for Laravel AI applications.

v0.1.1(1mo ago)10[1 issues](https://github.com/bajiroots/laravel-smart-thread-memory/issues)MITPHPPHP ^8.2CI passing

Since Jun 3Pushed 1mo agoCompare

[ Source](https://github.com/bajiroots/laravel-smart-thread-memory)[ Packagist](https://packagist.org/packages/smart-memory/laravel-smart-thread-memory)[ RSS](/packages/smart-memory-laravel-smart-thread-memory/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Laravel Smart Thread Memory
===========================

[](#laravel-smart-thread-memory)

Give your Laravel AI app a memory that survives the next chat window.

[Baca dalam Bahasa Indonesia](README.id.md)

Laravel Smart Thread Memory is a package for storing conversation memory, finding related threads, and pulling useful context back into your prompts. It is built for AI products where users jump between chats, projects, tickets, tasks, and decisions, but still expect the assistant to remember what came before.

It does not blindly merge conversations. It suggests related threads, shows confidence, and lets your app decide what happens next.

Why This Exists
---------------

[](#why-this-exists)

Most AI chat apps treat every new conversation like a fresh start.

That works until a user says:

> "Let's continue the Stripe invoice sync thing from last week."

The app may have the answer somewhere, but the assistant does not know where to look. Laravel Smart Thread Memory gives your app a semantic memory layer so old decisions, facts, todos, and technical notes can be found again when they matter.

Why Laravel
-----------

[](#why-laravel)

Laravel teams are already building AI copilots, support agents, internal tools, CRM assistants, coding assistants, and workflow automation. The missing piece is often not the chat box. It is memory that fits normal Laravel applications:

- Eloquent models instead of a separate service.
- migrations your app owns.
- queues for expensive embedding work.
- config that can be published and reviewed.
- provider contracts for teams that need OpenAI today and local embeddings later.

This package aims to be that memory layer: boring enough for Laravel apps, semantic enough for AI products.

What It Does
------------

[](#what-it-does)

- Stores persistent AI memory in your Laravel database.
- Turns conversations into reusable memory records.
- Searches memory semantically with embeddings.
- Detects whether a new message is related to older threads.
- Returns confidence scores for related thread suggestions.
- Retrieves relevant context for prompt injection.
- Supports PostgreSQL + pgvector as the main vector store.
- Keeps embedding providers swappable through a clean interface.

What It Does Not Do
-------------------

[](#what-it-does-not-do)

- It does not ship a chat UI.
- It does not auto-merge threads behind your back.
- It does not pretend keyword search is the same as semantic memory.
- It does not lock you into one embedding provider forever.

Current Status
--------------

[](#current-status)

Early MVP. The foundation is in place:

- Laravel package skeleton
- publishable config and migrations
- Eloquent models
- OpenAI embedding provider
- embedding provider contract
- pgvector search driver
- database fallback search
- thread detection
- context retrieval
- suggested merge service
- test baseline

The shape is here. The edges are still being sharpened.

Installation
------------

[](#installation)

```
composer require smart-memory/laravel-smart-thread-memory

php artisan vendor:publish --tag=ai-memory-config
php artisan vendor:publish --tag=ai-memory-migrations
php artisan migrate
```

Quick Start
-----------

[](#quick-start)

Record a thread, store a message, and save a decision as memory:

```
use LaravelAiMemory\Facades\AiMemory;

$thread = AiMemory::createThread([
    'owner_type' => 'user',
    'owner_id' => $user->id,
    'title' => 'Stripe invoice sync',
]);

$message = AiMemory::recordMessage($thread, [
    'role' => 'user',
    'content' => 'We decided to use Stripe webhooks for invoice sync.',
]);

AiMemory::remember([
    'thread_id' => $thread->id,
    'message_id' => $message->id,
    'owner_type' => 'user',
    'owner_id' => $user->id,
    'type' => 'decision',
    'content' => 'Invoice sync should be triggered by Stripe webhooks.',
    'importance' => 5,
]);
```

Later, when the user starts a new chat:

```
$related = AiMemory::detectRelatedThreads(
    content: 'Can we continue invoice sync retries?',
    owner: ['owner_type' => 'user', 'owner_id' => $user->id],
);
```

Before sending a prompt to your AI provider:

```
$context = AiMemory::retrieveContext(
    query: 'What did we decide about invoice sync?',
    owner: ['owner_type' => 'user', 'owner_id' => $user->id],
);

$prompt = user(),
);
```

Your app can then decide whether to:

- show "continue previous thread?"
- attach related context quietly
- start a clean thread
- let the user choose between multiple matches

The package gives you candidates and confidence. Product behavior stays yours.

PostgreSQL + pgvector
---------------------

[](#postgresql--pgvector)

PostgreSQL with pgvector is the primary target for semantic search.

Enable pgvector before running the migrations:

```
CREATE EXTENSION IF NOT EXISTS vector;
```

Then configure:

```
AI_MEMORY_VECTOR_DRIVER=pgvector
AI_MEMORY_EMBEDDING_DIMENSIONS=1536
```

For local development or unsupported databases:

```
AI_MEMORY_VECTOR_DRIVER=database
```

The fallback driver is useful for development and tests. It is not meant to compete with real vector search.

Embeddings
----------

[](#embeddings)

OpenAI is the default provider, but the package uses a provider contract so you can swap it later:

```
use LaravelAiMemory\Contracts\EmbeddingProvider;

$this->app->singleton(EmbeddingProvider::class, LocalEmbeddingProvider::class);
```

Default OpenAI config:

```
OPENAI_API_KEY=
AI_MEMORY_EMBEDDING_PROVIDER=openai
AI_MEMORY_OPENAI_EMBEDDING_MODEL=text-embedding-3-small
```

Testing
-------

[](#testing)

```
composer test
composer format
```

Roadmap
-------

[](#roadmap)

Near-term:

- stronger pgvector integration tests
- better ranking for retrieval
- batch embedding pipeline
- LLM-assisted memory extraction
- thread summarization
- richer docs and examples

Later:

- more embedding providers
- hybrid search
- review/approval workflow for extracted memory
- demo Laravel app

Documentation
-------------

[](#documentation)

Start with:

- [Installation](docs/installation.md)
- [Configuration](docs/configuration.md)
- [Usage](docs/usage.md)
- [Examples](docs/examples.md)
- [Embeddings](docs/embeddings.md)
- [Thread Detection](docs/thread-detection.md)
- [Issue Backlog](docs/issue-backlog.md)
- [Release Checklist](docs/release-checklist.md)
- [Contributing](docs/contributing.md)

Name
----

[](#name)

The package name is **Laravel Smart Thread Memory**. The idea behind it is simple: memory that helps an AI app notice when a new conversation belongs near an old one.

The name can still change. The problem is real either way.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance70

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

51d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c275e66ddfaa925d8c3c2da1f912deea50c06149f0a78744214ff47a4c847195?d=identicon)[bajiroots](/maintainers/bajiroots)

---

Top Contributors

[![bajiroots](https://avatars.githubusercontent.com/u/79397697?v=4)](https://github.com/bajiroots "bajiroots (3 commits)")

---

Tags

aiconversation-memoryembeddingslaravelmemoryopenaipgvectorsemantic-searchlaravelaimemoryopenaiembeddingspgvectorthreadingsemantic-searchconversation-memory

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/smart-memory-laravel-smart-thread-memory/health.svg)

```
[![Health](https://phpackages.com/badges/smart-memory-laravel-smart-thread-memory/health.svg)](https://phpackages.com/packages/smart-memory-laravel-smart-thread-memory)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M246](/packages/laravel-ai)[api-platform/laravel

API Platform support for Laravel

58174.6k17](/packages/api-platform-laravel)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
