---
title: Custom Script Training
slug: custom-script-training
docTags: 
createdAt: 2026-03-23T17:47:53.243Z
---

## <font color="#2166AE">Overview</font>

Custom Script Training allows the AI agent to **fetch and process data dynamically using custom scripts** instead of uploading static documents or URLs.

This method is useful when knowledge needs to be retrieved from **external APIs, databases, or dynamic data sources**.

The script processes the data and returns it in **JSON format**, which is then indexed by the AI system for retrieval.

**Custom Script Data Sources**

Inside Custom Script training, you can configure different data sources: Custom scripts can be used for two main purposes:

- [RAG (Custom Data Indexing)](docId\:VZcukQ1T4yEZekcpPO6Xx)  – Retrieve responses using trained documents.
- [MongoDB Search Custom Script ](docId\:ZBKO9ka1xQs29P_X1rt5w) – Fetch data dynamically from MongoDB.

## <font color="#2166AE">When to Use RAG vs MongoDB</font>

Custom scripts can be used for two different purposes depending on how the data needs to be used by the AI system.

- **RAG Indexing** is used when the AI needs to perform **semantic search and retrieve contextual answers** from large text data.
- **MongoDB Storage** is used when the system needs to **store structured data and retrieve it using APIs or exact field queries**.

The table below explains the key differences.

| <font color="#2166AE">**RAG Indexing**</font>           | <font color="#2166AE">**MongoDB Storage**</font>****    |
| ------------------------------------------------------- | ------------------------------------------------------- |
| Uses page\_content                                      | Uses data\_to\_save                                     |
| Used for **semantic AI search**                         | Used for **structured database retrieval**              |
| Data is converted into **embeddings**                   | Data is stored as **JSON documents**                    |
| Best for **FAQs, documents, websites, knowledge bases** | Best for **product data, tours, doctors, catalog data** |
| AI retrieves answers based on **context similarity**    | Data retrieved using **API queries or filters**         |
| Optimized for **natural language queries**              | Optimized for **exact field lookup**                    |
| Supports **vector search**                              | Supports **database queries and integrations**          |

## <font color="#2166AE">Quick Guideline</font>

Use **RAG Indexing** when:

- The AI must answer questions from **documents, websites, FAQs, or large text content**.
- The user asks questions in **natural language**.
- Context-based retrieval is required.

Use **MongoDB Storage** when:

- The data is **structured records** (tours, doctors, products, bookings).
- The system needs to retrieve **specific fields or filtered data**.
- The data will be accessed through **backend APIs or system queries**.
