akashi_rag library

Retrieval-augmented generation for Akashi.

One Retriever contract is the seam an agent consumes — and both the built-in path and an external/"standard" RAG service satisfy it. The built-in path is a KnowledgeBase: it pairs a core EmbeddingModel with a VectorStore (the pure-Dart InMemoryVectorStore by default) and a Chunker to ingest Documents and answer text queries — offline, no keys.

Wire retrieval into an agent with retrievalTool, which exposes any Retriever as an Akashi Tool the model can call.

Classes

Chunk
A retrievable slice of a Document, plus where it came from.
Chunker
Splits a Document into retrievable Chunks.
Document
A source document, before chunking.
EmbeddedChunk
A Chunk paired with its embedding vector — the unit a VectorStore ingests.
FixedSizeChunker
The simplest splitter: a fixed chunkSize window sliding by chunkSize - overlap, with no boundary awareness.
InMemoryVectorStore
A pure-Dart in-memory VectorStore: brute-force cosine similarity over a list. Zero dependencies and runs offline — the reference implementation, and what makes this package's example and tests key-free. Not intended for large corpora (search is O(n) per query).
KnowledgeBase
The high-level RAG façade for the built-in path: it pairs a core EmbeddingModel with a VectorStore to ingest Documents and answer text queries. It is the only place embeddings and storage meet, and it is a Retriever — so it drops straight into retrievalTool.
RecursiveChunker
Splits text to a target chunkSize (in characters) with overlap, preferring natural boundaries in separators order (paragraph → line → sentence → word) before falling back to a harder cut. The sensible default.
RetrievalQuery
A retrieval request.
RetrievedChunk
One scored hit from a Retriever.
Retriever
The read side of RAG, and the single seam an agent consumes: turn a text query into the most relevant chunks.
VectorStore
The write side of RAG: a vector index you upsert into and search by vector.

Functions

renderChunks(List<RetrievedChunk> hits) String
Render retrieved hits into a compact, model-friendly context block.
retrievalTool<TDeps>(Retriever retriever, {String name = 'search_knowledge_base', String description = 'Search the knowledge base for information relevant to a query.', int topK = 4, String render(List<RetrievedChunk> hits) = renderChunks}) → Tool<TDeps>
Expose a Retriever as an Akashi Tool the model can call — model-driven RAG, where the agent itself decides when to look something up.