MobileRag class

Singleton facade for Mobile RAG Engine.

Use MobileRag.initialize to set up the engine, then access it via MobileRag.instance anywhere in your app.

Properties

dbPath String
Path to the SQLite database.
no setter
engine RagEngine
Access the underlying RagEngine for advanced operations.
no setter
hashCode int
The hash code for this object.
no setterinherited
isIndexReady bool
Whether all retrieval indexes are ready for full-quality search.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
vocabSize int
Vocabulary size of the loaded tokenizer.
no setter
warmupFuture Future<void>
Completes when BM25/HNSW warmup has finished.
no setter

Methods

addDocument(String content, {String? metadata, String? name, String? filePath, ChunkingStrategy? strategy, Duration? chunkDelay, void onProgress(int done, int total)?}) Future<SourceAddResult>
Add a document with automatic chunking and embedding.
clearAllData() Future<void>
Clear all data (database and index files) and reset the engine.
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.
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 document.
getSourceDocument(int sourceId) Future<String?>
Get the original source document content.
getStats() Future<SourceStats>
Get statistics about stored sources and chunks.
inCollection(String collectionId) CollectionRag
Get a collection-scoped facade.
listSources() 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() Future<void>
Rebuild the HNSW index.
removeSource(int sourceId) Future<void>
Remove a source and all its chunks.
saveIndex() 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 = 0.2, double bm25Weight = 0.8, List<int>? sourceIds}) Future<List<HybridSearchResult>>
Hybrid search combining vector and keyword (BM25) search.
searchHybridWithContext(String query, {int topK = 10, int tokenBudget = 2000, ContextStrategy strategy = ContextStrategy.relevanceFirst, int adjacentChunks = 0, double vectorWeight = 0.2, double bm25Weight = 0.8, bool singleSourceMode = false, List<int>? sourceIds}) Future<RagSearchResult>
Hybrid search with context assembly for LLM.
toString() String
A string representation of this object.
inherited
tryLoadCachedIndex() Future<bool>
Try to load a cached HNSW index.

Operators

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

Static Properties

instance MobileRag
Get the singleton instance.
no setter
isInitialized bool
Check if the engine is initialized.
no setter

Static Methods

dispose() Future<void>
Dispose of resources.
initialize({required String tokenizerAsset, required String modelAsset, String? databaseName, int maxChunkChars = 500, int overlapChars = 50, int? embeddingIntraOpNumThreads, ThreadUseLevel? threadLevel, bool deferIndexWarmup = false, void onProgress(String status)?}) Future<void>
Initialize the RAG engine. Call once in main().
setMockInstance(MobileRag? mock) → void
(FOR TESTING ONLY) Inject a custom instance for mocking.