44
55namespace PhpLlm \LlmChain \Store \Azure ;
66
7- use PhpLlm \LlmChain \Document \Document ;
87use PhpLlm \LlmChain \Document \Metadata ;
98use PhpLlm \LlmChain \Document \Vector ;
9+ use PhpLlm \LlmChain \Document \VectorDocument ;
1010use PhpLlm \LlmChain \Store \VectorStoreInterface ;
1111use Symfony \Component \Uid \Uuid ;
1212use Symfony \Contracts \HttpClient \HttpClientInterface ;
@@ -26,28 +26,20 @@ public function __construct(
2626 ) {
2727 }
2828
29- public function addDocument (Document $ document ): void
30- {
31- $ this ->addDocuments ([$ document ]);
32- }
33-
34- public function addDocuments (array $ documents ): void
29+ public function add (VectorDocument ...$ documents ): void
3530 {
3631 $ this ->request ('index ' , [
37- 'value ' => array_map ([$ this , 'convertDocumentToIndexableArray ' ], $ documents ),
32+ 'value ' => array_map ([$ this , 'convertToIndexableArray ' ], $ documents ),
3833 ]);
3934 }
4035
41- /**
42- * @return list<Document>
43- */
4436 public function query (Vector $ vector , array $ options = []): array
4537 {
4638 $ result = $ this ->request ('search ' , [
4739 'vectorQueries ' => [$ this ->buildVectorQuery ($ vector )],
4840 ]);
4941
50- return array_map ([$ this , 'convertArrayToDocument ' ], $ result ['value ' ]);
42+ return array_map ([$ this , 'convertToVectorDocument ' ], $ result ['value ' ]);
5143 }
5244
5345 /**
@@ -73,7 +65,7 @@ private function request(string $endpoint, array $payload): array
7365 /**
7466 * @return array<string, mixed>
7567 */
76- private function convertDocumentToIndexableArray ( Document $ document ): array
68+ private function convertToIndexableArray ( VectorDocument $ document ): array
7769 {
7870 return array_merge ([
7971 'id ' => $ document ->id ,
@@ -84,12 +76,11 @@ private function convertDocumentToIndexableArray(Document $document): array
8476 /**
8577 * @param array<string, mixed> $data
8678 */
87- private function convertArrayToDocument (array $ data ): Document
79+ private function convertToVectorDocument (array $ data ): VectorDocument
8880 {
89- return new Document (
81+ return new VectorDocument (
9082 id: Uuid::fromString ($ data ['id ' ]),
91- text: null ,
92- vector: null ,
83+ vector: $ data [$ this ->vectorFieldName ] ? new Vector ($ data [$ this ->vectorFieldName ]) : null ,
9384 metadata: new Metadata ($ data ),
9485 );
9586 }
0 commit comments