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/ */
$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->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
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.