Generating An Answer
When documents have been retrieved, the pipeline needs to know how to generate an answer for the initial query.
The Answer trait
The Answer trait is defined as follows:
pub trait Answer: Send + Sync { async fn answer(&self, query: Query<states::Retrieved>) -> Result<Query<states::Answered>>;}The trait is also implemented for closures.
The Simple answer
In a lot of cases, the Simple answer might just be sufficient. It takes either a transformed context if present, or the current retrieved documents, then prompts
the LLM with the original query to generate an answer.
Optionally, it can also take a Prompt to render documents before adding them to the context.
The prompt used is straightforward:
Answer the following question based on the context provided:{{ question }}
## Constraints
- Do not include any information that is not in the provided context.- If the question cannot be answered by the provided context, state that it cannot be answered.- Answer the question completely and format it as markdown.
## Context
{{ context }}Built in answer generators
| Name | Description | Feature Flag |
|---|---|---|
| Simple | Generates an answer based on a transformed context, or the documents as is |