1414use PHPUnit \Framework \Attributes \CoversClass ;
1515use PHPUnit \Framework \TestCase ;
1616use Symfony \AI \Agent \Toolbox \Tool \SimilaritySearch ;
17- use Symfony \AI \Platform \Model ;
18- use Symfony \AI \Platform \PlatformInterface ;
19- use Symfony \AI \Platform \Result \RawResultInterface ;
20- use Symfony \AI \Platform \Result \ResultPromise ;
21- use Symfony \AI \Platform \Result \VectorResult ;
2217use Symfony \AI \Platform \Vector \Vector ;
2318use Symfony \AI \Store \Document \Metadata ;
2419use Symfony \AI \Store \Document \VectorDocument ;
20+ use Symfony \AI \Store \Document \VectorizerInterface ;
2521use Symfony \AI \Store \StoreInterface ;
2622use Symfony \Component \Uid \Uuid ;
2723
@@ -44,27 +40,19 @@ public function testSearchWithResults()
4440 new Metadata (['title ' => 'Document 2 ' , 'content ' => 'Second document content ' ]),
4541 );
4642
47- $ rawResult = $ this ->createMock (RawResultInterface::class);
48- $ vectorResult = new VectorResult ($ vector );
49- $ resultPromise = new ResultPromise (
50- fn () => $ vectorResult ,
51- $ rawResult
52- );
53-
54- $ platform = $ this ->createMock (PlatformInterface::class);
55- $ platform ->expects ($ this ->once ())
56- ->method ('invoke ' )
57- ->with ($ this ->isInstanceOf (Model::class), $ searchTerm )
58- ->willReturn ($ resultPromise );
43+ $ vectorizer = $ this ->createMock (VectorizerInterface::class);
44+ $ vectorizer ->expects ($ this ->once ())
45+ ->method ('vectorize ' )
46+ ->with ($ searchTerm )
47+ ->willReturn ($ vector );
5948
6049 $ store = $ this ->createMock (StoreInterface::class);
6150 $ store ->expects ($ this ->once ())
6251 ->method ('query ' )
6352 ->with ($ vector )
6453 ->willReturn ([$ document1 , $ document2 ]);
6554
66- $ model = new Model ('test-model ' );
67- $ similaritySearch = new SimilaritySearch ($ platform , $ model , $ store );
55+ $ similaritySearch = new SimilaritySearch ($ vectorizer , $ store );
6856
6957 $ result = $ similaritySearch ($ searchTerm );
7058
@@ -77,27 +65,19 @@ public function testSearchWithoutResults()
7765 $ searchTerm = 'find nothing ' ;
7866 $ vector = new Vector ([0.1 , 0.2 , 0.3 ]);
7967
80- $ rawResult = $ this ->createMock (RawResultInterface::class);
81- $ vectorResult = new VectorResult ($ vector );
82- $ resultPromise = new ResultPromise (
83- fn () => $ vectorResult ,
84- $ rawResult
85- );
86-
87- $ platform = $ this ->createMock (PlatformInterface::class);
88- $ platform ->expects ($ this ->once ())
89- ->method ('invoke ' )
90- ->with ($ this ->isInstanceOf (Model::class), $ searchTerm )
91- ->willReturn ($ resultPromise );
68+ $ vectorizer = $ this ->createMock (VectorizerInterface::class);
69+ $ vectorizer ->expects ($ this ->once ())
70+ ->method ('vectorize ' )
71+ ->with ($ searchTerm )
72+ ->willReturn ($ vector );
9273
9374 $ store = $ this ->createMock (StoreInterface::class);
9475 $ store ->expects ($ this ->once ())
9576 ->method ('query ' )
9677 ->with ($ vector )
9778 ->willReturn ([]);
9879
99- $ model = new Model ('test-model ' );
100- $ similaritySearch = new SimilaritySearch ($ platform , $ model , $ store );
80+ $ similaritySearch = new SimilaritySearch ($ vectorizer , $ store );
10181
10282 $ result = $ similaritySearch ($ searchTerm );
10383
@@ -116,27 +96,19 @@ public function testSearchWithSingleResult()
11696 new Metadata (['title ' => 'Single Document ' , 'description ' => 'Only one match ' ]),
11797 );
11898
119- $ rawResult = $ this ->createMock (RawResultInterface::class);
120- $ vectorResult = new VectorResult ($ vector );
121- $ resultPromise = new ResultPromise (
122- fn () => $ vectorResult ,
123- $ rawResult
124- );
125-
126- $ platform = $ this ->createMock (PlatformInterface::class);
127- $ platform ->expects ($ this ->once ())
128- ->method ('invoke ' )
129- ->with ($ this ->isInstanceOf (Model::class), $ searchTerm )
130- ->willReturn ($ resultPromise );
99+ $ vectorizer = $ this ->createMock (VectorizerInterface::class);
100+ $ vectorizer ->expects ($ this ->once ())
101+ ->method ('vectorize ' )
102+ ->with ($ searchTerm )
103+ ->willReturn ($ vector );
131104
132105 $ store = $ this ->createMock (StoreInterface::class);
133106 $ store ->expects ($ this ->once ())
134107 ->method ('query ' )
135108 ->with ($ vector )
136109 ->willReturn ([$ document ]);
137110
138- $ model = new Model ('test-model ' );
139- $ similaritySearch = new SimilaritySearch ($ platform , $ model , $ store );
111+ $ similaritySearch = new SimilaritySearch ($ vectorizer , $ store );
140112
141113 $ result = $ similaritySearch ($ searchTerm );
142114
0 commit comments