[GH-ISSUE #2212] [FEAT]: Cite source when using RAG #1446

Closed
opened 2026-02-22 18:24:50 -05:00 by yindo · 4 comments
Owner

Originally created by @goodglitch on GitHub (Sep 3, 2024).
Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/2212

What would you like to see?

The main problem with LLMs are their hallucinations. The best and the easiest way to have it under control is to double check results ourselves. That would be much easier if LLM will cite the exact source the information was retrieved from. For this I would suggest instead of using [CONTEXT #] to use something like [CONTEXT SRC="Attention Is All You Need"] blah, blah. [CONTEXT END]. Then in the LLM Prompt tell it directly to show the source that it has used and provide few examples like that:

Given the following conversation, relevant context, and a follow up question, reply with an answer to the current question the user is asking. Return only your response to the question given the above information following the users instructions as needed.

[CONTEXT SRC="Training strategies for improving listeners' comprehension of foreign-accented speech" page=5]
blah, blah.
[CONTEXT END]

[CONTEXT SRC="Teaching native speakers to listen to foreign-accented speech" page 23]
blah, blah.
[CONTEXT END]

ASSISTANT:
A few researchers in the linguistics field have developed training programs designed to improve native speakers' ability to understand accented speech (source 1). Their training techniques are based on the research described above indicating that comprehension improves with exposure to non-native speech. Other researchers conducted their training with students preparing to be social workers, but note that other professionals who work with non-native speakers could benefit from a similar program. (source 2)

References
Source 1: "Training strategies for improving listeners' comprehension of foreign-accented speech", page 5.
Source 2: "Teaching native speakers to listen to foreign-accented speech", page 23.

For htmls I think a relevant link will be sufficient.

Originally created by @goodglitch on GitHub (Sep 3, 2024). Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/2212 ### What would you like to see? The main problem with LLMs are their hallucinations. The best and the easiest way to have it under control is to double check results ourselves. That would be much easier if LLM will cite the exact source the information was retrieved from. For this I would suggest instead of using [CONTEXT #] to use something like [CONTEXT SRC="Attention Is All You Need"] blah, blah. [CONTEXT END]. Then in the LLM Prompt tell it directly to show the source that it has used and provide few examples like that: Given the following conversation, relevant context, and a follow up question, reply with an answer to the current question the user is asking. Return only your response to the question given the above information following the users instructions as needed. [CONTEXT SRC="Training strategies for improving listeners' comprehension of foreign-accented speech" page=5] blah, blah. [CONTEXT END] [CONTEXT SRC="Teaching native speakers to listen to foreign-accented speech" page 23] blah, blah. [CONTEXT END] ASSISTANT: A few researchers in the linguistics field have developed training programs designed to improve native speakers' ability to understand accented speech (source 1). Their training techniques are based on the research described above indicating that comprehension improves with exposure to non-native speech. Other researchers conducted their training with students preparing to be social workers, but note that other professionals who work with non-native speakers could benefit from a similar program. (source 2) References Source 1: "Training strategies for improving listeners' comprehension of foreign-accented speech", page 5. Source 2: "Teaching native speakers to listen to foreign-accented speech", page 23. For htmls I think a relevant link will be sufficient.
yindo added the enhancementfeature request labels 2026-02-22 18:24:50 -05:00
yindo closed this issue 2026-02-22 18:24:50 -05:00
Author
Owner

@timothycarambat commented on GitHub (Sep 3, 2024):

You cannot trust an LLM to do the above task, if it hallucinates a response even with valid context, it will hallucinate a validation for it as well. The reason the citation exists is that the only trustful way to verify information from a response is by directly viewing the context used by the LLM. This is why we include it in citations since you cannot, nor should you, trust an LLM to always give you perfect recall and answers.

When a citation is present we not only show the text snippets but also name the source document it was derived from. You get both of these details in the UI currently. I am not sure what more there is to accomplish on this detail that does not end with a black box evaluating a black box

@timothycarambat commented on GitHub (Sep 3, 2024): You cannot trust an LLM to do the above task, if it hallucinates a response even with valid context, it will hallucinate a validation for it as well. The reason the citation exists is that the only trustful way to verify information from a response is by directly viewing the context used by the LLM. This is why we include it in citations since you cannot, nor should you, trust an LLM to always give you perfect recall and answers. When a citation is present we not only show the text snippets but also name the source document it was derived from. You get both of these details in the UI currently. I am not sure what more there is to accomplish on this detail that does not end with a black box evaluating a black box
Author
Owner

@goodglitch commented on GitHub (Sep 4, 2024):

Thank you for the answer, missed Citations part. Happy that you have it, although there is no exact snippet and what is also important page number in the current reply:

image

Btw, just recently stumbled upon your two competitors Kotaemon and Ragflow. May be you can draw some inspiration from them. I especially like that you can immediately see relevant page of PDF in the UI in Kotaemon. Still haven't time to check Ragflow though.

@goodglitch commented on GitHub (Sep 4, 2024): Thank you for the answer, missed Citations part. Happy that you have it, although there is no exact snippet and what is also important page number in the current reply: ![image](https://github.com/user-attachments/assets/173b4878-57c4-4595-8e2c-373387ce204d) Btw, just recently stumbled upon your two competitors Kotaemon and Ragflow. May be you can draw some inspiration from them. I especially like that you can immediately see relevant page of PDF in the UI in Kotaemon. Still haven't time to check Ragflow though.
Author
Owner

@goodglitch commented on GitHub (Sep 4, 2024):

Btw, I am really curious how do you know what source has LLM used? I mean, you know what snippets you gave to it, but it is unclear to me how one can guess what exactly was used in the answer.

@goodglitch commented on GitHub (Sep 4, 2024): Btw, I am really curious how do you know what source has LLM used? I mean, you know what snippets you gave to it, but it is unclear to me how one can guess what exactly was used in the answer.
Author
Owner

@david-morris commented on GitHub (Sep 4, 2024):

I would like to move this to a discussion, but...
I understand that "hey where was your attention inside the loaded context" is the responsibility of the language model.
But the embedder decided to load a specific context from the available documents.

I get that the context window isn't going to line up with a page or paragraph, but it would be nice to spit out the part of the document that was loaded, even if it needs to be output as text. If we have some sort of "start of two pages worth of topic ... and that's why foo was chosen as a metasyntactic variable" citation mode, then we can look at how we could implement turning that into some sort of link that highlights relevant info.

I get that it's not what we really want (exact location citation), but it would make reviewing citations of large documents like books possible.

@david-morris commented on GitHub (Sep 4, 2024): I would like to move this to a discussion, but... I understand that "hey where was your attention inside the loaded context" is the responsibility of the language model. But the embedder decided to load a specific context from the available documents. I get that the context window isn't going to line up with a page or paragraph, but it would be nice to spit out the part of the document that was loaded, even if it needs to be output as text. If we have some sort of "start of two pages worth of topic ... and that's why foo was chosen as a metasyntactic variable" citation mode, then we can look at how we could implement turning that into some sort of link that highlights relevant info. I get that it's not what we really want (exact location citation), but it would make reviewing citations of large documents like books *possible*.
yindo changed title from [FEAT]: Cite source when using RAG to [GH-ISSUE #2212] [FEAT]: Cite source when using RAG 2026-06-05 14:40:49 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#1446