Skip to content

Commit 3203472

Browse files
committed
fix: upsert many with non-zero arrays was not working
1 parent db5bf56 commit 3203472

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

src/Operations/UpsertDataOperation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function upsert(DataUpsert $upsert): void
3030
*/
3131
public function upsertMany(array $upsert): void
3232
{
33-
$data = array_map(fn (DataUpsert $upsert) => $upsert->toArray(), $upsert);
33+
$data = array_map(fn (DataUpsert $upsert) => $upsert->toArray(), array_values($upsert));
3434
$request = $this->createRequest($data);
3535

3636
$response = $this->transporter->sendRequest($request);

src/Operations/UpsertVectorOperation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function upsert(VectorUpsert $upsert): void
3232
*/
3333
public function upsertMany(array $upsert): void
3434
{
35-
$data = array_map(fn (VectorUpsert $upsert) => $upsert->toArray(), $upsert);
35+
$data = array_map(fn (VectorUpsert $upsert) => $upsert->toArray(), array_values($upsert));
3636
$request = $this->createRequest($data);
3737

3838
$response = $this->transporter->sendRequest($request);

tests/Dense/Operations/UpsertDataTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,19 @@ public function test_upsert_many_data(): void
4040

4141
$this->assertSame(3, $info->vectorCount);
4242
}
43+
44+
public function test_upsert_many_data_with_non_zero_index_works(): void
45+
{
46+
$this->namespace->upsertDataMany([
47+
1 => new DataUpsert(id: '1', data: 'The capital of Japan is Tokyo'),
48+
2 => new DataUpsert(id: '2', data: 'The capital of France is Paris'),
49+
3 => new DataUpsert(id: '3', data: 'The capital of Germany is Berlin'),
50+
]);
51+
52+
$this->waitForIndex($this->namespace);
53+
54+
$info = $this->namespace->getNamespaceInfo();
55+
56+
$this->assertSame(3, $info->vectorCount);
57+
}
4358
}

tests/Dense/Operations/UpsertVectorTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,17 @@ public function test_upsert_vector_with_different_dimensions_than_index_throws_e
4747
vector: [1, 2, 3],
4848
));
4949
}
50+
51+
public function test_upsert_many_vectors_with_non_zero_index_works(): void
52+
{
53+
// Act
54+
$this->namespace->upsertMany([
55+
1 => new VectorUpsert(id: '1', vector: [1, 2]),
56+
2 => new VectorUpsert(id: '2', vector: [4, 5]),
57+
3 => new VectorUpsert(id: '3', vector: [7, 8]),
58+
]);
59+
60+
// Assert
61+
$this->assertSame(3, $this->namespace->getNamespaceInfo()->vectorCount);
62+
}
5063
}

0 commit comments

Comments
 (0)