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

Cookbook showing RAG with references to documents in answers #73

Open
julian-risch opened this issue Mar 27, 2024 · 1 comment
Open
Labels

Comments

@julian-risch
Copy link
Member

julian-risch commented Mar 27, 2024

Haystack 1.x had this prompt template https://prompthub.deepset.ai/?prompt=deepset%2Fquestion-answering-with-references instructing the LLM to provide references "[1]" to documents in the generated answer. It would be great to have a cookbook showing how to do that with Haystack 2.x.

The existing https://github.com/deepset-ai/haystack-cookbook/blob/main/notebooks/prompt_customization_for_Anthropic.ipynb is related but uses quotes from the documents. What I am looking for is a free text generated answer with references to documents not quotes.

Prompt could be the following:

from haystack.components.builders import PromptBuilder

template = """
Create a concise and informative answer (no more than 50 words) for a given question based solely on the given documents. 
You must only use information from the given documents. Use an unbiased and journalistic tone. Do not repeat text. 
Cite the documents using Document[number] notation. 
If multiple documents contain the answer, cite those documents like ‘as stated in Document[number], Document[number], etc.’. 
If the documents do not contain the answer to the question, say that ‘answering is not possible given the available information.’

Given the following information, answer the question.

{% for document in documents %}
    Document[{{loop.index}}]: {{ document.content }} \n
{% endfor %}

Question: {{question}}
Answer:
"""

prompt_builder = PromptBuilder(template=template)
@julian-risch
Copy link
Member Author

I prepared a notebook here: https://colab.research.google.com/drive/1-WZcQlpB_h6C82VHeeSFcaWqRl15aDC-?usp=sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant