Skip to content

Commit 9d5c50b

Browse files
feat: enhance simple example with robust autoload path, getCollection, and structured data for add.
1 parent 0b05cb9 commit 9d5c50b

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
playground/*
99
.idea
1010
.chroma
11-
.vscode
11+
.vscode

examples/simple.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
require '../vendor/autoload.php';
5+
require __DIR__ . '/../vendor/autoload.php';
66

77
use Codewithkyrian\ChromaDB\ChromaDB;
88
use Codewithkyrian\ChromaDB\Embeddings\JinaEmbeddingFunction;
@@ -13,18 +13,22 @@
1313
->withTenant('test_tenant')
1414
->connect();
1515

16-
$chroma->deleteAllCollections();
17-
1816
$embeddingFunction = new OllamaEmbeddingFunction();
1917

20-
$collection = $chroma->createCollection(
18+
$collection = $chroma->getCollection(
2119
name: 'test_collection',
2220
embeddingFunction: $embeddingFunction
2321
);
2422

23+
$items = [
24+
["id" => 1, "content" => "He seems very happy" ],
25+
["id" => 2, "content"=> "He was very sad when we last talked"],
26+
["id" => 3, "content"=> "She made him angry"],
27+
];
28+
2529
$collection->add(
26-
ids: ['1', '2', '3'],
27-
documents: ['He seems very happy', 'He was very sad when we last talked', 'She made him angry']
30+
ids: array_column($items, 'id'),
31+
documents: array_column($items, 'content')
2832
);
2933

3034
$queryResponse = $collection->query(

0 commit comments

Comments
 (0)