Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to show document fragments/snippets in Q&A RAG app?#116

AnsweredbySaksham65
niutech asked this question inQ&A
Discussion options

I'm testing theQ&A RAG demo app, but how to show the relevant fragments/snippets from the indexed documents as references? This is now it looks like in NotebookLM:

NotebookLM references

Could you provide a Pathway example for that? Thanks!

You must be logged in to vote

Hey there!

You can replicate NotebookLM’s “hover to see references” feature by following these steps:

Instruct the LLM to include citations:

Modify your prompt_template in BaseRAGQuestionAnswerer to tell the LLM to insert citation markers ([1], [2], etc.) in the response:

prompt_template=(    "Given the following documents:\n{context}\n\n"    "Answer the question in detail, and include citations in the format [number] "    "that map to the corresponding document snippets.\n\n"    "Question: {query}")

Set return_context_docs=True:

When calling the RAG endpoint, ensure that the response includes both the generated answer and the retrieved document snippets:

response = pathway_client.p…

Replies: 1 comment

Comment options

Hey there!

You can replicate NotebookLM’s “hover to see references” feature by following these steps:

Instruct the LLM to include citations:

Modify your prompt_template in BaseRAGQuestionAnswerer to tell the LLM to insert citation markers ([1], [2], etc.) in the response:

prompt_template=(    "Given the following documents:\n{context}\n\n"    "Answer the question in detail, and include citations in the format [number] "    "that map to the corresponding document snippets.\n\n"    "Question: {query}")

Set return_context_docs=True:

When calling the RAG endpoint, ensure that the response includes both the generated answer and the retrieved document snippets:

response = pathway_client.pw_ai_answer(    "What are the terms of the contract?",    return_context_docs=True)

That way, the response contains two parts:

  • response["response"]: the LLM’s final answer (with [1], [2], etc.).
  • response["context_docs"]: A list of relevant document snippets, each with metadata (e.g., file name, page number).

You can see the official RAGClient docs here inPathway’s documentation to learn more.

Link the citations to their corresponding snippets (UI side):

Once you have the answer and context_docs, your front-end (or final processing step) needs to:

  1. Extract citation markers ([2], [5], etc.) from the answer.
  2. Match them to the correct snippet in response["context_docs"].
  3. Replace citations with actual references, e.g., [2] → (myfile.pdf, p.18)
    For example, if [2] appears in the answer, it likely refers to context_docs[1]. You can format it like:
    📌 [2] → (myfile.pdf, Page 18)

Right now, our demo-qna UI does not automatically map citations to snippets. This needs to be handled in the front-end.
However, you now have all the pieces:

  1. The LLM generates citations
  2. The RAG system retrieves relevant document snippets
  3. You can post-process the answer to dynamically link [2] → context_docs[1]
You must be logged in to vote
0 replies
Answer selected byniutech
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@niutech@Saksham65

[8]ページ先頭

©2009-2025 Movatter.jp