embedText method
Queue an embedding job for a record on this collection. The server's embedding worker picks it up within ~1 second, calls the configured provider, and writes the resulting vector to the record.
If text is omitted, the value of the vector field's configured
source_field on the record is used. Pass text explicitly for
backfills, A/B comparisons, or when you want to embed something other
than the record's source field.
// Re-embed using the record's content field (the configured source):
await Koolbase.db.collection('articles').embedText(
recordId: article.id,
vectorField: 'content_embedding',
);
// Embed a custom string for this record:
await Koolbase.db.collection('articles').embedText(
recordId: article.id,
vectorField: 'content_embedding',
text: '${article.title}\n\n${article.summary}',
);
Returns when the job is queued — not when the vector lands. Poll the vector via KoolbaseDocRef.getVector if you need to wait for it.
Implementation
Future<void> embedText({
required String recordId,
required String vectorField,
String? text,
}) async {
final body = <String, dynamic>{
'collection': collectionName,
'record_id': recordId,
'vector_field': vectorField,
if (text != null && text.isNotEmpty) 'text': text,
};
final res = await _client
.post(
Uri.parse('$baseUrl/v1/sdk/db/embed-text'),
headers: await _headers(),
body: jsonEncode(body),
)
.timeout(const Duration(seconds: 10));
if (res.statusCode != 200) {
throw await koolbaseDataErrorNotifying(res,
onSessionExpired: _onSessionExpired,
fallbackMessage: 'embedText failed');
}
}