@@ -32,12 +32,12 @@ final public function __construct(string $table = '')
32
32
*
33
33
* @param array<string, mixed> $data The document data.
34
34
* @param array<float> $embedding The embedding vector.
35
- * @param string $embeddingColumn The embedding column name.
35
+ * @param string|null $embeddingColumn The embedding column name.
36
36
* @return PromiseInterface<int> A promise that resolves to the number of affected rows.
37
37
*/
38
38
public function insertWithEmbedding (array $ data , array $ embedding , ?string $ embeddingColumn = null ): PromiseInterface
39
39
{
40
- $ embeddingColumn = $ embeddingColumn ?? $ this ->ragConfig ['default_vector_column ' ];
40
+ $ embeddingColumn ??= $ this ->ragConfig ['default_vector_column ' ];
41
41
42
42
if (empty ($ embedding )) {
43
43
return Promise::resolve (0 );
@@ -52,17 +52,17 @@ public function insertWithEmbedding(array $data, array $embedding, ?string $embe
52
52
*
53
53
* @param array<string, mixed> $data The document data.
54
54
* @param array<float> $embedding The embedding vector.
55
- * @param string $embeddingColumn The embedding column name.
56
55
* @param string $idColumn The ID column name.
56
+ * @param string|null $embeddingColumn The embedding column name.
57
57
* @return PromiseInterface<mixed> A promise that resolves to the inserted ID.
58
58
*/
59
59
public function insertWithEmbeddingGetId (
60
60
array $ data ,
61
61
array $ embedding ,
62
- ? string $ embeddingColumn = null ,
63
- string $ idColumn = ' id '
62
+ string $ idColumn = ' id ' ,
63
+ ? string $ embeddingColumn = null
64
64
): PromiseInterface {
65
- $ embeddingColumn = $ embeddingColumn ?? $ this ->ragConfig ['default_vector_column ' ];
65
+ $ embeddingColumn ??= $ this ->ragConfig ['default_vector_column ' ];
66
66
67
67
if (empty ($ embedding )) {
68
68
return Promise::resolve (null );
@@ -76,12 +76,12 @@ public function insertWithEmbeddingGetId(
76
76
* Batch insert documents with embeddings.
77
77
*
78
78
* @param array<array{data: array<string, mixed>, embedding: array<float>}> $documents Documents with embeddings.
79
- * @param string $embeddingColumn The embedding column name.
79
+ * @param string|null $embeddingColumn The embedding column name.
80
80
* @return PromiseInterface<int> A promise that resolves to the number of affected rows.
81
81
*/
82
82
public function insertBatchWithEmbeddings (array $ documents , ?string $ embeddingColumn = null ): PromiseInterface
83
83
{
84
- $ embeddingColumn = $ embeddingColumn ?? $ this ->ragConfig ['default_vector_column ' ];
84
+ $ embeddingColumn ??= $ this ->ragConfig ['default_vector_column ' ];
85
85
86
86
if (empty ($ documents )) {
87
87
return Promise::resolve (0 );
@@ -107,19 +107,22 @@ public function insertBatchWithEmbeddings(array $documents, ?string $embeddingCo
107
107
*
108
108
* @param array<float> $queryVector The query vector.
109
109
* @param array<string, mixed> $filters Additional filters.
110
- * @param string $vectorColumn The vector column name.
111
- * @param float $threshold Similarity threshold.
112
- * @param int $limit Number of results to return.
110
+ * @param string|null $vectorColumn The vector column name.
111
+ * @param string|null $metadataColumn The metadata column name.
112
+ * @param float|null $threshold Similarity threshold.
113
+ * @param int|null $limit Number of results to return.
113
114
* @return PromiseInterface<array<int, array<string, mixed>>> A promise that resolves to search results.
114
115
*/
115
116
public function performSemanticSearch (
116
117
array $ queryVector ,
117
118
array $ filters = [],
118
119
?string $ vectorColumn = null ,
120
+ ?string $ metadataColumn = null ,
119
121
?float $ threshold = null ,
120
122
?int $ limit = null
121
123
): PromiseInterface {
122
- $ query = $ this ->semanticSearch ($ queryVector , $ filters , $ vectorColumn , $ this ->ragConfig ['default_metadata_column ' ], $ threshold , $ limit );
124
+ $ metadataColumn ??= $ this ->ragConfig ['default_metadata_column ' ];
125
+ $ query = $ this ->semanticSearch ($ queryVector , $ filters , $ vectorColumn , $ metadataColumn , $ threshold , $ limit );
123
126
return $ query ->get ();
124
127
}
125
128
@@ -132,21 +135,21 @@ public function performSemanticSearch(
132
135
* @param string $vectorColumn The vector column name.
133
136
* @param float $textWeight Weight for text search.
134
137
* @param float $vectorWeight Weight for vector search.
135
- * @param int $limit Number of results to return.
138
+ * @param int|null $limit Number of results to return.
136
139
* @return PromiseInterface<array<int, array<string, mixed>>> A promise that resolves to search results.
137
140
*/
138
141
public function performHybridSearch (
139
142
string $ textQuery ,
140
143
array $ queryVector ,
141
- ? string $ textColumn = null ,
142
- ? string $ vectorColumn = null ,
144
+ string $ textColumn ,
145
+ string $ vectorColumn ,
143
146
float $ textWeight = 0.3 ,
144
147
float $ vectorWeight = 0.7 ,
145
148
?int $ limit = null
146
149
): PromiseInterface {
147
- $ textColumn = $ textColumn ?? $ this ->ragConfig ['default_content_column ' ];
148
- $ vectorColumn = $ vectorColumn ?? $ this ->ragConfig ['default_vector_column ' ];
149
- $ limit = $ limit ?? $ this ->ragConfig ['default_search_limit ' ];
150
+ $ textColumn ??= $ this ->ragConfig ['default_content_column ' ];
151
+ $ vectorColumn ??= $ this ->ragConfig ['default_vector_column ' ];
152
+ $ limit ??= $ this ->ragConfig ['default_search_limit ' ];
150
153
151
154
$ query = $ this ->hybridSearch ($ textColumn , $ vectorColumn , $ textQuery , $ queryVector , $ textWeight , $ vectorWeight , $ limit );
152
155
return $ query ->get ();
@@ -158,7 +161,7 @@ public function performHybridSearch(
158
161
* @param array<float> $queryVector The query vector.
159
162
* @param array<string, mixed> $filters Additional filters.
160
163
* @param int $topK Number of results to return.
161
- * @param float $threshold Similarity threshold.
164
+ * @param float|null $threshold Similarity threshold.
162
165
* @return PromiseInterface<array<int, array<string, mixed>>> A promise that resolves to context with citations.
163
166
*/
164
167
public function retrieveContextForRAG (
@@ -167,7 +170,7 @@ public function retrieveContextForRAG(
167
170
int $ topK = 5 ,
168
171
?float $ threshold = null
169
172
): PromiseInterface {
170
- $ threshold = $ threshold ?? $ this ->ragConfig ['default_similarity_threshold ' ];
173
+ $ threshold ??= $ this ->ragConfig ['default_similarity_threshold ' ];
171
174
172
175
$ query = $ this ->retrievalWithCitation ($ queryVector , ['title ' , 'source ' , 'url ' , 'author ' , 'created_at ' ], null , $ topK )
173
176
->semanticSearch ($ queryVector , $ filters , null , null , $ threshold , $ topK );
@@ -185,12 +188,12 @@ public function retrieveContextForRAG(
185
188
* @return PromiseInterface<int> A promise that resolves when index is created.
186
189
*/
187
190
public function createVectorIndex (
188
- ?string $ column = null ,
189
191
string $ method = 'hnsw ' ,
190
192
string $ operator = 'vector_cosine_ops ' ,
191
- array $ options = ['m ' => 16 , 'ef_construction ' => 64 ]
193
+ array $ options = ['m ' => 16 , 'ef_construction ' => 64 ],
194
+ ?string $ column = null ,
192
195
): PromiseInterface {
193
- $ column = $ column ?? $ this ->ragConfig ['default_vector_column ' ];
196
+ $ column ??= $ this ->ragConfig ['default_vector_column ' ];
194
197
$ sql = $ this ->buildVectorIndexQuery ($ column , $ method , $ operator , $ options );
195
198
return AsyncPostgreSQL::execute ($ sql , []);
196
199
}
@@ -204,11 +207,11 @@ public function createVectorIndex(
204
207
* @return PromiseInterface<array<int, array<string, mixed>>> A promise that resolves to document chunks.
205
208
*/
206
209
public function chunkDocuments (
207
- ?string $ contentColumn = null ,
208
210
int $ chunkSize = 1000 ,
209
- int $ overlapSize = 200
211
+ int $ overlapSize = 200 ,
212
+ ?string $ contentColumn = null ,
210
213
): PromiseInterface {
211
- $ contentColumn = $ contentColumn ?? $ this ->ragConfig ['default_content_column ' ];
214
+ $ contentColumn ??= $ this ->ragConfig ['default_content_column ' ];
212
215
$ sql = $ this ->buildChunkQuery ($ contentColumn , $ chunkSize , $ overlapSize );
213
216
return AsyncPostgreSQL::query ($ sql , []);
214
217
}
@@ -218,17 +221,17 @@ public function chunkDocuments(
218
221
*
219
222
* @param mixed $id The document ID.
220
223
* @param array<float> $embedding The new embedding vector.
221
- * @param string $embeddingColumn The embedding column name.
222
224
* @param string $idColumn The ID column name.
225
+ * @param string|null $embeddingColumn The embedding column name.
223
226
* @return PromiseInterface<int> A promise that resolves to the number of affected rows.
224
227
*/
225
228
public function updateEmbedding (
226
229
mixed $ id ,
227
230
array $ embedding ,
228
- ? string $ embeddingColumn = null ,
229
- string $ idColumn = ' id '
231
+ string $ idColumn = ' id ' ,
232
+ ? string $ embeddingColumn = null
230
233
): PromiseInterface {
231
- $ embeddingColumn = $ embeddingColumn ?? $ this ->ragConfig ['default_vector_column ' ];
234
+ $ embeddingColumn ??= $ this ->ragConfig ['default_vector_column ' ];
232
235
233
236
if (empty ($ embedding )) {
234
237
return Promise::resolve (0 );
@@ -246,7 +249,7 @@ public function updateEmbedding(
246
249
*/
247
250
public function getVectorStatistics (?string $ vectorColumn = null ): PromiseInterface
248
251
{
249
- $ vectorColumn = $ vectorColumn ?? $ this ->ragConfig ['default_vector_column ' ];
252
+ $ vectorColumn ??= $ this ->ragConfig ['default_vector_column ' ];
250
253
251
254
// @phpstan-ignore-next-line
252
255
return Async::async (function () use ($ vectorColumn ): array {
@@ -282,7 +285,7 @@ public function analyzeVectorPerformance(
282
285
array $ sampleVector ,
283
286
?string $ vectorColumn = null
284
287
): PromiseInterface {
285
- $ vectorColumn = $ vectorColumn ?? $ this ->ragConfig ['default_vector_column ' ];
288
+ $ vectorColumn ??= $ this ->ragConfig ['default_vector_column ' ];
286
289
287
290
// @phpstan-ignore-next-line
288
291
return Async::async (function () use ($ sampleVector , $ vectorColumn ): array {
0 commit comments