-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_usage.php
More file actions
68 lines (53 loc) · 2.32 KB
/
Copy pathbasic_usage.php
File metadata and controls
68 lines (53 loc) · 2.32 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
require '../vendor/autoload.php';
use TheoGibbons\ChromaPHP\ChromaDBClient;
$chroma = ChromaDBClient::connect([
'host' => 'http://localhost',
'port' => 8000,
]);
$tenantName = 'default_tenant';
$databaseName = 'default_database';
$collectionName = 'test_collection_' . uniqid();
try {
echo "\n----------------- Testing connection -----------------\n";
print_r($chroma->heartbeat());
echo "\n----------------- Testing version -----------------\n";
echo "ChromaDB Version: " . $chroma->version() . "\n";
echo "\n----------------- Testing identity -----------------\n";
print_r($chroma->identity());
echo "\n----------------- Creating collection: $collectionName -----------------\n";
$createResponse = $chroma->createCollection($tenantName, $databaseName, [
'name' => $collectionName,
'metadata' => ['test' => 'yes'],
]);
print_r($createResponse);
echo "\n----------------- Listing collections -----------------\n";
foreach ($chroma->listCollections($tenantName, $databaseName) as $collection) {
echo "- {$collection['name']}\n";
}
echo "\n----------------- Adding data to collection -----------------\n";
print_r($chroma->addToCollection($tenantName, $databaseName, $createResponse['id'], [
'ids' => ['doc1'],
'embeddings' => [[1.0, 2.0, 3.0, 4.0]],
'documents' => ['Hello World'],
]));
echo "\n----------------- Querying collection -----------------\n";
print_r($chroma->queryCollection($tenantName, $databaseName, $createResponse['id'], [
'query_embeddings' => [[1.0, 2.0, 3.0, 4.0]],
'n_results' => 1,
]));
echo "\n----------------- Checking collection exists -----------------\n";
$found = count(array_filter(
$chroma->listCollections($tenantName, $databaseName),
fn($c) => $c['id'] === $createResponse['id']
)) > 0;
echo $found ? "Collection found.\n" : "Collection not found.\n";
echo "\n----------------- Deleting collection -----------------\n";
$chroma->deleteCollection($tenantName, $databaseName, $collectionName);
echo "Collection deleted.\n";
echo "\n✅ Test completed successfully.\n";
} catch (Exception $e) {
echo "\n❌ Test failed: {$e->getMessage()}\n";
echo $e->getTraceAsString();
}
die("Done\n");