1. Go to this page and download the library: Download codewithkyrian/chromadb-php 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/ */
use CodeWithKyrian\ChromaDB\EmbeddingFunction\EmbeddingFunctionInterface;
$embeddingFunction = new OpenAIEmbeddingFunction('api-key', 'org-id', 'model-name');
$collection = $chroma->createCollection('test-collection', embeddingFunction: $embeddingFunction);
use CodeWithKyrian\Chroma\EmbeddingFunction\OpenAIEmbeddingFunction;
$embeddingFunction = new OpenAIEmbeddingFunction('api-key', 'org-id', 'model-name');
$collection = $chromaDB->createCollection('test-collection', embeddingFunction: $embeddingFunction);
use Codewithkyrian\ChromaDB\Embeddings\JinaEmbeddingFunction;
$embeddingFunction = new JinaEmbeddingFunction('api-key');
$collection = $chromaDB->createCollection('test-collection', embeddingFunction: $embeddingFunction);
use CodeWithKyrian\Chroma\EmbeddingFunction\HuggingFaceEmbeddingFunction;
$embeddingFunction = new HuggingFaceEmbeddingFunction('api-key', 'model-name');
$collection = $chromaDB->createCollection('test-collection', embeddingFunction: $embeddingFunction);
use CodeWithKyrian\ChromaDB\EmbeddingFunction\EmbeddingFunctionInterface;
$embeddingFunction = new class implements EmbeddingFunctionInterface {
public function generate(array $texts): array
{
// Compute the embeddings here and return them as an array of arrays
}
};
$collection = $chroma->createCollection('test-collection', embeddingFunction: $embeddingFunction);
$ids = ['test1', 'test2', 'test3'];
$documents = [
'This is a test document',
'This is another test document',
'This is yet another test document',
];
$metadatas = [
['url' => 'https://example.com/test1'],
['url' => 'https://example.com/test2'],
['url' => 'https://example.com/test3'],
];
$collection->add(
ids: $ids,
documents: $documents,
metadatas: $metadatas
);