Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit a42da3a

Browse files
authored
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 b3acb31 commit a42da3a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Store/Bridge/MariaDB/Store.php

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

128128
/**
129-
* @param array{} $options
129+
* @param array{dimensions?: positive-int} $options
130130
*/
131131
public function initialize(array $options = []): void
132132
{
133-
if ([] !== $options) {
134-
throw new InvalidArgumentException('No supported options');
133+
if ([] !== $options && !\array_key_exists('dimensions', $options)) {
134+
throw new InvalidArgumentException('The only supported option is "dimensions"');
135135
}
136136

137137
$serverVersion = $this->connection->getAttribute(\PDO::ATTR_SERVER_VERSION);
@@ -146,13 +146,14 @@ public function initialize(array $options = []): void
146146
CREATE TABLE IF NOT EXISTS %1$s (
147147
id BINARY(16) NOT NULL PRIMARY KEY,
148148
metadata JSON,
149-
%2$s VECTOR(1536) NOT NULL,
149+
%2$s VECTOR(%4$d) NOT NULL,
150150
VECTOR INDEX %3$s (%2$s)
151151
)
152152
SQL,
153153
$this->tableName,
154154
$this->vectorFieldName,
155155
$this->indexName,
156+
$options['dimensions'] ?? 1536,
156157
),
157158
);
158159
}

0 commit comments

Comments
 (0)