Execute RAG Endpoint

RAG

Retrieval-Augmented Generation (RAG) combines a large language model with your organization’s own knowledge base to deliver accurate, context-aware responses grounded in the organization specific documents.

Catalyst QuickML is equipped with RAG system under Generative AI services, to deliver responses grounded in the organization’s own documents with ground truth citations of the documents for traceability. Multiple RAG modes have been introduced each designed for a different use case. Every mode exposes its own dedicated parameters, giving you absolute control over how the RAG system generates responses.

Let’s take a quick look at the RAG modes:

  • Response Generation : Response Generation is the standard RAG mode where model generates response grounded with relevant chunks of information from the documents
  • Agentic RAG : An agent layer on top of RAG that can reason over complex queries, decompose them into sub-queries, and handle conversational interactions
  • Document Search : It is retrieval-only task, doesn’t generate a response but returns the most relevant chunks of content from the documents.

Execute RAG Endpoint

Create a RAG endpoint from a saved RAG configuration. The RAG mode, selected large language model, respective parameters, and document store are captured from the saved configuration at the time of endpoint creation. It cannot be overridden through the SDK.

The SDK method you call depends on the RAG mode the endpoint was configured with:

RAG mode SDK method
Response Generation generateRagRsponse( endpointKey, prompt )
Document Search searchDocuments( endpointKey, query )
Agentic RAG (without history) askRagAgent( endpointKey, prompt )
Agentic RAG (with history) converseWithRagAgent( endpointKey, prompt, conversationId )

Note:
  1. You will need to have the RAG endpoint created and published in your project using the Catalyst console, before you execute the code snippets below.

  2. QuickML is currently available to Catalyst users accessing from the US, IN, and EU data centers

a. Generate a RAG Response

The generateRagResponse(endpointKey, prompt) method sends a question to a published RAG endpoint. The service retrieves the most relevant content from the endpoint’s document store and returns a summarized response grounded in the retrieved content.

Parameters used

Parameter Description Values
endpointKey The unique ID of the RAG endpoint published in your project String
prompt The query which is sent to the model. String

Sample Code Snippet

copy

// Replace with your endpoint key copied from the Catalyst console. String endpointKey = “<ENDPOINT_KEY>”;

// Enter your question. String prompt = “<YOUR_PROMPT>”;

ZCQuickMLDetail result = quickMlInstance.generateRagResponse(endpointKey, prompt);

System.out.println(result.getResponse());

The syntax of the response received is shown below:

copy
{
  "status": "success",
  "result": [
    {
      "content": "The answer, grounded in the retrieved documents.",
      "citations": [
        {
          "document_name": "employee_handbook_2026.pdf",
          "document_id": "doc_10294",
          "chunk_id": "chunk_58",
          "page_number": 14,
          "text": "The excerpt of source text the answer was grounded in.",
          "score": 0.91
        }
      ],
      "usage": {
        "input_tokens": 1420,
        "output_tokens": 112,
        "total_tokens": 1532
      }
    }
  ]
}

Use this method for document-based question answering, summarization, and support assistants

b. Search Documents

The searchDocuments(endpointKey, query) method performs document retrieval only. It returns the chunks of content from the document store that most closely match the specified query, without generating a response.

Parameters used

Parameter Description Values
endpointKey The unique ID of the RAG endpoint published in your project String
query The search query is sent to the document store. String

Sample Code Snippet

copy

// Replace with your endpoint key copied from the Catalyst console. String endpointKey = “<ENDPOINT_KEY>”;

// Enter the search query. String query = “<SEARCH_QUERY>”;

ZCQuickMLDetail result = quickMlInstance.searchDocuments(endpointKey, query);

System.out.println(result.getResponse());

The syntax of the response received is shown below:

copy
{
  "status": "success",
  "result": [
    {
      "chunk_id": "chunk_58",
      "document_name": "employee_handbook_2026.pdf",
      "document_id": "doc_10294",
      "page_number": 14,
      "text": "The retrieved chunk of content that matched the query.",
      "score": 0.91
    },
    {
      "chunk_id": "chunk_59",
      "document_name": "employee_handbook_2026.pdf",
      "document_id": "doc_10294",
      "page_number": 15,
      "text": "The next most relevant chunk of content.",
      "score": 0.84
    }
  ]
}

