ragCreatePipeline static method
Create the RAG pipeline with the given configuration.
Marshals config to a native RacRagConfigStruct via FFI, calls
DartBridgeRAG.createPipeline, then publishes SDKRAGEvent.pipelineCreated.
Throws SDKError.notInitialized if SDK is not initialized. Throws SDKError.invalidState if pipeline creation fails.
Implementation
static Future<void> ragCreatePipeline(RAGConfiguration config) async {
if (!RunAnywhere.isSDKInitialized) {
throw SDKError.notInitialized();
}
if (!RAGModule.isRegistered) {
throw SDKError.invalidState(
'RAG backend not registered. Call RAGModule.register() first.',
);
}
final embeddingModelPathPtr = config.embeddingModelPath.toNativeUtf8();
final llmModelPathPtr = config.llmModelPath.toNativeUtf8();
final promptTemplatePtr = config.promptTemplate?.toNativeUtf8();
final embeddingConfigJsonPtr = config.embeddingConfigJSON?.toNativeUtf8();
final llmConfigJsonPtr = config.llmConfigJSON?.toNativeUtf8();
final configPtr = calloc<RacRagConfigStruct>();
try {
configPtr.ref.embeddingModelPath = embeddingModelPathPtr;
configPtr.ref.llmModelPath = llmModelPathPtr;
configPtr.ref.embeddingDimension = config.embeddingDimension;
configPtr.ref.topK = config.topK;
configPtr.ref.similarityThreshold = config.similarityThreshold;
configPtr.ref.maxContextTokens = config.maxContextTokens;
configPtr.ref.chunkSize = config.chunkSize;
configPtr.ref.chunkOverlap = config.chunkOverlap;
configPtr.ref.promptTemplate = promptTemplatePtr ?? nullptr;
configPtr.ref.embeddingConfigJson = embeddingConfigJsonPtr ?? nullptr;
configPtr.ref.llmConfigJson = llmConfigJsonPtr ?? nullptr;
DartBridgeRAG.shared.createPipeline(config: configPtr);
EventBus.shared.publish(SDKRAGEvent.pipelineCreated());
} catch (e) {
EventBus.shared.publish(SDKRAGEvent.error(message: e.toString()));
throw SDKError.invalidState('RAG pipeline creation failed: $e');
} finally {
calloc.free(embeddingModelPathPtr);
calloc.free(llmModelPathPtr);
if (promptTemplatePtr != null) calloc.free(promptTemplatePtr);
if (embeddingConfigJsonPtr != null) calloc.free(embeddingConfigJsonPtr);
if (llmConfigJsonPtr != null) calloc.free(llmConfigJsonPtr);
calloc.free(configPtr);
}
}