Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added retrieved documents in QuestionAnswering #122

Merged
merged 2 commits into from
May 14, 2024

Conversation

ezimuel
Copy link
Collaborator

@ezimuel ezimuel commented May 13, 2024

This PR adds the possibility to return the retrieved documents in QuestionAnswering using the similarity search in searchDocumentAndCreateSystemMessage(). This can be useful when implementing RAG architectures to retrieve the documents (chunk) used to generate the answer.

I proposed to add a QuestionAnswering::getRetrievedDocuments() that returns the array of Documents retrieved from the similarity search, as follows:

$qa = new QuestionAnswering($vectorStore, $embedding, $chat);

$result = $qa->answerQuestion('What is the capital city of Italy?');
print($result); // The capital city of Italy is Rome

$docs = $qa->getRetrievedDocuments();
printf("Answer generated using the following contents:\n");
foreach($docs as $d) {
    printf("%s\n", $d->content);
    printf("Source: %s\n", $d->sourceName);
}

@MaximeThoonsen MaximeThoonsen merged commit e795789 into theodo-group:main May 14, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants