Skip to content

Commit fd9baff

Browse files
refactor: remove image parameters and properties from item requests and types
1 parent 884fc15 commit fd9baff

7 files changed

Lines changed: 12 additions & 70 deletions

File tree

src/Models/Collection.php

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -67,30 +67,26 @@ public function toArray(): array
6767
* @param number[][]|null $embeddings The embeddings of the items to add (optional).
6868
* @param array<string, array<string, mixed>>|null $metadatas The metadatas of the items to add (optional).
6969
* @param string[]|null $documents The documents of the items to add (optional).
70-
* @param string[]|null $images The base64 encoded images of the items to add (optional).
7170
* @return void
7271
*/
7372
public function add(
7473
array $ids,
7574
?array $embeddings = null,
7675
?array $metadatas = null,
7776
?array $documents = null,
78-
?array $images = null
7977
): void {
8078
if (!empty($ids) && $ids[0] instanceof Record) {
8179
$records = $ids;
8280
$ids = [];
8381
$embeddings = [];
8482
$metadatas = [];
8583
$documents = [];
86-
$images = [];
8784

8885
foreach ($records as $record) {
8986
$ids[] = $record->id;
9087
$embeddings[] = $record->embedding;
9188
$metadatas[] = $record->metadata;
9289
$documents[] = $record->document;
93-
$images[] = $record->image;
9490
}
9591
}
9692

@@ -99,7 +95,6 @@ public function add(
9995
embeddings: $embeddings,
10096
metadatas: $metadatas,
10197
documents: $documents,
102-
images: $images,
10398
requireEmbeddingsOrDocuments: true,
10499
);
105100

@@ -108,7 +103,6 @@ public function add(
108103
metadatas: $validated['metadatas'],
109104
ids: $validated['ids'],
110105
documents: $validated['documents'],
111-
images: $validated['images'],
112106
);
113107

114108
$this->api->addCollectionItems($this->id, $this->database, $this->tenant, $request);
@@ -121,30 +115,26 @@ public function add(
121115
* @param number[][]|null $embeddings The embeddings of the items to update (optional).
122116
* @param array<string, array<string, mixed>>|null $metadatas The metadatas of the items to update (optional).
123117
* @param string[]|null $documents The documents of the items to update (optional).
124-
* @param string[]|null $images The base64 encoded images of the items to update (optional).
125118
*
126119
*/
127120
public function update(
128121
array $ids,
129122
?array $embeddings = null,
130123
?array $metadatas = null,
131124
?array $documents = null,
132-
?array $images = null
133125
) {
134126
if (!empty($ids) && $ids[0] instanceof Record) {
135127
$records = $ids;
136128
$ids = [];
137129
$embeddings = [];
138130
$metadatas = [];
139131
$documents = [];
140-
$images = [];
141132

142133
foreach ($records as $record) {
143134
$ids[] = $record->id;
144135
$embeddings[] = $record->embedding;
145136
$metadatas[] = $record->metadata;
146137
$documents[] = $record->document;
147-
$images[] = $record->image;
148138
}
149139
}
150140

@@ -153,7 +143,6 @@ public function update(
153143
embeddings: $embeddings,
154144
metadatas: $metadatas,
155145
documents: $documents,
156-
images: $images,
157146
requireEmbeddingsOrDocuments: false,
158147
);
159148

@@ -162,7 +151,6 @@ public function update(
162151
ids: $validated['ids'],
163152
metadatas: $validated['metadatas'],
164153
documents: $validated['documents'],
165-
images: $validated['images'],
166154
);
167155

168156
$this->api->updateCollectionItems($this->id, $this->database, $this->tenant, $request);
@@ -175,30 +163,26 @@ public function update(
175163
* @param number[][]|null $embeddings The embeddings of the items to upsert (optional).
176164
* @param array<string, array<string, mixed>>|null $metadatas The metadatas of the items to upsert (optional).
177165
* @param string[]|null $documents The documents of the items to upsert (optional).
178-
* @param string[]|null $images The base64 encoded images of the items to upsert (optional).
179166
*
180167
*/
181168
public function upsert(
182169
array $ids,
183170
?array $embeddings = null,
184171
?array $metadatas = null,
185172
?array $documents = null,
186-
?array $images = null
187173
): void {
188174
if (!empty($ids) && $ids[0] instanceof Record) {
189175
$records = $ids;
190176
$ids = [];
191177
$embeddings = [];
192178
$metadatas = [];
193179
$documents = [];
194-
$images = [];
195180

196181
foreach ($records as $record) {
197182
$ids[] = $record->id;
198183
$embeddings[] = $record->embedding;
199184
$metadatas[] = $record->metadata;
200185
$documents[] = $record->document;
201-
$images[] = $record->image;
202186
}
203187
}
204188

@@ -207,7 +191,6 @@ public function upsert(
207191
embeddings: $embeddings,
208192
metadatas: $metadatas,
209193
documents: $documents,
210-
images: $images,
211194
requireEmbeddingsOrDocuments: true,
212195
);
213196

@@ -216,7 +199,6 @@ public function upsert(
216199
metadatas: $validated['metadatas'],
217200
ids: $validated['ids'],
218201
documents: $validated['documents'],
219-
images: $validated['images'],
220202
);
221203

222204
$this->api->upsertCollectionItems($this->id, $this->database, $this->tenant, $request);
@@ -307,7 +289,6 @@ public function delete(?array $ids = null, ?array $where = null, ?array $whereDo
307289
*
308290
* @param number[][]|null $queryEmbeddings The embeddings of the query (optional).
309291
* @param string[]|null $queryTexts The texts of the query (optional).
310-
* @param string[]|null $queryImages The images of the query (optional).
311292
* @param int $nResults The number of results to return (optional).
312293
* @param ?array $where The where clause to filter items to search based on metadata values (optional).
313294
* @param ?array $whereDocument The where clause to filter to search based on document content (optional).
@@ -316,7 +297,6 @@ public function delete(?array $ids = null, ?array $where = null, ?array $whereDo
316297
public function query(
317298
?array $queryEmbeddings = null,
318299
?array $queryTexts = null,
319-
?array $queryImages = null,
320300
int $nResults = 10,
321301
?array $where = null,
322302
?array $whereDocument = null,
@@ -331,10 +311,10 @@ public function query(
331311
}
332312

333313
if (
334-
!(($queryEmbeddings != null xor $queryTexts != null xor $queryImages != null))
314+
!(($queryEmbeddings != null xor $queryTexts != null))
335315
) {
336316
throw new InvalidArgumentException(
337-
'You must provide only one of queryEmbeddings, queryTexts, queryImages, or queryUris'
317+
'You must provide only one of queryEmbeddings or queryTexts'
338318
);
339319
}
340320

@@ -347,11 +327,9 @@ public function query(
347327
);
348328
} elseif ($queryTexts != null) {
349329
$finalEmbeddings = $this->embeddingFunction->generate($queryTexts);
350-
} elseif ($queryImages != null) {
351-
$finalEmbeddings = $this->embeddingFunction->generate($queryImages);
352330
} else {
353331
throw new InvalidArgumentException(
354-
'If you did not provide embeddings, you must provide documents or images'
332+
'If you did not provide queryEmbeddings, you must provide queryTexts'
355333
);
356334
}
357335
} else {
@@ -408,21 +386,20 @@ public function setEmbeddingFunction(EmbeddingFunction $embeddingFunction): void
408386
/**
409387
* Validates the inputs to the add, upsert, and update methods.
410388
*
411-
* @return array{ids: string[], embeddings: int[][], metadatas: array[], documents: string[], images: string[], uris: string[]}
389+
* @return array{ids: string[], embeddings: int[][], metadatas: array[], documents: string[]}
412390
*/
413391
protected function validate(
414392
array $ids,
415393
?array $embeddings,
416394
?array $metadatas,
417395
?array $documents,
418-
?array $images,
419396
bool $requireEmbeddingsOrDocuments
420397
): array {
421398

422399
if ($requireEmbeddingsOrDocuments) {
423-
if ($embeddings === null && $documents === null && $images === null) {
400+
if ($embeddings === null && $documents === null) {
424401
throw new InvalidArgumentException(
425-
'You must provide embeddings, documents, or images'
402+
'You must provide embeddings or documents'
426403
);
427404
}
428405
}
@@ -431,10 +408,9 @@ protected function validate(
431408
$embeddings != null && count($embeddings) != count($ids)
432409
|| $metadatas != null && count($metadatas) != count($ids)
433410
|| $documents != null && count($documents) != count($ids)
434-
|| $images != null && count($images) != count($ids)
435411
) {
436412
throw new InvalidArgumentException(
437-
'The number of ids, embeddings, metadatas, documents, and images must be the same'
413+
'The number of ids, embeddings, metadatas, and documents must be the same'
438414
);
439415
}
440416

@@ -459,11 +435,9 @@ protected function validate(
459435
);
460436
} elseif ($documents != null) {
461437
$finalEmbeddings = $this->embeddingFunction->generate($documents);
462-
} elseif ($images != null) {
463-
$finalEmbeddings = $this->embeddingFunction->generate($images);
464438
} else {
465439
throw new InvalidArgumentException(
466-
'If you did not provide embeddings, you must provide documents or images'
440+
'If you did not provide embeddings, you must provide documents'
467441
);
468442
}
469443
} else {
@@ -517,7 +491,6 @@ protected function validate(
517491
'embeddings' => $finalEmbeddings,
518492
'metadatas' => $metadatas,
519493
'documents' => $documents,
520-
'images' => $images,
521494
];
522495
}
523496
}

src/Requests/AddItemsRequest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ class AddItemsRequest
1515
* @param array<array<string, string>> $metadatas Optional metadatas of the items to add.
1616
* @param string[] $ids IDs of the items to add.
1717
* @param string[] $documents Optional documents of the items to add.
18-
* @param string[] $images Optional images of the items to add.
1918
*/
2019
public function __construct(
2120
public readonly array $ids,
2221
public readonly ?array $embeddings = null,
2322
public readonly ?array $metadatas = null,
2423
public readonly ?array $documents = null,
25-
public readonly ?array $images = null,
2624
) {}
2725

2826
public static function fromArray(array $data): self
@@ -32,7 +30,6 @@ public static function fromArray(array $data): self
3230
metadatas: $data['metadatas'] ?? null,
3331
ids: $data['ids'],
3432
documents: $data['documents'] ?? null,
35-
images: $data['images'] ?? null,
3633
);
3734
}
3835

@@ -43,7 +40,6 @@ public function toArray(): array
4340
'metadatas' => $this->metadatas,
4441
'ids' => $this->ids,
4542
'documents' => $this->documents,
46-
'images' => $this->images,
4743
], fn($value) => $value !== null);
4844
}
4945
}

src/Requests/UpdateItemsRequest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ class UpdateItemsRequest
1212
* @param string[] $ids IDs of the items to update.
1313
* @param array<string, string> $metadatas Optional metadatas of the items to update.
1414
* @param string[] $documents Optional documents of the items to update.
15-
* @param string[] $images Optional images of the items to update.
1615
*/
1716
public function __construct(
1817
public readonly ?array $embeddings,
1918
public readonly array $ids,
2019
public readonly ?array $metadatas,
2120
public readonly ?array $documents,
22-
public readonly ?array $images,
2321
) {}
2422

2523
public static function fromArray(array $data): self
@@ -29,7 +27,6 @@ public static function fromArray(array $data): self
2927
ids: $data['ids'],
3028
metadatas: $data['metadatas'] ?? null,
3129
documents: $data['documents'] ?? null,
32-
images: $data['images'] ?? null,
3330
);
3431
}
3532

src/Types/Record.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ class Record
1212
* @param array<string, mixed>|null $metadata The metadata of the item.
1313
* @param string|null $document The document content of the item.
1414
* @param string|null $uri The URI of the item.
15-
* @param string|null $image The base64 encoded image of the item.
1615
*/
1716
public function __construct(
1817
public string $id,
1918
public ?array $embedding = null,
2019
public ?array $metadata = null,
2120
public ?string $document = null,
2221
public ?string $uri = null,
23-
public ?string $image = null,
2422
) {
2523
}
2624

