Skip to content
2 changes: 1 addition & 1 deletion docs/cookbook/rag-implementation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ Document Loading Strategies
$articles = $articleRepository->findAll();
$documents = array_map(
fn($article) => new TextDocument(
id: Uuid::fromString($article->getId()),
id: $article->getId(),
content: $article->getTitle().PHP_EOL.$article->getContent(),
metadata: new Metadata(['author' => $article->getAuthor()])
),
Expand Down
3 changes: 1 addition & 2 deletions src/store/src/Bridge/AzureSearch/SearchStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Symfony\AI\Store\Document\Metadata;
use Symfony\AI\Store\Document\VectorDocument;
use Symfony\AI\Store\StoreInterface;
use Symfony\Component\Uid\Uuid;
use Symfony\Contracts\HttpClient\HttpClientInterface;

/**
Expand Down Expand Up @@ -91,7 +90,7 @@ private function convertToIndexableArray(VectorDocument $document): array
private function convertToVectorDocument(array $data): VectorDocument
{
return new VectorDocument(
id: Uuid::fromString($data['id']),
id: $data['id'],
vector: !\array_key_exists($this->vectorFieldName, $data) || null === $data[$this->vectorFieldName]
? new NullVector()
: new Vector($data[$this->vectorFieldName]),
Expand Down
3 changes: 1 addition & 2 deletions src/store/src/Bridge/Cache/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Symfony\AI\Store\Exception\InvalidArgumentException;
use Symfony\AI\Store\ManagedStoreInterface;
use Symfony\AI\Store\StoreInterface;
use Symfony\Component\Uid\Uuid;
use Symfony\Contracts\Cache\CacheInterface;

/**
Expand Down Expand Up @@ -79,7 +78,7 @@ public function query(Vector $vector, array $options = []): iterable
$documents = $this->cache->get($this->cacheKey, static fn (): array => []);

$vectorDocuments = array_map(static fn (array $document): VectorDocument => new VectorDocument(
id: Uuid::fromString($document['id']),
id: $document['id'],
vector: new Vector($document['vector']),
metadata: new Metadata($document['metadata']),
), $documents);
Expand Down
3 changes: 1 addition & 2 deletions src/store/src/Bridge/ChromaDb/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Symfony\AI\Store\Document\Metadata;
use Symfony\AI\Store\Document\VectorDocument;
use Symfony\AI\Store\StoreInterface;
use Symfony\Component\Uid\Uuid;

/**
* @author Christopher Hertel <mail@christopher-hertel.de>
Expand Down Expand Up @@ -83,7 +82,7 @@ public function query(Vector $vector, array $options = []): iterable
}

yield new VectorDocument(
id: Uuid::fromString($queryResponse->ids[0][$i]),
id: $queryResponse->ids[0][$i],
vector: new Vector($queryResponse->embeddings[0][$i]),
metadata: $metaData,
score: $queryResponse->distances[0][$i] ?? null,
Expand Down
3 changes: 1 addition & 2 deletions src/store/src/Bridge/ClickHouse/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\AI\Store\Exception\RuntimeException;
use Symfony\AI\Store\ManagedStoreInterface;
use Symfony\AI\Store\StoreInterface;
use Symfony\Component\Uid\Uuid;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;

Expand Down Expand Up @@ -95,7 +94,7 @@ public function query(Vector $vector, array $options = [], ?float $minScore = nu

foreach ($results as $result) {
yield new VectorDocument(
id: Uuid::fromString($result['id']),
id: $result['id'],
vector: new Vector($result['embedding']),
metadata: new Metadata(json_decode($result['metadata'] ?? '{}', true, 512, \JSON_THROW_ON_ERROR)),
score: $result['score'],
Expand Down
3 changes: 1 addition & 2 deletions src/store/src/Bridge/Cloudflare/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\AI\Store\Exception\InvalidArgumentException;
use Symfony\AI\Store\ManagedStoreInterface;
use Symfony\AI\Store\StoreInterface;
use Symfony\Component\Uid\Uuid;
use Symfony\Contracts\HttpClient\HttpClientInterface;

/**
Expand Down Expand Up @@ -138,7 +137,7 @@ private function convertToVectorDocument(array $data): VectorDocument
: new Vector($data['values']);

return new VectorDocument(
id: Uuid::fromString($id),
id: $id,
vector: $vector,
metadata: new Metadata($data['metadata']),
score: $data['score'] ?? null
Expand Down
3 changes: 1 addition & 2 deletions src/store/src/Bridge/ManticoreSearch/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\AI\Store\Exception\InvalidArgumentException;
use Symfony\AI\Store\ManagedStoreInterface;
use Symfony\AI\Store\StoreInterface;
use Symfony\Component\Uid\Uuid;
use Symfony\Contracts\HttpClient\HttpClientInterface;

/**
Expand Down Expand Up @@ -150,7 +149,7 @@ private function convertToVectorDocument(array $data): VectorDocument
: new Vector($payload[$this->field]);

return new VectorDocument(
id: Uuid::fromString($payload['uuid']),
id: $payload['uuid'],
vector: $vector,
metadata: new Metadata($payload['metadata'] ?? []),
score: $data['_knn_dist'] ?? null
Expand Down
4 changes: 2 additions & 2 deletions src/store/src/Bridge/Meilisearch/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private function request(string $method, string $endpoint, array $payload): arra
private function convertToIndexableArray(VectorDocument $document): array
{
return array_merge([
'id' => $document->id->toRfc4122(),
'id' => $document->id,
$this->vectorFieldName => [
$this->embedder => [
'embeddings' => $document->vector->getData(),
Expand All @@ -154,6 +154,6 @@ private function convertToVectorDocument(array $data): VectorDocument

unset($data['id'], $data[$this->vectorFieldName], $data['_rankingScore']);

return new VectorDocument(Uuid::fromString($id), $vector, new Metadata($data), $score);
return new VectorDocument($id, $vector, new Metadata($data), $score);
}
}
4 changes: 2 additions & 2 deletions src/store/src/Bridge/Milvus/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private function request(string $method, string $endpoint, array $payload): arra
private function convertToIndexableArray(VectorDocument $document): array
{
return [
'id' => $document->id->toRfc4122(),
'id' => $document->id,
'_metadata' => json_encode($document->metadata->getArrayCopy()),
$this->vectorFieldName => $document->vector->getData(),
];
Expand All @@ -170,6 +170,6 @@ private function convertToVectorDocument(array $data): VectorDocument

$score = $data['distance'] ?? null;

return new VectorDocument(Uuid::fromString($id), $vector, new Metadata(json_decode($data['_metadata'], true)), $score);
return new VectorDocument($id, $vector, new Metadata(json_decode($data['_metadata'], true)), $score);
}
}
6 changes: 3 additions & 3 deletions src/store/src/Bridge/MongoDb/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function query(Vector $vector, array $options = []): iterable

foreach ($results as $result) {
yield new VectorDocument(
id: $this->toUuid($result['_id']),
id: $this->getBinaryData($result['_id']),
vector: new Vector($result[$this->vectorFieldName]),
metadata: new Metadata($result['metadata'] ?? []),
score: $result['score'],
Expand All @@ -197,8 +197,8 @@ private function toBinary(Uuid $uuid): Binary
return new Binary($uuid->toBinary(), Binary::TYPE_UUID);
}

private function toUuid(Binary $binary): Uuid
private function getBinaryData(Binary $binary): string
{
return Uuid::fromString($binary->getData());
return $binary->getData();
}
}
3 changes: 1 addition & 2 deletions src/store/src/Bridge/Neo4j/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\AI\Store\Exception\InvalidArgumentException;
use Symfony\AI\Store\ManagedStoreInterface;
use Symfony\AI\Store\StoreInterface;
use Symfony\Component\Uid\Uuid;
use Symfony\Contracts\HttpClient\HttpClientInterface;

/**
Expand Down Expand Up @@ -117,7 +116,7 @@ private function convertToVectorDocument(array $data): VectorDocument
: new Vector($payload['properties'][$this->embeddingsField]);

return new VectorDocument(
id: Uuid::fromString($id),
id: $id,
vector: $vector,
metadata: new Metadata(json_decode($payload['properties']['metadata'], true)),
score: $data[1] ?? null
Expand Down
4 changes: 2 additions & 2 deletions src/store/src/Bridge/OpenSearch/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function add(VectorDocument ...$documents): void
$documentToIndex = fn (VectorDocument $document): array => [
'index' => [
'_index' => $this->indexName,
'_id' => $document->id->toRfc4122(),
'_id' => $document->id,
],
];

Expand Down Expand Up @@ -153,6 +153,6 @@ private function convertToVectorDocument(array $document): VectorDocument
? new NullVector()
: new Vector($document['_source'][$this->vectorsField]);

return new VectorDocument(Uuid::fromString($id), $vector, new Metadata(json_decode($document['_source']['metadata'], true)), $document['_score'] ?? null);
return new VectorDocument($id, $vector, new Metadata(json_decode($document['_source']['metadata'], true)), $document['_score'] ?? null);
}
}
3 changes: 1 addition & 2 deletions src/store/src/Bridge/Pinecone/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Symfony\AI\Store\Document\Metadata;
use Symfony\AI\Store\Document\VectorDocument;
use Symfony\AI\Store\StoreInterface;
use Symfony\Component\Uid\Uuid;

/**
* @author Christopher Hertel <mail@christopher-hertel.de>
Expand Down Expand Up @@ -65,7 +64,7 @@ public function query(Vector $vector, array $options = []): iterable

foreach ($result->json()['matches'] as $match) {
yield new VectorDocument(
id: Uuid::fromString($match['id']),
id: $match['id'],
vector: new Vector($match['values']),
metadata: new Metadata($match['metadata']),
score: $match['score'],
Expand Down
3 changes: 1 addition & 2 deletions src/store/src/Bridge/Postgres/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Symfony\AI\Store\Exception\InvalidArgumentException;
use Symfony\AI\Store\ManagedStoreInterface;
use Symfony\AI\Store\StoreInterface;
use Symfony\Component\Uid\Uuid;

/**
* Requires PostgreSQL with pgvector extension.
Expand Down Expand Up @@ -172,7 +171,7 @@ public function query(Vector $vector, array $options = []): iterable

foreach ($statement->fetchAll(\PDO::FETCH_ASSOC) as $result) {
yield new VectorDocument(
id: Uuid::fromString($result['id']),
id: $result['id'],
vector: new Vector($this->fromPgvector($result['embedding'])),
metadata: new Metadata(json_decode($result['metadata'] ?? '{}', true, 512, \JSON_THROW_ON_ERROR)),
score: $result['score'],
Expand Down
3 changes: 1 addition & 2 deletions src/store/src/Bridge/Qdrant/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\AI\Store\Exception\InvalidArgumentException;
use Symfony\AI\Store\ManagedStoreInterface;
use Symfony\AI\Store\StoreInterface;
use Symfony\Component\Uid\Uuid;
use Symfony\Contracts\HttpClient\HttpClientInterface;

/**
Expand Down Expand Up @@ -153,7 +152,7 @@ private function convertToVectorDocument(array $data): VectorDocument
: new Vector($data['vector']);

return new VectorDocument(
id: Uuid::fromString($id),
id: $id,
vector: $vector,
metadata: new Metadata($data['payload']),
score: $data['score'] ?? null
Expand Down
3 changes: 1 addition & 2 deletions src/store/src/Bridge/Redis/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\AI\Store\Exception\RuntimeException;
use Symfony\AI\Store\ManagedStoreInterface;
use Symfony\AI\Store\StoreInterface;
use Symfony\Component\Uid\Uuid;

/**
* @author Grégoire Pineau <lyrixx@lyrixx.info>
Expand Down Expand Up @@ -167,7 +166,7 @@ public function query(Vector $vector, array $options = []): iterable
}

yield new VectorDocument(
id: Uuid::fromString($data['$.id']),
id: $data['$.id'],
vector: new Vector($data['$.embedding'] ?? []),
metadata: new Metadata($data['$.metadata'] ?? []),
score: $score,
Expand Down
3 changes: 1 addition & 2 deletions src/store/src/Bridge/Supabase/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Symfony\AI\Store\Exception\InvalidArgumentException;
use Symfony\AI\Store\Exception\RuntimeException;
use Symfony\AI\Store\StoreInterface;
use Symfony\Component\Uid\Uuid;
use Symfony\Contracts\HttpClient\HttpClientInterface;

/**
Expand Down Expand Up @@ -137,7 +136,7 @@ public function query(Vector $vector, array $options = []): iterable
$metadata = \is_array($record['metadata']) ? $record['metadata'] : json_decode($record['metadata'], true, 512, \JSON_THROW_ON_ERROR);

yield new VectorDocument(
id: Uuid::fromString($record['id']),
id: $record['id'],
vector: new Vector($embedding),
metadata: new Metadata($metadata),
score: (float) $record['score'],
Expand Down
8 changes: 4 additions & 4 deletions src/store/src/Bridge/Supabase/Tests/StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function testQuerySuccess()

$this->assertCount(1, $result);
$this->assertInstanceOf(VectorDocument::class, $result[0]);
$this->assertTrue($uuid->equals($result[0]->id));
$this->assertSame($uuid->toRfc4122(), $result[0]->id);
$this->assertSame([0.5, 0.6, 0.7], $result[0]->vector->getData());
$this->assertSame(['category' => 'test'], $result[0]->metadata->getArrayCopy());
$this->assertSame(0.85, $result[0]->score);
Expand Down Expand Up @@ -176,12 +176,12 @@ public function testQueryHandlesMultipleResultsAndMultipleOptions()

$this->assertCount(2, $result);
$this->assertInstanceOf(VectorDocument::class, $result[0]);
$this->assertTrue($uuid1->equals($result[0]->id));
$this->assertSame($uuid1->toRfc4122(), $result[0]->id);
$this->assertSame([0.1, 0.2], $result[0]->vector->getData());
$this->assertSame(0.95, $result[0]->score);
$this->assertSame(['type' => 'first'], $result[0]->metadata->getArrayCopy());
$this->assertInstanceOf(VectorDocument::class, $result[1]);
$this->assertTrue($uuid2->equals($result[1]->id));
$this->assertSame($uuid2->toRfc4122(), $result[1]->id);
$this->assertSame([0.3, 0.4], $result[1]->vector->getData());
$this->assertSame(0.85, $result[1]->score);
$this->assertSame(['type' => 'second'], $result[1]->metadata->getArrayCopy());
Expand Down Expand Up @@ -209,7 +209,7 @@ public function testQueryParsesComplexMetadata()
$metadata = $document->metadata->getArrayCopy();
$this->assertCount(1, $result);
$this->assertInstanceOf(VectorDocument::class, $document);
$this->assertTrue($uuid->equals($document->id));
$this->assertSame($uuid->toRfc4122(), $document->id);
$this->assertSame([0.1, 0.2, 0.3, 0.4], $document->vector->getData());
$this->assertSame(0.92, $document->score);
$this->assertSame('Test Document', $metadata['title']);
Expand Down
3 changes: 1 addition & 2 deletions src/store/src/Bridge/SurrealDb/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Symfony\AI\Store\Exception\RuntimeException;
use Symfony\AI\Store\ManagedStoreInterface;
use Symfony\AI\Store\StoreInterface;
use Symfony\Component\Uid\Uuid;
use Symfony\Contracts\HttpClient\HttpClientInterface;

/**
Expand Down Expand Up @@ -149,7 +148,7 @@ private function convertToVectorDocument(array $data): VectorDocument
unset($data['_metadata']['_id']);

return new VectorDocument(
id: Uuid::fromString($id),
id: $id,
vector: $vector,
metadata: new Metadata($data['_metadata']),
);
Expand Down
4 changes: 2 additions & 2 deletions src/store/src/Bridge/Typesense/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private function request(string $method, string $endpoint, array $payload): arra
private function convertToIndexableArray(VectorDocument $document): array
{
return [
'id' => $document->id->toRfc4122(),
'id' => $document->id,
$this->vectorFieldName => $document->vector->getData(),
'metadata' => json_encode($document->metadata->getArrayCopy()),
];
Expand All @@ -136,6 +136,6 @@ private function convertToVectorDocument(array $data): VectorDocument

$score = $data['vector_distance'] ?? null;

return new VectorDocument(Uuid::fromString($id), $vector, new Metadata(json_decode($document['metadata'], true)), $score);
return new VectorDocument($id, $vector, new Metadata(json_decode($document['metadata'], true)), $score);
}
}
6 changes: 3 additions & 3 deletions src/store/src/Bridge/Weaviate/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ private function convertToIndexableArray(VectorDocument $document): array
{
return [
'class' => $this->collection,
'id' => $document->id->toRfc4122(),
'id' => $document->id,
'vector' => $document->vector->getData(),
'properties' => [
'uuid' => $document->id->toRfc4122(),
'uuid' => $document->id,
'vector' => $document->vector->getData(),
'_metadata' => json_encode($document->metadata->getArrayCopy()),
],
Expand All @@ -137,6 +137,6 @@ private function convertToVectorDocument(array $data): VectorDocument
? new NullVector()
: new Vector($data['vector']);

return new VectorDocument(Uuid::fromString($id), $vector, new Metadata(json_decode($data['_metadata'], true)));
return new VectorDocument($id, $vector, new Metadata(json_decode($data['_metadata'], true)));
}
}
4 changes: 2 additions & 2 deletions src/store/src/Document/TextDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
final class TextDocument implements EmbeddableDocumentInterface
{
public function __construct(
private readonly Uuid $id,
private readonly int|string|Uuid $id,
private readonly string $content,
private readonly Metadata $metadata = new Metadata(),
) {
Expand All @@ -34,7 +34,7 @@ public function withContent(string $content): self
return new self($this->id, $content, $this->metadata);
}

public function getId(): Uuid
public function getId(): int|string|Uuid
{
return $this->id;
}
Expand Down
2 changes: 1 addition & 1 deletion src/store/src/Document/VectorDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
final class VectorDocument
{
public function __construct(
public readonly Uuid $id,
public readonly int|string|Uuid $id,
public readonly VectorInterface $vector,
public readonly Metadata $metadata = new Metadata(),
public readonly ?float $score = null,
Expand Down
Loading
Loading