Skip to content

Commit 23ab86a

Browse files
committed
refactor(store): embeddings limit removed
1 parent 590f623 commit 23ab86a

File tree

4 files changed

+5
-84
lines changed

4 files changed

+5
-84
lines changed

examples/compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ services:
3333
surrealdb:
3434
image: surrealdb/surrealdb:v2
3535
command: ['start', '--user', 'symfony', '--pass', 'symfony']
36+
environment:
37+
SURREAL_HTTP_MAX_KEY_BODY_SIZE: 49152
3638
ports:
3739
- '8000:8000'

src/store/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ CHANGELOG
4343
- ChromaDB
4444
- Pinecone
4545
- Qdrant
46+
- SurrealDB
4647
* Add Retrieval Augmented Generation (RAG) support:
4748
- Document embedding storage
4849
- Similarity search for relevant documents

src/store/src/Bridge/SurrealDB/Store.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
*/
2828
final class Store implements InitializableStoreInterface, VectorStoreInterface
2929
{
30-
private const MAXIMUM_EMBEDDINGS_DIMENSIONS = 1275;
31-
3230
public function __construct(
3331
private readonly HttpClientInterface $httpClient,
3432
private readonly string $endpointUrl,
@@ -43,7 +41,7 @@ public function __construct(
4341
private readonly string $table = 'vectors',
4442
private readonly string $vectorFieldName = '_vectors',
4543
private readonly string $strategy = 'cosine',
46-
private readonly int $embeddingsDimension = self::MAXIMUM_EMBEDDINGS_DIMENSIONS,
44+
private readonly int $embeddingsDimension = 1536,
4745
) {
4846
}
4947

@@ -52,10 +50,6 @@ public function add(VectorDocument ...$documents): void
5250
$authenticationToken = $this->authenticate([]);
5351

5452
foreach ($documents as $document) {
55-
if (self::MAXIMUM_EMBEDDINGS_DIMENSIONS < $document->vector->getDimensions()) {
56-
throw new InvalidArgumentException(\sprintf('The SurrealDB HTTP API does not support embeddings with more than %d dimensions, found %d', self::MAXIMUM_EMBEDDINGS_DIMENSIONS, $document->vector->getDimensions()));
57-
}
58-
5953
$this->request('POST', \sprintf('key/%s', $this->table), $this->convertToIndexableArray($document), [
6054
'Surreal-NS' => $this->namespace,
6155
'Surreal-DB' => $this->database,
@@ -66,10 +60,6 @@ public function add(VectorDocument ...$documents): void
6660

6761
public function query(Vector $vector, array $options = [], ?float $minScore = null): array
6862
{
69-
if (self::MAXIMUM_EMBEDDINGS_DIMENSIONS < $vector->getDimensions()) {
70-
throw new InvalidArgumentException(\sprintf('The dimensions of the vector must be less than or equal to %d, found %d', self::MAXIMUM_EMBEDDINGS_DIMENSIONS, $vector->getDimensions()));
71-
}
72-
7363
$authenticationToken = $this->authenticate($options);
7464

7565
$vectors = json_encode($vector->getData());
@@ -160,9 +150,7 @@ private function convertToVectorDocument(array $data): VectorDocument
160150
return new VectorDocument(
161151
id: Uuid::fromString($id),
162152
vector: $vector,
163-
metadata: new Metadata(array_merge($data['_metadata'], [
164-
$this->vectorFieldName => $data[$this->vectorFieldName],
165-
])),
153+
metadata: new Metadata($data['_metadata']),
166154
);
167155
}
168156

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

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Symfony\AI\Platform\Vector\Vector;
1717
use Symfony\AI\Store\Bridge\SurrealDB\Store;
1818
use Symfony\AI\Store\Document\VectorDocument;
19-
use Symfony\AI\Store\Exception\InvalidArgumentException;
2019
use Symfony\Component\HttpClient\Exception\ClientException;
2120
use Symfony\Component\HttpClient\MockHttpClient;
2221
use Symfony\Component\HttpClient\Response\JsonMockResponse;
@@ -115,26 +114,6 @@ public function testStoreCannotAddOnInvalidResponse(): void
115114
$store->add(new VectorDocument(Uuid::v4(), new Vector([0.1, 0.2, 0.3])));
116115
}
117116

118-
public function testStoreCannotAddOnOversizedEmbeddings(): void
119-
{
120-
$httpClient = new MockHttpClient([
121-
new JsonMockResponse([
122-
'code' => 200,
123-
'details' => 'Authentication succeeded.',
124-
'token' => 'bar',
125-
], [
126-
'http_code' => 200,
127-
]),
128-
], 'http://localhost:8000');
129-
130-
$store = new Store($httpClient, 'http://localhost:8000', 'test', 'test', 'test', 'test');
131-
132-
self::expectException(InvalidArgumentException::class);
133-
self::expectExceptionMessage('The SurrealDB HTTP API does not support embeddings with more than 1275 dimensions, found 2000');
134-
self::expectExceptionCode(0);
135-
$store->add(new VectorDocument(Uuid::v4(), new Vector(array_fill(0, 2000, 0.1))));
136-
}
137-
138117
public function testStoreCannotAddOnInvalidAddResponse(): void
139118
{
140119
$httpClient = new MockHttpClient([
@@ -257,55 +236,6 @@ public function testStoreCannotQueryOnInvalidResponse(): void
257236
$store->query(new Vector(array_fill(0, 1275, 0.1)));
258237
}
259238

260-
public function testStoreCannotQueryOnOversizedEmbeddings(): void
261-
{
262-
$httpClient = new MockHttpClient([
263-
new JsonMockResponse([
264-
'code' => 200,
265-
'details' => 'Authentication succeeded.',
266-
'token' => 'bar',
267-
], [
268-
'http_code' => 200,
269-
]),
270-
new JsonMockResponse([
271-
[
272-
'result' => [
273-
[
274-
'id' => Uuid::v4()->toRfc4122(),
275-
'_vectors' => [0.1, 0.1, 0.1],
276-
'_metadata' => [
277-
'_id' => Uuid::v4()->toRfc4122(),
278-
],
279-
],
280-
[
281-
'id' => Uuid::v4()->toRfc4122(),
282-
'_vectors' => [0.1, 0.1, 0.1],
283-
'_metadata' => [
284-
'_id' => Uuid::v4()->toRfc4122(),
285-
],
286-
],
287-
],
288-
'status' => 'OK',
289-
'time' => '263.208µs',
290-
],
291-
], [
292-
'http_code' => 200,
293-
]),
294-
new JsonMockResponse([], [
295-
'http_code' => 400,
296-
]),
297-
], 'http://localhost:8000');
298-
299-
$store = new Store($httpClient, 'http://localhost:8000', 'test', 'test', 'test', 'test', 'test');
300-
301-
$store->add(new VectorDocument(Uuid::v4(), new Vector(array_fill(0, 1275, 0.1))));
302-
303-
self::expectException(InvalidArgumentException::class);
304-
self::expectExceptionMessage('The dimensions of the vector must be less than or equal to 1275, found 2000');
305-
self::expectExceptionCode(0);
306-
$store->query(new Vector(array_fill(0, 2000, 0.1)));
307-
}
308-
309239
public function testStoreCanQueryOnValidEmbeddings(): void
310240
{
311241
$httpClient = new MockHttpClient([

0 commit comments

Comments
 (0)