@@ -52,10 +50,4 @@ public function withUri(string $uri): self
5250
$this->uri = $uri;
5351
return $this;
5452
}
55-
56-
public function withImage(string $image): self
57-
{
58-
$this->image = $image;
59-
return $this;
60-
}
6153
}

src/Types/ScoredRecord.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,17 @@ class ScoredRecord extends Record
1212
* @param array<string, mixed>|null $metadata The metadata of the item.
1313
* @param string|null $document The document content of the item.
1414
* @param string|null $uri The URI of the item.
15-
* @param string|null $image The base64 encoded image of the item.
16-
* @param float|null $distance The distance of the item (only for query results).
15+
* @param float|null $distance The distance of the item
1716
*/
1817
public function __construct(
1918
string $id,
2019
?array $embedding = null,
2120
?array $metadata = null,
2221
?string $document = null,
2322
?string $uri = null,
24-
?string $image = null,
2523
public ?float $distance = null,
2624
) {
27-
parent::__construct($id, $embedding, $metadata, $document, $uri, $image);
28-
}
29-
30-
public static function make(string $id): self
31-
{
32-
return new self($id);
25+
parent::__construct($id, $embedding, $metadata, $document, $uri);
3326
}
3427

3528
public function withDistance(float $distance): self

0 commit comments

Comments
 (0)