Skip to content

Commit 23ffb63

Browse files
committed
feature #463 [Store] Add VectorizerInterface for better abstraction and testability (OskarStark)
This PR was merged into the main branch. Discussion ---------- [Store] Add `VectorizerInterface` for better abstraction and testability | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Docs? | no | Issues | -- | License | MIT Commits ------- cc82b0c Add VectorizerInterface and implement in existing Vectorizer
2 parents 38afc15 + cc82b0c commit 23ffb63

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/store/src/Document/Vectorizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* The Vectorizer encapsulates the logic to convert a collection of TextDocuments into VectorDocuments. It checks for
2020
* the model's capabilities to handle batch processing or handles it with HttpClient's concurrency feature.
2121
*/
22-
final readonly class Vectorizer
22+
final readonly class Vectorizer implements VectorizerInterface
2323
{
2424
public function __construct(
2525
private PlatformInterface $platform,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\AI\Store\Document;
13+
14+
/**
15+
* Interface for converting TextDocuments into VectorDocuments.
16+
*
17+
* @author Oskar Stark <[email protected]>
18+
*/
19+
interface VectorizerInterface
20+
{
21+
/**
22+
* @param TextDocument[] $documents
23+
*
24+
* @return VectorDocument[]
25+
*/
26+
public function vectorizeDocuments(array $documents): array;
27+
}

src/store/src/Indexer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Psr\Log\LoggerInterface;
1515
use Psr\Log\NullLogger;
1616
use Symfony\AI\Store\Document\TextDocument;
17-
use Symfony\AI\Store\Document\Vectorizer;
17+
use Symfony\AI\Store\Document\VectorizerInterface;
1818

1919
/**
2020
* Converts a collection of TextDocuments into VectorDocuments and pushes them to a store implementation.
@@ -24,7 +24,7 @@
2424
final readonly class Indexer
2525
{
2626
public function __construct(
27-
private Vectorizer $vectorizer,
27+
private VectorizerInterface $vectorizer,
2828
private StoreInterface $store,
2929
private LoggerInterface $logger = new NullLogger(),
3030
) {

0 commit comments

Comments
 (0)