addDocument method
Add document to vector store (will compute embedding automatically).
Implementation
@override
Future<void> addDocument({
required String id,
required String content,
String? metadata,
}) async {
// Generate embedding for content first
if (initializedEmbeddingModel == null) {
throw StateError(
'No embedding model is active. addDocument(content:) and '
'searchSimilar(query:) auto-embed text, which requires an embedding '
'model. Install and activate one with FlutterGemma.installEmbedder(...) '
'(or modelManager.setActiveModel) before calling these methods — or '
'pass a precomputed vector to addDocumentWithEmbedding(embedding:).',
);
}
final embedding = await initializedEmbeddingModel!.generateEmbedding(
content,
taskType: TaskType.retrievalDocument,
);
// Add document with computed embedding
await addDocumentWithEmbedding(
id: id,
content: content,
embedding: embedding,
metadata: metadata,
);
}