SourceRagService class

High-level service for source-based RAG operations.

Constructors

SourceRagService({required String dbPath, int maxChunkChars = 500, int overlapChars = 50})

Properties

dbPath String
final
hashCode int
The hash code for this object.
no setterinherited
maxChunkChars int
Maximum characters per chunk (default: 500)
final
overlapChars int
Overlap characters between chunks for context continuity
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addSourceWithChunking(String content, {String? metadata, void onProgress(int done, int total)?}) Future<SourceAddResult>
Add a source document with automatic chunking and embedding.
formatPrompt(String query, RagSearchResult result) String
Format search results as an LLM prompt.
getSourceForChunk(ChunkSearchResult chunk) Future<String?>
Get the original source document for a chunk.
getStats() Future<SourceStats>
Get statistics about stored sources and chunks.
init() Future<void>
Initialize the source database.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
rebuildIndex() Future<void>
Rebuild the HNSW index after adding sources.
regenerateAllEmbeddings({void onProgress(int done, int total)?}) Future<void>
Regenerate embeddings for all existing chunks using the current model. This is needed when the embedding model or tokenizer has been updated.
saveIndex() Future<void>
Save HNSW index marker to disk.
Search for relevant chunks and assemble context for LLM.
searchHybrid(String query, {int topK = 10, double vectorWeight = 0.5, double bm25Weight = 0.5}) 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.5, double bm25Weight = 0.5}) Future<RagSearchResult>
Hybrid search with context assembly for LLM.
toString() String
A string representation of this object.
inherited
tryLoadCachedIndex() Future<bool>
Try to load cached HNSW index.

Operators

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