Skip to content

Commit b1c2fe5

Browse files
valtzuchr-hertel
authored andcommitted
chore: Allow arbitrary vector dimensions for MariaDB store (#348)
MariaDB insists the dimensions of the vector being inserted match exactly the dimensions of the vector defined in the schema. Since the store knows nothing about the Model & it's expected vector dimensions, let's allow passing vector dimensions as a parameter to `initialize()` leave the problem to the user.
1 parent c6e32b6 commit b1c2fe5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/store/src/Bridge/MariaDB/Store.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ public function query(Vector $vector, array $options = [], ?float $minScore = nu
133133
}
134134

135135
/**
136-
* @param array{} $options
136+
* @param array{dimensions?: positive-int} $options
137137
*/
138138
public function initialize(array $options = []): void
139139
{
140-
if ([] !== $options) {
141-
throw new InvalidArgumentException('No supported options');
140+
if ([] !== $options && !\array_key_exists('dimensions', $options)) {
141+
throw new InvalidArgumentException('The only supported option is "dimensions"');
142142
}
143143

144144
$serverVersion = $this->connection->getAttribute(\PDO::ATTR_SERVER_VERSION);
@@ -153,13 +153,14 @@ public function initialize(array $options = []): void
153153
CREATE TABLE IF NOT EXISTS %1$s (
154154
id BINARY(16) NOT NULL PRIMARY KEY,
155155
metadata JSON,
156-
%2$s VECTOR(1536) NOT NULL,
156+
%2$s VECTOR(%4$d) NOT NULL,
157157
VECTOR INDEX %3$s (%2$s)
158158
)
159159
SQL,
160160
$this->tableName,
161161
$this->vectorFieldName,
162162
$this->indexName,
163+
$options['dimensions'] ?? 1536,
163164
),
164165
);
165166
}

0 commit comments

Comments
 (0)