agentic_rag library

Retrieval-augmented generation for the agentic framework.

Documents in, cited answers out — with every stage of the pipeline replaceable.

import 'package:agentic_rag/agentic_rag.dart';

final indexer = RagIndexer(
  index: EmbeddingIndex(model: embeddings, store: store),
  chunker: const MarkdownChunker(),
);
await indexer.indexAll(documents);

final pipeline = RagPipeline(
  retriever: VectorRetriever(index: indexer.index),
  model: chatModel,
  reranker: const ScoreFloorReranker(minScore: 0.25),
);

final answer = await pipeline.answer('How do refunds work?');
print(answer.text);                 // "... refunds take 5 days [2]."
print(answer.citations.first.label); // "[2] Handbook › Refunds"

Each stage is a port: Chunker, Retriever, Reranker, DocumentLoader. Replacing one is a class in your own package, and nothing here needs to change.

Classes

AnswerGenerated
An answer was generated from retrieved passages.
BaseChunker
Shared machinery for chunkers.
ChainedReranker
Runs several re-rankers in order.
Chunker
Splits a document into chunks.
ChunkOptions
How a document is split.
ChunkPiece
A piece of text produced by a chunker, before it becomes a chunk.
ChunksReranked
A re-ranking step ran.
ChunksRetrieved
Retrieval ran.
Citation
A reference an answer can point at.
CompositeDocumentLoader
Runs several loaders as one.
DocumentChunk
One retrievable piece of a document.
DocumentLoader
Converts source material into documents.
DocumentsIndexed
An ingestion run finished.
FixedSizeChunker
Splits at a fixed width, ignoring structure.
HtmlDocumentLoader
Loads HTML by reducing it to readable text.
HybridRetriever
Runs several retrievers and fuses their rankings.
IndexingReport
What one ingestion run did.
InMemoryKeywordIndex
An in-process BM25 index over chunks.
KeywordRetriever
Retrieves passages by term overlap.
LlmReranker
Scores candidates by having a model read them against the question.
MarkdownChunker
Splits Markdown at headings, keeping the heading path with each chunk.
MarkdownDocumentLoader
Loads Markdown, lifting the title and YAML front matter into metadata.
MmrReranker
Trades relevance against variety.
NeighbourExpandingRetriever
Adds context around whatever another retriever found.
RagAnswer
An answer and what it was built from.
RagContext
The passages selected for a question, ready to put in a prompt.
RagDocument
A source document, before it is chunked.
RagEvent
Base for every retrieval event.
RagIndexer
Chunks documents, embeds them and writes them to an index.
RagPipeline
Runs the retrieval half of a question end to end.
RecursiveChunker
Splits text by trying progressively weaker separators.
Reranker
Reorders and trims retrieval results.
RetrievalRequest
A retrieval request.
RetrievedChunk
A chunk that came back from retrieval, and why.
Retriever
Finds the passages most relevant to a question.
ScoreFloorReranker
Keeps only what clears a bar, and at most so many.
TextDocumentLoader
Loads documents that are already in hand as text.
TextSource
One text and what is known about it.
VectorRetriever
Retrieves passages by embedding similarity.

Extensions

ChunkerOperations on Chunker
Conveniences available on every Chunker.
RetrieverOperations on Retriever
Conveniences available on every Retriever.

Constants

kChunkIndexKey → const String
Metadata key holding the chunk's position within its document.
kContentHashKey → const String
Metadata key holding the source document's content fingerprint.
kDocumentIdKey → const String
Metadata key holding the source document's identifier.
kHeadingKey → const String
Metadata key holding the heading a chunk sits under.
kReservedMetadataKeys → const Set<String>
Every key this package reserves.
kSourceKey → const String
Metadata key holding where the document came from.
kStartOffsetKey → const String
Metadata key holding the chunk's character offset in its document.
kTitleKey → const String
Metadata key holding the document title.

Functions

answeringTool({required RagPipeline pipeline, String name = 'ask_documents', String corpus = 'the indexed documents', MetadataFilter? filter, String? namespace}) → Tool
Builds a tool that answers from a corpus in one step.
chunkFromRecord(VectorRecord record) DocumentChunk?
Reconstructs a chunk from a stored record.
chunkMetadata(DocumentChunk chunk, {String? contentHash}) → JsonMap
Builds the metadata a chunk is stored with.
documentFilter(String documentId) → MetadataFilter
A filter matching every chunk of documentId.
formatSourceLabel(String name, String? heading) String
Joins a document name and a heading path into one readable label.
searchTool({required Retriever retriever, String name = 'search_documents', String corpus = 'the indexed documents', int topK = 5, int maxPassageChars = 800, double minScore = 0, MetadataFilter? filter, String? namespace}) → Tool
Builds a tool that searches a corpus.
staleTailFilter(String documentId, int index) → MetadataFilter
A filter matching chunks of documentId at or beyond index.
userMetadata(JsonMap metadata) → JsonMap
Strips this package's reserved keys from metadata.