RagPipeline class
Ingests documents into a DocumentStore and answers questions from them.
final kb = await AsyncPhoenixCollection.open('kb', dimensions: 1024);
final rag = RagPipeline(
store: kb,
embedder: OpenAICompatibleEmbedder.voyage(
apiKey: voyageKey, model: 'voyage-3.5', dimensions: 1024),
chat: AnthropicChatModel(apiKey: anthropicKey),
);
await rag.ingest(RagDocument('handbook', handbookText));
final answer = await rag.ask('How many vacation days do I get?');
print(answer.text);
for (final c in answer.citations) print('[${c.number}] ${c.documentId}');
Retrieval is hybrid by default — embeddings and BM25 keywords fused with RRF — which is markedly more robust than either alone for names, codes and rare terms; MMR then removes near-duplicate chunks.
Constructors
- RagPipeline({required DocumentStore store, required Embedder embedder, required ChatModel chat, TextChunker? chunker, int k = 6, bool hybrid = true, double? mmr = 0.7, String systemPrompt = defaultSystemPrompt, int maxContextChars = 24000})
-
Creates a pipeline.
embeddermust produce vectors of the store's dimensionality.
Properties
- chat → ChatModel
-
Writes the answers.
final
- chunker → TextChunker
-
Splits documents into chunks.
final
- embedder → Embedder
-
Embeds chunks and questions.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- hybrid → bool
-
Fuse keyword (BM25) retrieval with vector retrieval.
final
- k → int
-
Chunks retrieved per question.
final
- maxContextChars → int
-
Most source characters placed in one prompt; lower-ranked sources
beyond it are left out whole rather than cut mid-text.
final
- mmr → double?
-
MMR diversity for retrieval, or
nullfor plain relevance.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- store → DocumentStore
-
Where chunks live.
final
- systemPrompt → String
-
Instructions for the model.
final
Methods
-
ask(
String question, {int? k, Filter? filter, List< ChatMessage> history = const [], int? maxTokens}) → Future<RagAnswer> -
Answers
questionfrom the most relevant chunks. -
askStream(
String question, {int? k, Filter? filter, List< ChatMessage> history = const [], int? maxTokens}) → Future<RagStream> - Like ask, streaming the answer; the sources are known up front.
-
buildMessages(
String question, List< RagSource> sources, {List<ChatMessage> history = const [], List<RagSource> ? included}) → List<ChatMessage> -
The prompt for
questionoversources, afterhistory. -
ingest(
RagDocument document) → Future< int> - Ingests one document; returns its chunk count.
-
ingestAll(
Iterable< RagDocument> documents) → Future<int> - Ingests documents (embedding all their chunks in batched calls) and returns the total chunk count. Re-ingesting a document replaces it: new chunks are written first, then stale ones removed, so the document never disappears in between.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remove(
String documentId) → Future< int> - Removes a document's chunks; returns how many were removed.
-
retrieve(
String question, {int? k, Filter? filter}) → Future< List< RagSource> > -
The chunks most relevant to
question. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- defaultSystemPrompt → const String
- Default systemPrompt.