PHP code example of synapcores / sdk

1. Go to this page and download the library: Download synapcores/sdk 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/ */

    

synapcores / sdk example snippets



SynapCores\SDK\Client;

// Option A — API key (recommended for service-to-service)
$sc = new Client([
    'host'   => 'localhost',
    'port'   => 28080,
    'apiKey' => 'aidb_…',
]);

// Option B — username/password login flow
$sc = new Client(['host' => 'localhost', 'port' => 28080,
                  'username' => 'admin', 'password' => '…']);
$sc->login();

// Run SQL — returns a typed QueryResult (iterable, countable)
$result = $sc->sql('SELECT name FROM customers WHERE id = :id', ['id' => 42]);
foreach ($result as $row) {
    echo $row['name'], PHP_EOL;
}
echo $result->scalar();              // first column of first row

$hits = $sc->ragSearch('how do I reset my password?', [
    'table'  => 'docs_chunks',
    'vecCol' => 'embedding',
    'k'      => 5,
]);
foreach ($hits as $hit) {
    printf("[%.2f] %s\n", $hit['_score'], $hit['title']);
}

$out = $sc->agentRun(
    persona: 'technical_advisor',
    task:    'Summarize the support tickets opened today.'
);
echo $out->answer;

$recipe = $sc->importRecipe('https://synapcores.com/recipes/churn-prediction.md');
$result = $sc->execRecipe($recipe->recipeId, ['cohort' => 'enterprise']);
echo "Recipe done in {$result->tookMs} ms — {$result->succeededSteps}/{$result->totalSteps} steps OK\n";

$vec = $sc->embed('hello world');
echo count($vec); // 384 (MiniLM) or 768 (your configured model)

// SAFE — single quotes inside the value get doubled correctly
$sc->sql('SELECT * FROM users WHERE name = :n', ['n' => "O'Brien"]);

// SAFE — vector value becomes [0.1,0.2,0.3]
$sc->sql('INSERT INTO docs (id, embedding) VALUES (:id, :v)',
         ['id' => 1, 'v' => [0.1, 0.2, 0.3]]);