Can a RAG reference back to its source document? #233
-
Basically as the title says, because the FileVectorStore stores by lines, even knowing which line was the source will help |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 14 replies
-
The RAG component injects the retreived document into the system prompt along with its souce type and source name: https://github.com/inspector-apm/neuron-ai/blob/main/src/RAG/RAG.php#L125 Be sure to have the latest version 1.15.14 With a bit of good prompting I think you can get what you want asking the agent for a structured output. The structured output class should ask for the "citations". Somthing like: namespace App\Output;
class CitedAnswer
{
#[SchemaProperty(description: 'The answer to the user question', required: true)]
public string $answer;
/**
* @var \App\Output\Citations[]
*/
#[ArrayOf(Citations::class)]
public array $citations:
} namespace App\Output;
class Citations
{
#[SchemaProperty(description: 'The type of the source', required: true)]
public string $type;
#[SchemaProperty(description: 'The name of the source', required: true)]
public string $name:
} And than call the agent with structured method to enforce the agent includes also the reference to the original document: $response = MyRAG::make()->structured(
new UserMessage(...),
CitedAnswer::class
);
var_dump($response); The agent should be able to attach the source information of the documents used to generate the final answer. It is just as an inspiration. You can play with this to catch the structure that guarantees you the details you want. |
Beta Was this translation helpful? Give feedback.
The RAG component injects the retreived document into the system prompt along with its souce type and source name: https://github.com/inspector-apm/neuron-ai/blob/main/src/RAG/RAG.php#L125
Be sure to have the latest version 1.15.14
With a bit of good prompting I think you can get what you want asking the agent for a structured output.
The structured output class should ask for the "citations". Somthing like: