Skip to content

Commit 7535e14

Browse files
feat: Add comprehensive API feature tests, refactor API client creation, and enhance request payload generation.
1 parent 9d5c50b commit 7535e14

13 files changed

Lines changed: 366 additions & 22 deletions

File tree

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,8 @@ jobs:
3939
- name: Install Composer dependencies
4040
run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist
4141

42+
- name: Start Chroma Server
43+
run: chroma run tests/chroma.yaml
44+
4245
- name: Run tests
4346
run: composer test

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@
5353
"test": "vendor/bin/pest",
5454
"test:coverage": "XDEBUG_MODE=coverage ./vendor/bin/pest --coverage"
5555
}
56-
}
56+
}

src/Factory.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,26 @@ public function withHeaders(array $headers): self
104104
}
105105

106106
public function connect(): Client
107+
{
108+
$api = $this->createApi();
109+
110+
return new Client($api, $this->database, $this->tenant);
111+
}
112+
113+
public function createApi(): Api
107114
{
108115
$baseUrl = $this->port ? "$this->host:$this->port" : $this->host;
109116

110117
$httpClient = Psr18ClientDiscovery::find();
111118
$requestFactory = Psr17FactoryDiscovery::findRequestFactory();
112119
$streamFactory = Psr17FactoryDiscovery::findStreamFactory();
113120

114-
$api = new Api(
121+
return new Api(
115122
$httpClient,
116123
$requestFactory,
117124
$streamFactory,
118125
$baseUrl,
119126
$this->headers
120127
);
121-
122-
return new Client($api, $this->database, $this->tenant);
123128
}
124129
}

src/Models/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public function query(
266266
$include ??= ['embeddings', 'metadatas', 'distances'];
267267

268268
if (
269-
!(($queryEmbeddings != null xor $queryTexts != null xor $queryImages != null))
269+
!(($queryEmbeddings != null xor $queryTexts != null xor $queryImages != null))
270270
) {
271271
throw new \InvalidArgumentException(
272272
'You must provide only one of queryEmbeddings, queryTexts, queryImages, or queryUris'
@@ -350,7 +350,7 @@ function validate(
350350
|| $images != null && count($images) != count($ids)
351351
) {
352352
throw new \InvalidArgumentException(
353-
'The number of ids, embeddings, metadatas, documents, and images must be the same'
353+
'The number of ids, embeddings, metadatas, documents, and images must be the same'
354354
);
355355
}
356356

src/Requests/AddItemsRequest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ public static function create(array $data): self
3939

4040
public function toArray(): array
4141
{
42-
return [
42+
return array_filter([
4343
'embeddings' => $this->embeddings,
4444
'metadatas' => $this->metadatas,
4545
'ids' => $this->ids,
4646
'documents' => $this->documents,
47-
];
47+
'images' => $this->images,
48+
], fn($value) => $value !== null);
4849
}
4950
}

src/Requests/DeleteItemsRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public static function create(array $data): self
2929

3030
public function toArray(): array
3131
{
32-
return [
32+
return array_filter([
3333
'ids' => $this->ids,
3434
'where' => $this->where,
3535
'where_document' => $this->whereDocument,
36-
];
36+
], fn($value) => $value !== null);
3737
}
3838
}

src/Requests/GetEmbeddingRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ public static function create(array $data): self
4444

4545
public function toArray(): array
4646
{
47-
return [
47+
return array_filter([
4848
'ids' => $this->ids,
4949
'where' => $this->where,
5050
'whereDocument' => $this->whereDocument,
5151
'sort' => $this->sort,
5252
'limit' => $this->limit,
5353
'offset' => $this->offset,
5454
'include' => $this->include,
55-
];
55+
], fn($value) => $value !== null);
5656
}
5757
}

0 commit comments

Comments
 (0)