Skip to content

RAG Framework

Retrieval Augmented Generation (RAG) is a method that combines information retrieval with text generation for knowledge-intensive tasks. It retrieves relevant documents from a datasource (user selected set of documents) and uses them as context for LLM, improving factual consistency and reliability.

When given an input, RAG retrieves a collection of relevant documents from a specified datasource. These documents are then combined as context with the original input prompt and supplied to the LLM, resulting in the final output.

RAG Data Flow

flowchart LR
    A[User Query] -->B[RAG Framework]
    B --> |User Query| R{Query Refining}
    R --> |Yes| L1[LLM]
    L1--> |Refined Query|D[Datasource]
    R --> |No \n User Query| D
    D --> |Retrieved Documents| L2[LLM]
    B --> |Reference + Prompt|L2 --> O[Output]

How to use

Usecase Creation

You can use the developer portal under the tab usecase creation or call the POST API.

Please use the following steps:

  1. Create a datasource by uploading relevant files (Please refer to Datasource for further details.) We provide a SingtelDemo datasource as an example.

  2. Create RAG use case by providing the required attirbutes.

  3. Prepare the prompt that needs to include {query} and {sources}.

    Here's a sample:

    Explain why each of the 3 sources retrieved is relevant to the user query.
        User Query: {query}
        Sources:
        {sources}
        Return in the following format:
        1.  Resource No: Resource Number for the job\n
            Content: Content of the sources\n
            Explanation:\n
            A concise paragraph explaining to a user why this is chosen.
    

    Remember to put topk value to 3 so that it is consistent with the prompt.

Usecase Test/Debug

You can test the usecase through the frontend or debug using the developer portal under the tab Debug.

Type your query under the message and the framework will refer to the assigned datasource and will execute the RAG method to answer your query.

How to use SingtelRAG usecase?

You can ask questions related to Singtel which has been uploaded as a datasource,

Sample input:

who is Singtel Chairman in 2021?

The response will list out 3 most relevant resources in the format specified in the prompt earlier.

Sample response:

when reference option is set to Table with Reference Link during usecase creation, this option is selected by default:

| Reference Url                | Relevant Content                                                                     | Reason                                                                                                                             |
|------------------------------|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
| [Singtel Annual Report 2021, page 108](\api\v1\url\to_file) | Lee Theng Kiat is the Chairman of Singtel as of 2021                                 | This source directly answers the user query by providing the name of the current Chairman of Singtel in 2021.                      |
| [Singtel Annual Report 2021, page 57](\api\v1\url\to_file)  | Information on Singtel's Directors' fees and interests in shares and debentures      | This source is relevant to the user query as it provides information on the Directors of Singtel, including the Chairman, and their interests in shares and debentures. |
| [Singtel Annual Report 2022, page 57](\api\v1\url\to_file)  | Proposed aggregate fees for Directors for the financial year ending 31 March 2023    | This source is relevant to the user query as it provides information on the proposed fees for Directors, including the Chairman, for the upcoming financial year.       |

when reference is set to Table:

| Relevant Content                                                                     | Reason                                                                                                                             |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
| Lee Theng Kiat is the Chairman of Singtel as of 2021                                 | This source directly answers the user query by providing the name of the current Chairman of Singtel in 2021.                      |
| Information on Singtel's Directors' fees and interests in shares and debentures      | This source is relevant to the user query as it provides information on the Directors of Singtel, including the Chairman, and their interests in shares and debentures. |
| Proposed aggregate fees for Directors for the financial year ending 31 March 2023    | This source is relevant to the user query as it provides information on the proposed fees for Directors, including the Chairman, for the upcoming financial year.       |

The third option is In-line. Which would display a natural language answer like a Q&A dialogue, With the reference link inserted at the end.

The fourth option is Empty. Which would display no extra formatting. And attempt to answer user's question directly from sources.

Note: The response wording might be different, but the content should remain the same.