Skip to content

Commit d0999b9

Browse files
committed
minor #903 [Store][MariaDB] Use UUID type instead of Binary (lyrixx)
This PR was merged into the main branch. Discussion ---------- [Store][MariaDB] Use UUID type instead of Binary | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | | License | MIT Binary type is really painful It needs to be casted to be able to read it. There is no native function to do that in MariaDB. And except for HUGE amount of data, it does not make a big deference from char(36). I mean, there is a trade off to find between perf and DX. ANYWAY, MariaDB comes from a native UUID type that solves all issues! Let's use it. Commits ------- c5dc4d9 [Store][MariaDB] Use UUID type instead of Binary
2 parents 7bd5f0a + c5dc4d9 commit d0999b9

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/store/src/Bridge/MariaDb/Store.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function setup(array $options = []): void
6666
\sprintf(
6767
<<<'SQL'
6868
CREATE TABLE IF NOT EXISTS %1$s (
69-
id BINARY(16) NOT NULL PRIMARY KEY,
69+
id UUID NOT NULL PRIMARY KEY,
7070
metadata JSON,
7171
`%2$s` VECTOR(%4$d) NOT NULL,
7272
VECTOR INDEX %3$s (`%2$s`)
@@ -126,7 +126,7 @@ public function add(VectorDocument ...$documents): void
126126

127127
foreach ($documents as $document) {
128128
$operation = [
129-
'id' => $document->id->toBinary(),
129+
'id' => $document->id->toRfc4122(),
130130
'metadata' => json_encode($document->metadata->getArrayCopy()),
131131
'vector' => json_encode($document->vector->getData()),
132132
];
@@ -173,7 +173,7 @@ public function query(Vector $vector, array $options = []): array
173173

174174
foreach ($statement->fetchAll(\PDO::FETCH_ASSOC) as $result) {
175175
$documents[] = new VectorDocument(
176-
id: Uuid::fromBinary($result['id']),
176+
id: Uuid::fromRfc4122($result['id']),
177177
vector: new Vector(json_decode((string) $result['embedding'], true)),
178178
metadata: new Metadata(json_decode($result['metadata'] ?? '{}', true)),
179179
score: $result['score'],

src/store/tests/Bridge/MariaDb/StoreTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function testQueryWithMaxScore()
5656
->with(\PDO::FETCH_ASSOC)
5757
->willReturn([
5858
[
59-
'id' => $uuid->toBinary(),
59+
'id' => $uuid->toRfc4122(),
6060
'embedding' => json_encode($vectorData),
6161
'metadata' => json_encode(['title' => 'Test Document']),
6262
'score' => 0.85,
@@ -104,7 +104,7 @@ public function testQueryWithoutMaxScore()
104104
->with(\PDO::FETCH_ASSOC)
105105
->willReturn([
106106
[
107-
'id' => $uuid->toBinary(),
107+
'id' => $uuid->toRfc4122(),
108108
'embedding' => json_encode($vectorData),
109109
'metadata' => json_encode(['title' => 'Test Document']),
110110
'score' => 0.95,

0 commit comments

Comments
 (0)