-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathindex.php
More file actions
39 lines (29 loc) · 1006 Bytes
/
index.php
File metadata and controls
39 lines (29 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
declare(strict_types=1);
require __DIR__ . '/../../vendor/autoload.php';
use Codewithkyrian\ChromaDB\ChromaDB;
use Codewithkyrian\ChromaDB\Embeddings\JinaEmbeddingFunction;
use Codewithkyrian\ChromaDB\Embeddings\OllamaEmbeddingFunction;
$chroma = ChromaDB::factory()
->withDatabase('test_database')
->withTenant('test_tenant')
->connect();
$embeddingFunction = new OllamaEmbeddingFunction();
$collection = $chroma->getCollection(
name: 'test_collection',
embeddingFunction: $embeddingFunction
);
$items = [
["id" => 1, "content" => "He seems very happy"],
["id" => 2, "content" => "He was very sad when we last talked"],
["id" => 3, "content" => "She made him angry"],
];
$collection->add(
ids: array_column($items, 'id'),
documents: array_column($items, 'content')
);
$queryResponse = $collection->query(
queryTexts: ['She annoyed him'],
include: ['documents', 'distances']
);
dd($queryResponse->documents[0], $queryResponse->distances[0]);