PHP code example of particle-academy / prism-memory

1. Go to this page and download the library: Download particle-academy/prism-memory library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

particle-academy / prism-memory example snippets


use Prism\Memory\Facades\PrismMemory;

$memory = PrismMemory::for($user, scope: 'support');

$memory->remember($response->messages);

$relevant = $memory->recall('billing address', budget: 1500);

Prism::text()
    ->using(Provider::Anthropic, 'claude-sonnet-4-5')
    ->withSystemPrompt($instructions)
    ->withSystemPrompt($relevant->asContext())
    ->withPrompt($question)
    ->asText();

$ids = $memory->remember($response->messages);

$relevant = $memory->recall(
    'billing address',
    budget: 1500,                                    // fill a token budget, not a fixed k
    weighting: new Weighting(relevance: 0.7, recency: 0.3),
    filter: ['role' => 'user'],
);

Prism::text()
    ->withSystemPrompt($instructions)                  // stable — mark THIS one
    ->withSystemPrompt($relevant->asContext())         // changes as memory grows
    ->withPrompt($question)                            // changes every turn

$memory->forget($ids);              // specific memories
$memory->forget();                  // this owner, this scope, all of it
$memory->forgetBefore($date);       // everything that HAPPENED before $date

$memory->remember($passage, metadata: (new Provenance(
    id: 'handbook.md',
    uri: 'https://example.test/handbook.md',
    version: 'a1b2c3',
    part: 4,
    heading: 'Billing > Refunds',
))->toMetadata());

$provenance = Provenance::fromMetadata($recalled->metadata);

$store->search(new VectorQuery(['handbook', 'contracts'], $vector, $space));

$memory->recall('where do I live?', filter: ['kind' => 'observation']);   // prose only
$memory->recall('what did the lookup return?', filter: ['tool_name' => 'lookup']);

'remember_tool_results' => false,

// A service provider in your app — both packages installed.
$this->app->singleton(EvictionSink::class, fn () => new MemoryEvictionSink(
    app(PrismMemory::class),
    $owner,
));

$this->app->singleton(ContextRecall::class, fn () => new MemoryContextRecall(
    app(PrismMemory::class),
    $owner,
));

// config/memory.php
'store' => 'pgvector',
'drivers' => [
    'pgvector' => [
        'driver' => 'pgvector',
        'dimensions' => 1536,   // must match the embedding model
    ],
],

app(VectorStoreManager::class)->extend('qdrant', fn ($config, $app) => new QdrantStore(...));
bash
composer migrate
sh
php artisan vendor:publish --tag=memory-pgvector-migrations
php artisan migrate