RagEngine class

Unified RAG engine with simplified initialization.

Wraps SourceRagService with automatic dependency initialization.

Properties

currentEmbeddingFingerprint → String
Fingerprint of the currently loaded embedding model. Captured during initialize via a one-shot probe embed.
final
dbPath → String
Path to the SQLite database.
final
embeddingFingerprintLock → RagEmbeddingFingerprintLock?
Snapshot of the active embedding fingerprint lock (null when unlocked).
no setter
hashCode → int
The hash code for this object.
no setterinherited
isEmbeddingFingerprintLocked → bool
Whether boot detected an embedding fingerprint mismatch.
no setter
isIndexReady → bool
Whether all retrieval indexes are ready for full-quality search.
no setter
migrationState → Future<MigrationAxes>
Read-only snapshot of all on-device data migration axes.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
service → SourceRagService
Access to the underlying SourceRagService for advanced operations.
no setter
vocabSize → int
Vocabulary size of the loaded tokenizer.
final
warmupFuture → Future<void>
Completes when the latest index warmup/rebuild task has finished.
no setter

Methods

addDocument(String content, {String? metadata, String? name, String? filePath, ChunkingStrategy? strategy, Duration? chunkDelay, void onProgress(int done, int total)?, String? collectionId}) → Future<SourceAddResult>
Add a document with automatic chunking and embedding.
addDocumentFromFile(String filePath, {String? metadata, String? name, ChunkingStrategy? strategy, Duration? chunkDelay, void onProgress(int done, int total)?, String? collectionId}) → Future<SourceAddResult>
Add a document from a file path using a Rust-side ingest fast path.
addDocumentUtf8(Uint8List bytes, {String? metadata, String? name, ChunkingStrategy? strategy, Duration? chunkDelay, void onProgress(int done, int total)?, String? collectionId}) → Future<SourceAddResult>
Add a UTF-8 document payload while reducing input-side Dart String materialization.
assembleContext({required SearchHandle searchHandle, int tokenBudget = 2000, ContextStrategy strategy = ContextStrategy.relevanceFirst, String separator = '\n\n---\n\n', bool singleSourceMode = false, String? collectionId}) → Future<AssembledContextV2>
clearAllData() → Future<void>
Clear all data (database and index files) and reset the engine.
clearAndRestart({required ClearAndRestartConfirmation confirm}) → Future<void>
Resolve an embeddingFingerprintLock by discarding every on-device embedding (chunks table) and rotating the fingerprint baseline.
collectionWarmupFuture(String collectionId) → Future<void>
Completes when a specific collection warmup/rebuild task has finished.
deriveContextBudgetForPromptV2({required int fullPromptBudget, required String query, String? systemInstruction, bool useStrictMode = true, int safetyMarginTokens = 0, int? fixedPromptOverheadTokens, String? collectionId}) → Future<int>
formatPrompt(String query, RagSearchResult result) → String
Format search results as an LLM prompt.
getAdjacentChunks({required int sourceId, required int minIndex, required int maxIndex}) → Future<List<ChunkSearchResult>>
Get adjacent chunks around a given chunk range.
getChunkExcerpts({required SearchHandle searchHandle, required List<int> chunkIds, required int maxBytes, String? collectionId}) → Future<List<ChunkExcerptResult>>
getSourceChunkCount(int sourceId) → Future<int>
Get the number of chunks for a specific source.
getSourceChunks(int sourceId) → Future<List<String>>
Get all chunk texts for a specific source.
getSourceDocument(int sourceId) → Future<String?>
Get the original source document content by ID.
getStats({String? collectionId}) → Future<SourceStats>
Get statistics about stored sources and chunks.
hydrateChunks({required SearchHandle searchHandle, required List<int> chunkIds, String? collectionId}) → Future<List<ChunkSearchResult>>
isCollectionIndexReady(String collectionId) → bool
Whether a specific collection index is ready for full-quality search.
listSources({String? collectionId}) → Future<List<SourceEntry>>
Get a list of all stored sources.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
rebuildIndex({bool force = false, String? collectionId}) → Future<void>
Rebuild the HNSW index after adding documents.
reembedAll({void onProgress(RagReembedProgress progress)?, int batchSize = 32}) → Future<void>
Resolve an embeddingFingerprintLock by re-embedding every chunk with the currently loaded model.
reembedRemaining() → Future<int>
Up-to-date count of chunks still tagged with a non-current fingerprint.
regenerateAllEmbeddings({void onProgress(int done, int total)?, String? collectionId}) → Future<void>
Regenerate embeddings for all existing chunks.
removeSource(int sourceId, {String? collectionId}) → Future<void>
Remove a source and all its chunks from the database.
saveIndex({String? collectionId}) → Future<void>
Save the HNSW index marker to disk.
Search for relevant chunks and assemble context for LLM.
searchHybrid(String query, {int topK = 10, double vectorWeight = kDefaultVectorWeight, double bm25Weight = kDefaultBm25Weight, List<int>? sourceIds, String? collectionId}) → Future<List<HybridSearchResult>>
Hybrid search combining vector and keyword (BM25) search.
searchHybridWithContext(String query, {int topK = 10, int tokenBudget = 2000, ContextStrategy strategy = ContextStrategy.relevanceFirst, double vectorWeight = kDefaultVectorWeight, double bm25Weight = kDefaultBm25Weight, List<int>? sourceIds, int adjacentChunks = 0, bool singleSourceMode = false, SearchHydrationMode hydrationMode = SearchHydrationMode.full, int previewMaxBytes = 512, String? collectionId}) → Future<RagSearchResult>
Hybrid search with context assembly for LLM.
searchMeta(String query, {int topK = 10, double vectorWeight = kDefaultVectorWeight, double bm25Weight = kDefaultBm25Weight, List<int>? sourceIds, int adjacentChunks = 0, String? collectionId}) → Future<SearchMetaResult>
Additive metadata-first low-level search lane.
toString() → String
A string representation of this object.
inherited
tryLoadCachedIndex({String? collectionId}) → Future<bool>
Try to load a cached HNSW index from disk.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

dispose() → Future<void>
Dispose of resources.
initialize({required RagConfig config, void onProgress(String status)?}) → Future<RagEngine>
Initialize RagEngine with all dependencies.