RagEngine class
Unified RAG engine with simplified initialization.
Wraps SourceRagService with automatic dependency initialization.
Properties
- dbPath → String
-
Path to the SQLite database.
final
- 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
- 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.
-
clearAllData(
) → Future< void> - Clear all data (database and index files) and reset the engine.
-
collectionWarmupFuture(
String collectionId) → Future< void> - Completes when a specific collection warmup/rebuild task has finished.
-
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.
-
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.
-
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.
-
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(
String query, {int topK = 10, int tokenBudget = 2000, ContextStrategy strategy = ContextStrategy.relevanceFirst, int adjacentChunks = 0, bool singleSourceMode = false, List< int> ? sourceIds, String? collectionId}) → Future<RagSearchResult> - 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, 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 = 0.2, double bm25Weight = 0.8, List< int> ? sourceIds, int adjacentChunks = 0, bool singleSourceMode = false, String? collectionId}) → Future<RagSearchResult> - Hybrid search with context assembly for LLM.
-
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