PHP code example of corvid / php-corvid

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

    

corvid / php-corvid example snippets


$db = Corvid\Db::openMemory();
$docs = $db->collection('docs');

$docs->insert('s1', [
    'kind' => 'doc', 'body' => 'rust embedded database',
    'v' => new Corvid\Vector([1.0, 0.0]),
]);

// filter + vector + text, RRF-fused and MMR-reranked,
// in one transactionally consistent call.
$rows = $docs->query()
    ->filter((new Corvid\Field('kind'))->eq('doc'))
    ->vector('v', new Corvid\Vector([1.0, 0.0]), 2, Corvid\Metric::COSINE)
    ->text('body', 'rust database', 2)
    ->fuseRrf(60.0)
    ->rerankMmr(1.0)
    ->limit(2)
    ->run();

foreach ($rows as $rank => $r) {
    printf("%d. %s score=%.6f %s\n", $rank + 1, $r->key, $r->score, $r->doc['body']);
}
sh
./fetch.sh                        # download + sha256-verify corvid v0.4.1
./scripts/build-ext.sh            # phpize + configure + make
php -d extension=ext/corvid/modules/corvid.so tests/run-golden.php
php -d extension=ext/corvid/modules/corvid.so examples/quickstart.php
sh
php -d extension=ext/corvid/modules/corvid.so phpunit.phar