> ## Documentation Index
> Fetch the complete documentation index at: https://docs.leapfinancial.com/llms.txt
> Use this file to discover all available pages before exploring further.

# RAG capabilities

> Retrieval-augmented generation for grounding agent responses in approved knowledge bases.

Lola Send uses Markdown-based retrieval-augmented generation (RAG) to ground agent responses in bank-approved knowledge bases. Before generating a response, agents retrieve relevant passages from the knowledge base, reducing hallucination and ensuring answers align with approved documentation.

## How it works

Lola Send's RAG implementation loads Markdown documents from a designated directory and splits them for granular retrieval. When an agent processes a message, it retrieves the most relevant passages from the knowledge base and includes them as context for the AI model — alongside the conversation history and system prompt.

This dual approach — tool functions for real-time data (quotes, recipients, operations) and RAG for static knowledge (country lists, fee schedules, payer information) — ensures agents reference verified content for both dynamic and reference data.

## Implementation

RAG is implemented as a singleton `MarkdownRAG` instance shared across all agents:

```python theme={null}
class MarkdownRAGSingleton:
    _instance = None

    def __new__(cls, *args, **kwargs):
        if cls._instance is None:
            cls._instance = super().__new__(cls)
            cls._instance._initialized = False
        return cls._instance

    def __init__(self, *args, **kwargs):
        if self._initialized:
            return
        self.mdm = MarkdownRAG(*args, **kwargs)
        self.mdm.load()
        self._initialized = True
```

The singleton loads once at application startup and is shared across all agents via `ast.set_rag_retrieval(rag)`.

### Document loading

Documents are loaded from `docs/{PROJECT_NAME}.md`, where `PROJECT_NAME` is set via environment variable. The `split_table_rows=True` option splits table-heavy documents by row, enabling precise retrieval of individual entries (e.g., a specific country's fee schedule or a single payer's details).

```python theme={null}
def get_rag():
    project_name = os.getenv("PROJECT_NAME")
    singleton = MarkdownRAGSingleton(
        "docs",
        file_path=f"{project_name}.md",
        split_table_rows=True
    )
    return singleton.mdm
```

### Per-agent activation

Each agent opts into RAG retrieval explicitly:

```python theme={null}
ast.set_rag_retrieval(rag)
```

All five of Lola Send's agents — onboarding, sender home, blocked, pending CIP, and service unavailable — use the same RAG instance and knowledge base.

## Knowledge base configuration

| Setting            | Source                   | Purpose                                        |
| ------------------ | ------------------------ | ---------------------------------------------- |
| `PROJECT_NAME`     | Environment variable     | Determines which knowledge base file is loaded |
| Document path      | `docs/{PROJECT_NAME}.md` | Markdown file containing the knowledge base    |
| `split_table_rows` | `True`                   | Splits tables by row for granular retrieval    |

Different deployments (brands, regions) can use different knowledge bases by changing the `PROJECT_NAME` environment variable. This enables white-label deployments where each bank has its own approved content.

<Note>
  RAG grounds agent responses in verified content. Combined with tool functions for real-time data, this dual approach minimizes hallucination risk — agents reference approved documentation for static knowledge and live backend services for transactional data.
</Note>

## Security considerations

* **Bank-maintained content**: The bank provides and maintains the knowledge base documents. Lola Send retrieves from them but does not modify them.
* **Read-only access**: The RAG system loads documents at startup and serves them as retrieval context. Agents cannot write to or alter the knowledge base at runtime.
* **Content isolation**: Each deployment's knowledge base is scoped by `PROJECT_NAME`. One deployment's content is not accessible to another.
* **No external retrieval**: RAG retrieves from local Markdown files only — it does not fetch content from the internet or external sources.

## Configuration and control

| Control                | Description                                                |
| ---------------------- | ---------------------------------------------------------- |
| Knowledge base content | The bank writes and maintains the Markdown documents       |
| `PROJECT_NAME`         | Selects the knowledge base per deployment or brand         |
| `split_table_rows`     | Controls retrieval granularity for table-heavy documents   |
| Per-agent activation   | Each agent can be configured with or without RAG retrieval |
