services/ask library

Answers a question from on-device search with a generation function the app supplies, without depending on any LLM SDK.

Classes

RagAnswer
An answer from ask, with the passages it was based on.
RagAskPrompt
The prompt for one question, built by prepareAsk.
RagPassage
A passage given to the LLM, with the citation id the model uses.

Functions

askWith(RagSearchTool tool, String question, {required RagGenerate generate, RagPromptBuilder buildPrompt = defaultAskPrompt}) → Future<RagAnswer>
prepareAskWith, then generate, then RagAskPrompt.answer. generate is not called when no passages were found.
citedPassages(String text, List<RagPassage> passages) → List<RagPassage>
Passages of passages cited in text as [1], [1, 2] or [1][2], in order of first citation and without repeats.
defaultAskPrompt(String question, List<RagPassage> passages) → String
Default prompt: instructions, numbered passages, then the question.
prepareAskWith(RagSearchTool tool, String question, {RagPromptBuilder buildPrompt = defaultAskPrompt}) → Future<RagAskPrompt>
Searches with tool (its defaultTopK passages) and builds the prompt for question.

Typedefs

RagGenerate = Future<String> Function(String prompt)
Generates the answer for prompt with the app's LLM.
RagPromptBuilder = String Function(String question, List<RagPassage> passages)
Builds the prompt sent to the LLM from the question and the passages found for it.