Retriever class

Wires a Chunker, an Embedder, and a VectorStore into a retrieval pipeline: add texts once, then retrieve the passages most relevant to a query.

Constructors

Retriever({required Embedder embedder, required VectorStore store, Chunker? chunker})
Creates a retriever.

Properties

chunker Chunker
Splits added texts into chunks.
final
embedder Embedder
Embeds batches of chunk texts and single queries.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
store VectorStore
Holds the embedded chunks.
final

Methods

addText(String text, {String? sourceId, Map<String, Object?> metadata = const {}}) Future<void>
Chunks text, embeds all chunks in a single embedder call, and upserts them into store.
buildContext(String query, {int topK = 5, int? maxChars, String separator = '\n\n---\n\n', double? minScore, bool where(Document document)?, bool diverse = false, double lambda = 0.5}) Future<String>
Retrieves the chunks most relevant to query and joins their texts with separator into a single string, ready to paste into an LLM prompt.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
retrieve(String query, {int topK = 5, double? minScore, bool where(Document document)?}) Future<List<ScoredChunk>>
Embeds query and returns the most similar stored chunks, best first.
retrieveDiverse(String query, {int topK = 5, int? fetchK, double lambda = 0.5, double? minScore, bool where(Document document)?}) Future<List<ScoredChunk>>
Retrieves chunks that are relevant to query and unlike each other.
toString() String
A string representation of this object.
inherited

Operators

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