Class GroundedAnswer<T>
- Namespace
- AiDotNet.RetrievalAugmentedGeneration.Models
- Assembly
- AiDotNet.dll
Represents a generated answer with citations and source attribution for transparency and verification.
public class GroundedAnswer<T>
Type Parameters
TThe numeric data type used for relevance scoring.
- Inheritance
-
GroundedAnswer<T>
- Inherited Members
Remarks
A GroundedAnswer contains the AI-generated response along with references to the source documents used to create it. This grounding enables users to verify claims, understand context, and trust the generated content. The answer includes both inline citations and references to source documents.
For Beginners: A GroundedAnswer is like a research paper answer with footnotes.
Think of it like writing a school report:
- Answer: Your written response to the question
- SourceDocuments: The books and articles you referenced
- Citations: The footnote numbers [1], [2], [3] in your text
- ConfidenceScore: How sure you are that your answer is correct
Why is this important?
- Transparency: You can see where the information came from
- Verification: You can check if the AI interpreted sources correctly
- Trust: Answers backed by real sources are more reliable
- Learning: You can read the sources to learn more
Example: Question: "What causes rainbows?" Answer: "Rainbows are caused by light refraction through water droplets [1]. The water acts like a prism, separating white light into colors [2]." Citations: [1] = Physics textbook, [2] = Optics journal article SourceDocuments: The actual textbook and article ConfidenceScore: 0.95 (95% confident this answer is accurate)
Constructors
GroundedAnswer()
Initializes a new instance of the GroundedAnswer class.
public GroundedAnswer()
GroundedAnswer(string, IReadOnlyList<Document<T>>)
Initializes a new instance of the GroundedAnswer class with basic components.
public GroundedAnswer(string answer, IReadOnlyList<Document<T>> sourceDocuments)
Parameters
answerstringThe generated answer text.
sourceDocumentsIReadOnlyList<Document<T>>The source documents used to generate the answer.
GroundedAnswer(string, string, IReadOnlyList<Document<T>>, IReadOnlyList<string>, double)
Initializes a new instance of the GroundedAnswer class with all components.
public GroundedAnswer(string query, string answer, IReadOnlyList<Document<T>> sourceDocuments, IReadOnlyList<string> citations, double confidenceScore)
Parameters
querystringThe original query.
answerstringThe generated answer text.
sourceDocumentsIReadOnlyList<Document<T>>The source documents used to generate the answer.
citationsIReadOnlyList<string>The extracted citations.
confidenceScoredoubleThe confidence score.
Properties
Answer
Gets or sets the generated answer text.
public string Answer { get; set; }
Property Value
Remarks
The main response text generated by the model, potentially including inline citations in formats like [1], [2], or (Source: DocumentID). This is the direct answer to the user's query, augmented with information from retrieved documents.
For Beginners: This is the actual answer text the AI generated.
For example: "Photosynthesis is the process where plants convert sunlight into chemical energy [1]. This occurs primarily in chloroplasts [2] and produces oxygen as a byproduct [3]."
Citations
Gets or sets the extracted citations mapping citation markers to source documents.
public IReadOnlyList<string> Citations { get; set; }
Property Value
Remarks
A collection of citation text that maps markers in the answer (like [1], [2]) to actual source references. This enables click-through from citations to source documents and provides structured metadata for citation analysis.
For Beginners: These are the footnotes or reference markers in the answer.
For example, if the answer contains "[1]", the citation tells you:
- [1] = Document ID: doc_123, Title: "Photosynthesis Basics", Page: 45
Think of it like hovering over a Wikipedia citation number:
- You see [1] in the text
- You look at citations to see what [1] refers to
- You can then read that specific source
ConfidenceScore
Gets or sets the confidence score indicating the model's certainty in the answer.
public double ConfidenceScore { get; set; }
Property Value
Remarks
A value between 0 and 1 representing the model's confidence in the generated answer. Higher values indicate greater confidence based on factors like source document quality, relevance scores, and model certainty. A score below 0.5 may indicate the answer should be treated with caution or that insufficient information was available.
For Beginners: This is how confident the AI is that the answer is correct.
Think of it like a weather forecast:
- 0.95-1.0: Very confident (like "100% chance of rain")
- 0.70-0.85: Fairly confident (like "70% chance of rain")
- 0.50-0.70: Moderate confidence (like "50/50")
- Below 0.50: Low confidence (maybe the documents didn't have good info)
For example:
- Score 0.92: Retrieved documents clearly answered the question
- Score 0.45: Retrieved documents were somewhat related but unclear
Low scores mean: "I tried to answer, but I'm not very sure about this."
Query
Gets or sets the original query that prompted this answer.
public string Query { get; set; }
Property Value
Remarks
The user's original question or query that this answer responds to. Storing the query enables answer caching, logging, and analysis of query-answer pairs.
For Beginners: This is the question that was asked.
Keeping track of the question is useful for:
- Understanding context later
- Caching (if someone asks the same question again, reuse this answer)
- Analytics (what questions do users ask most often?)
SourceDocuments
Gets or sets the source documents that were used to generate the answer.
public IReadOnlyList<Document<T>> SourceDocuments { get; set; }
Property Value
Remarks
The collection of documents retrieved and used as context for generating the answer. These documents provide the factual grounding for the response and can be presented to users for verification and deeper exploration. Documents are typically ordered by relevance or citation frequency.
For Beginners: These are the "books" the AI read to write the answer.
Think of it like a bibliography in a research paper:
- Each source document is a reference you cited
- Users can click on these to read the original text
- This proves the answer isn't made up - it comes from real documents
For example:
- Document 1: "Photosynthesis in Plants" (biology textbook chapter)
- Document 2: "Chloroplast Function" (scientific journal)
- Document 3: "Oxygen Production in Plants" (research paper)