14
14
use PHPUnit \Framework \Attributes \CoversClass ;
15
15
use PHPUnit \Framework \TestCase ;
16
16
use 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 ;
22
17
use Symfony \AI \Platform \Vector \Vector ;
23
18
use Symfony \AI \Store \Document \Metadata ;
24
19
use Symfony \AI \Store \Document \VectorDocument ;
20
+ use Symfony \AI \Store \Document \VectorizerInterface ;
25
21
use Symfony \AI \Store \StoreInterface ;
26
22
use Symfony \Component \Uid \Uuid ;
27
23
@@ -44,27 +40,19 @@ public function testSearchWithResults()
44
40
new Metadata (['title ' => 'Document 2 ' , 'content ' => 'Second document content ' ]),
45
41
);
46
42
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 );
59
48
60
49
$ store = $ this ->createMock (StoreInterface::class);
61
50
$ store ->expects ($ this ->once ())
62
51
->method ('query ' )
63
52
->with ($ vector )
64
53
->willReturn ([$ document1 , $ document2 ]);
65
54
66
- $ model = new Model ('test-model ' );
67
- $ similaritySearch = new SimilaritySearch ($ platform , $ model , $ store );
55
+ $ similaritySearch = new SimilaritySearch ($ vectorizer , $ store );
68
56
69
57
$ result = $ similaritySearch ($ searchTerm );
70
58
@@ -77,27 +65,19 @@ public function testSearchWithoutResults()
77
65
$ searchTerm = 'find nothing ' ;
78
66
$ vector = new Vector ([0.1 , 0.2 , 0.3 ]);
79
67
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 );
92
73
93
74
$ store = $ this ->createMock (StoreInterface::class);
94
75
$ store ->expects ($ this ->once ())
95
76
->method ('query ' )
96
77
->with ($ vector )
97
78
->willReturn ([]);
98
79
99
- $ model = new Model ('test-model ' );
100
- $ similaritySearch = new SimilaritySearch ($ platform , $ model , $ store );
80
+ $ similaritySearch = new SimilaritySearch ($ vectorizer , $ store );
101
81
102
82
$ result = $ similaritySearch ($ searchTerm );
103
83
@@ -116,27 +96,19 @@ public function testSearchWithSingleResult()
116
96
new Metadata (['title ' => 'Single Document ' , 'description ' => 'Only one match ' ]),
117
97
);
118
98
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 );
131
104
132
105
$ store = $ this ->createMock (StoreInterface::class);
133
106
$ store ->expects ($ this ->once ())
134
107
->method ('query ' )
135
108
->with ($ vector )
136
109
->willReturn ([$ document ]);
137
110
138
- $ model = new Model ('test-model ' );
139
- $ similaritySearch = new SimilaritySearch ($ platform , $ model , $ store );
111
+ $ similaritySearch = new SimilaritySearch ($ vectorizer , $ store );
140
112
141
113
$ result = $ similaritySearch ($ searchTerm );
142
114
0 commit comments