PHP code example of b7s / neuraphp

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

    

b7s / neuraphp example snippets


use B7s\Neuraphp\Neuraphp;
use B7s\Neuraphp\ModelReference;
use B7s\Neuraphp\Enums\Model;

// Embed text (uses default model: AllMiniLML6V2)
$result = Neuraphp::make()->embed('Hello world');
echo $result->dimension();  // 384

// Use a specific model
$result = Neuraphp::make()
    ->model(Model::BgeSmallENV15)
    ->embed('Hello world'); // float[]

// Compare two texts
$similarity = Neuraphp::make()
    ->cosineSimilarity(
       'The cat sat on the mat',
       'A feline rested on the rug'
    ); // 0.87