Is it possible to create a RAG with citations? #8286
-
As the title says, I would be interested in building a RAG that gives me citations. Your tutorials are great btw, I hope I didn't miss something. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @alybel yes that's possible! You're looking for the Haystack component called AnswerBuilder: https://docs.haystack.deepset.ai/docs/answerbuilder ...
Always use references in the form [NUMBER OF DOCUMENT] if you use information from a document, e.g. [3] for document [3].
Never name the documents, only enter a number in square brackets as a reference.
The reference may only refer to the number in square brackets after the passage.
Otherwise, do not use brackets in your answer and give ONLY the number of the document without mentioning the word document.
Give a precise, accurate and structured answer without repeating the question.
...
These are the documents:
{% for document in documents %}
Document[{{ loop.index }}]:
{{ document.content }}
{% endfor %}
Question: {{question}}
Answer: |
Beta Was this translation helpful? Give feedback.
Hi @alybel yes that's possible! You're looking for the Haystack component called AnswerBuilder: https://docs.haystack.deepset.ai/docs/answerbuilder
It has an optional parameter
reference_pattern
. You could set that reference_pattern to\\[(?:(\\d+),?\\s*)+\\]
and then instruct the LLM to include references in the answer. The AnswerBuilder will then extract references to documents from the answer generated by the LLM. Set the prompt of the LLM in your pipeline to something like the following so that it includes references in the generated answer: