File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed
src/agent/src/Bridge/SimilaritySearch Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 2323final class SimilaritySearch
2424{
2525 /**
26- * @var iterable< VectorDocument>
26+ * @var VectorDocument[]
2727 */
28- public iterable $ usedDocuments = [];
28+ public array $ usedDocuments = [];
2929
3030 public function __construct (
3131 private readonly VectorizerInterface $ vectorizer ,
@@ -39,17 +39,17 @@ public function __construct(
3939 public function __invoke (string $ searchTerm ): string
4040 {
4141 $ vector = $ this ->vectorizer ->vectorize ($ searchTerm );
42- $ this ->usedDocuments = $ this ->store ->query ($ vector );
42+ $ this ->usedDocuments = iterator_to_array ( $ this ->store ->query ($ vector) );
4343
44- $ result = '' ;
45- foreach ($ this ->usedDocuments as $ document ) {
46- $ result .= json_encode ($ document ->metadata );
44+ if ([] === $ this ->usedDocuments ) {
45+ return 'No results found ' ;
4746 }
4847
49- if ('' === $ result ) {
50- return 'No results found ' ;
48+ $ result = 'Found documents with following information: ' .\PHP_EOL ;
49+ foreach ($ this ->usedDocuments as $ document ) {
50+ $ result .= json_encode ($ document ->metadata );
5151 }
5252
53- return ' Found documents with following information: ' .\ PHP_EOL . $ result ;
53+ return $ result ;
5454 }
5555}
You can’t perform that action at this time.
0 commit comments