Use this method when your application needs the raw retrieved passages for downstream processing, ranking, or custom rendering

c. Ask a RAG Agent

The askRagAgent(endpointKey, prompt ) method sends a single message to an Agentic RAG endpoint. The agent can decompose complex queries into sub-queries, refine them, and perform multi-step reasoning over the document store before returning a response.

Note: Each call is independent. No conversation context is retained.

Parameters used

Parameter Description Values
endpointKey The unique ID of the RAG endpoint published in your project String
prompt The query which is sent to the model String

Sample Code Snippet

copy

// Replace with your endpoint key copied from the Catalyst console. String endpointKey = “<ENDPOINT_KEY>”;

// Enter your message. String prompt = “<YOUR_PROMPT>”;

ZCQuickMLDetail result = quickMlInstance.askRagAgent(endpointKey, prompt);

System.out.println(result.getResponse());

The syntax of the response received is shown below:

copy
{
  "status": "success",
  "result": [
    {
      "content": "The agent's answer after reasoning over the document store.",
      "sub_queries": [
        "First decomposed sub-query the agent generated.",
        "Second decomposed sub-query the agent generated."
      ],
      "citations": [
        {
          "document_name": "policy_v3.pdf",
          "document_id": "doc_10877",
          "chunk_id": "chunk_12",
          "page_number": 3,
          "text": "The excerpt of source text the answer was grounded in.",
          "score": 0.88
        }
      ],
      "usage": {
        "input_tokens": 3180,
        "output_tokens": 204,
        "total_tokens": 3384
      }
    }
  ]
}

Use this method when your application needs agentic reasoning over documents for complex questions that may require query decomposition, refinement, and multi-step retrieval.

d. Converse with a RAG Agent

The converseWithRagAgent(endpointKey, prompt, conversationId) method sends a message to an Agentic RAG endpoint while retaining the context of previous turns. Use this method to build multi-turn assistants that answer follow-up questions using information from the same document store.

Parameters used

Parameter Description Values
endpointKey The unique ID of the RAG endpoint published in your project String
prompt The query which is sent to the model String
conversationId Identifies the conversation thread to which the message belongs. String

Note: For the first request, set conversationId to `"-1"`. The response returns a unique conversation ID, which you must pass in subsequent requests to continue the same conversation thread.

Sample Code Snippet

copy

// Replace with your endpoint key copied from the Catalyst console. String endpointKey = “<ENDPOINT_KEY>”;

// Enter your message. String prompt = “<YOUR_PROMPT>”;

/*

  • For the first request, set the conversation ID to “-1”.
  • For subsequent requests, use the conversation ID returned
  • in the previous response. */ String conversationId = “<CONVERSATION_ID>”;

ZCQuickMLDetail result = quickMlInstance.converseWithRagAgent(endpointKey, prompt, conversationId);

System.out.println(result.getResponse());

The syntax of the response received is shown below:

copy
{
  "status": "success",
  "result": [
    {
      "conversationId": "55663000000288001",
      "content": "The agent's answer, informed by earlier turns in this conversation.",
      "citations": [
        {
          "document_name": "policy_v3.pdf",
          "document_id": "doc_10877",
          "chunk_id": "chunk_12",
          "page_number": 3,
          "text": "The excerpt of source text the answer was grounded in.",
          "score": 0.88
        }
      ],
      "usage": {
        "input_tokens": 3612,
        "output_tokens": 188,
        "total_tokens": 3800
      }
    }
  ]
}

The conversationId returned in the response identifies the conversation thread. Use this ID in subsequent requests to maintain the conversation context.

Use this method to build multi-turn RAG assistants that can understand follow-up questions while retaining the context of previous interactions.

Where to find the endpoint information
Create an endpoint for your saved RAG configuration and access the endpoint details page to view the Endpoint URL , required headers, and a sample request and response.

quickml-java-sdk-4.webp

Last Updated 2026-09-08 15:18:40 +0530 IST