PHP code example of mindfulcoder49 / mysql-vector-openai

1. Go to this page and download the library: Download mindfulcoder49/mysql-vector-openai 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/ */

    

mindfulcoder49 / mysql-vector-openai example snippets


$results = $vectorTable->search($inputVector, $n = 10);

$results = $vectorTable->searchWithHamming($inputVector, $n = 10);

$id = $vectorTable->upsert($vector, $id = null);

$ids = $vectorTable->batchInsert($vectorArray);

$vectors = $vectorTable->select($ids);

$vectors = $vectorTable->selectAll();

$vectorTable->delete($id);

$normalizedVector = $vectorTable->normalize($vector);

$similarity = $vectorTable->cosim($v1, $v2);

$totalVectors = $vectorTable->count();

$binaryCode = $vectorTable->vectorToBinary($vector);

$vectorTable->initialize();

$mysqli = new \mysqli('localhost', 'user', 'password', 'database');

$vectorTable = new \MHz\MysqlVector\VectorTable($mysqli, 'example_table', 384);
$vectorTable->initialize();

$vector = [1, 2, 3, 4, 5];
$vectorTable->upsert($vector);

$similarVectors = $vectorTable->search($vector);