# End-to-end RAG application workflow

> End-to-end RAG application workflow - This example demonstrates how to build a complete RAG
> (Retrieval-Augmented Generation) application, combining LLM blueprints, vector databases,
> moderation, and testing. This workflow shows how to integrate all the components of a production-
> ready generative AI application.

This Markdown file sits beside the HTML page at the same path (with a `.md` suffix). It summarizes the topic and lists links for tools and LLM context.

Companion generated at `2026-04-24T16:03:56.279945+00:00` (UTC).

## Primary page

- [End-to-end RAG application workflow](https://docs.datarobot.com/en/docs/api/dev-learning/python/genai/rag-workflow.html): Full documentation for this topic (HTML).

## Sections on this page

- [Create a playground](https://docs.datarobot.com/en/docs/api/dev-learning/python/genai/rag-workflow.html#create-a-playground): In-page section heading.
- [Select an LLM](https://docs.datarobot.com/en/docs/api/dev-learning/python/genai/rag-workflow.html#select-an-llm): In-page section heading.
- [Build a vector database](https://docs.datarobot.com/en/docs/api/dev-learning/python/genai/rag-workflow.html#build-a-vector-database): In-page section heading.
- [Create an LLM blueprint](https://docs.datarobot.com/en/docs/api/dev-learning/python/genai/rag-workflow.html#create-an-llm-blueprint): In-page section heading.
- [Register custom model](https://docs.datarobot.com/en/docs/api/dev-learning/python/genai/rag-workflow.html#register-custom-model): In-page section heading.
- [Add moderation](https://docs.datarobot.com/en/docs/api/dev-learning/python/genai/rag-workflow.html#add-moderation): In-page section heading.
- [Interact via chats](https://docs.datarobot.com/en/docs/api/dev-learning/python/genai/rag-workflow.html#interact-via-chats): In-page section heading.

## Related documentation

- [Developer documentation](https://docs.datarobot.com/en/docs/api/index.html): Linked from this page.
- [Developer learning](https://docs.datarobot.com/en/docs/api/dev-learning/index.html): Linked from this page.
- [Python API client user guide](https://docs.datarobot.com/en/docs/api/dev-learning/python/index.html): Linked from this page.
- [Generative AI](https://docs.datarobot.com/en/docs/api/dev-learning/python/genai/index.html): Linked from this page.

## Documentation content

# End-to-end RAG application workflow

This example demonstrates how to build a complete RAG (Retrieval-Augmented Generation) application, combining LLM blueprints, vector databases, moderation, and testing. This workflow shows how to integrate all the components of a production-ready generative AI application.

### Create a playground

A playground is a workspace for experimenting with LLM configurations. All LLM blueprints must be associated with a playground.

```
import datarobot as dr
playground = dr.genai.Playground.create(
    name="RAG Application Playground",
    use_case=use_case.id
)
```

### Select an LLM

Choose from available LLMs provided by DataRobot. You can filter by use case or select based on model capabilities.

```
llms = dr.genai.LLMDefinition.list()
llm = [l for l in llms if 'gpt-4' in l.name.lower()][0]
```

### Build a vector database

Upload your documents as a dataset, then create a vector database with appropriate chunking parameters. The vector database stores document embeddings for RAG.

```
dataset = dr.Dataset.upload("company_docs.csv")
supported = dr.genai.VectorDatabase.get_supported_embeddings(dataset_id=dataset.id)
from datarobot.models.genai.vector_database import ChunkingParameters
chunking_params = ChunkingParameters(
    embedding_model=supported.default_embedding_model,
    chunking_method="semantic",
    chunk_size=500,
    chunk_overlap_percentage=10
)
use_case = dr.UseCase.get(use_case_id)
vector_db = dr.genai.VectorDatabase.create(
    dataset_id=dataset.id,
    use_case=use_case.id,
    name="Company Knowledge Base",
    chunking_parameters=chunking_params
)
```

### Create an LLM blueprint

Combine the LLM with the vector database to create a RAG-enabled blueprint. Configure system prompts and other LLM settings.

```
blueprint = dr.genai.LLMBlueprint.create(
    playground=playground.id,
    name="RAG Customer Support",
    description="RAG-enabled customer support assistant",
    llm=llm.id,
    llm_settings={
        "system_prompt": "You are a customer support assistant. Use the provided context to answer questions accurately.",
        "temperature": 0.7
    },
    vector_database=vector_db.id,
    vector_database_settings={
        "max_documents_retrieved_per_prompt": 3
    }
)
```

### Register custom model

Register the blueprint as a custom model version so it can be deployed and used in production.

```
custom_model_version = blueprint.register_custom_model()
```

### Add moderation

Set up content filtering to ensure safe and appropriate responses. Moderation can block or warn on problematic content.

```
template = dr.ModerationTemplate.list()[0]
moderation = dr.ModerationConfiguration.create(
    template_id=template.id,
    name="Content Safety",
    description="Filter inappropriate content",
    stages=[dr.ModerationGuardStage.PROMPT, dr.ModerationGuardStage.RESPONSE],
    entity_id=custom_model_version.id,
    entity_type=dr.ModerationGuardEntityType.CUSTOM_MODEL_VERSION,
    intervention=dr.ModerationIntervention.BLOCK
)
```

### Interact via chats

Create chat sessions to interact with your RAG application. Chats maintain conversation history for context-aware responses.

```
chat = dr.genai.Chat.create(
    name="Customer Support Session",
    llm_blueprint=blueprint.id
)
prompt = dr.genai.ChatPrompt.create(
    chat=chat.id,
    text="What is your return policy?"
)
prompt.text
prompt.result_text
```
