> ## Documentation Index
> Fetch the complete documentation index at: https://ibm-llm-runtime-aaf3a78b.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# mellea.stdlib.requirements.rag

> Requirements for RAG (Retrieval-Augmented Generation) workflows.

export const SidebarFix = () => <script dangerouslySetInnerHTML={{
  __html: `
        (function () {
          const INTERVAL_MS = 500;

          const upgradeSidebar = () => {
            const links = document.querySelectorAll('a[href^="#"]');

            links.forEach((link) => {
              if (link.dataset.badged === "true") return;

              const rawText = (link.textContent || "").trim();

              // ========== FUNC ==========
              if (rawText.startsWith("FUNC ")) {
                const label = rawText.replace(/^FUNC\\s+/, "").trim();

                while (link.firstChild) link.removeChild(link.firstChild);

                // 👉 Make the whole link a single flex row & prevent wrapping
                link.style.display = "flex";
                link.style.alignItems = "center";
                link.style.whiteSpace = "nowrap";
                link.style.columnGap = "0.5rem";

                const badge = document.createElement("span");
                badge.style.marginRight = "0.5rem";
                badge.style.display = "inline-flex";
                badge.style.alignItems = "center";
                badge.style.borderRadius = "9999px";
                badge.style.padding = "0rem 0.6rem";
                badge.style.fontSize = "0.5rem";
                badge.style.fontWeight = "700";
                badge.style.letterSpacing = "0.05em";
                badge.style.backgroundColor = "rgba(48, 100, 227, 0.20)";
                badge.style.color = "#1D4ED8";

                badge.textContent = "FUNC";

                link.appendChild(badge);
                link.appendChild(document.createTextNode(label));
                link.dataset.badged = "true";
                return;
              }

              // ========== CLASS ==========
              if (rawText.startsWith("CLASS ")) {
                const label = rawText.replace(/^CLASS\\s+/, "").trim();

                while (link.firstChild) link.removeChild(link.firstChild);

                // 👉 Same flex / nowrap treatment for class links
                link.style.display = "flex";
                link.style.alignItems = "center";
                link.style.whiteSpace = "nowrap";
                link.style.columnGap = "0.5rem";

                const badge = document.createElement("span");
                badge.style.marginRight = "0.5rem";
                badge.style.display = "inline-flex";
                badge.style.alignItems = "center";
                badge.style.borderRadius = "9999px";
                badge.style.padding = "0rem 0.6rem";
                badge.style.fontSize = "0.5rem";
                badge.style.fontWeight = "700";
                badge.style.letterSpacing = "0.05em";
                badge.style.backgroundColor = "rgba(74, 222, 128, 0.20)";
                badge.style.color = "#15803D";

                badge.textContent = "CLASS";

                link.appendChild(badge);
                link.appendChild(document.createTextNode(label));
                link.dataset.badged = "true";
                return;
              }
            });
          };

          upgradeSidebar();
          setInterval(upgradeSidebar, INTERVAL_MS);
        })();
      `
}} />;

<SidebarFix />

Requirements for RAG (Retrieval-Augmented Generation) workflows.

## Classes

<div className="w-full h-px bg-gray-200 dark:bg-gray-700 my-4" />

### <span className="ml-2 inline-flex items-center rounded-full px-2 py-1 text-[0.7rem] font-bold tracking-wide bg-[#4ADE8033]/20 text-[#15803D]">CLASS</span> `GroundednessRequirement` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.7.0.dev0/mellea/stdlib/requirements/rag.py#L22" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Requirement that validates LLM responses are grounded by citations.

This requirement implements a sophisticated 4-step validation pipeline to ensure
that LLM responses are fully grounded by citations to provided documents:

1. **Citation Generation**: Generate citations for the response using the
   find\_citations intrinsic.
2. **Citation Necessity**: Identify which response spans require citations (vs.
   conversational/inference text that doesn't need citations).
3. **Citation Support**: For spans that need citations, assess the level of
   citation support: fully, partially, or not supported.
4. **Groundedness Output**: Declare response grounded iff all spans needing
   citations are fully supported.

**Important**: This requirement requires a HuggingFace backend (LocalHFBackend)
as it uses both the find\_citations intrinsic and LLM-as-Judge for assessment.

**Args:**

* `documents`: Optional documents to validate against. Can be Document
  objects or strings (will be converted to Documents). If provided,
  these documents will be used instead of documents attached to
  messages in the context. Default is None (use context documents).
* `allow_partial_support`: Whether to accept partially supported spans as
  grounded. If False (default), response is grounded iff all spans
  needing citations are FULLY supported. If True, response is grounded
  if spans are fully or partially supported.
* `max_new_tokens`: Maximum tokens for LLM judgment outputs. Increase this
  if LLM outputs are being truncated (particularly for complex
  responses with many spans). Default is 500.
* `description`: Custom description for the requirement. If None,
  generates a default description.

<div className="h-8" />

**Methods:**

<div className="w-full h-px bg-gray-200 dark:bg-gray-700 my-4" />

#### <span className="ml-2 inline-flex items-center rounded-full px-2 py-1 text-[0.7rem] font-bold tracking-wide bg-[#3064E3]/20 text-[#1D4ED8]">FUNC</span> `validate` <sup><a href="https://github.com/generative-computing/mellea/blob/v0.7.0.dev0/mellea/stdlib/requirements/rag.py#L106" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={null}
validate(self, backend: Backend, ctx: Context) -> ValidationResult
```

Validate groundedness of the response using the 4-step pipeline.

**Args:**

* `backend`: Backend to use for citation detection and LLM judgment.
  Must be LocalHFBackend as this uses find\_citations intrinsic.
* `ctx`: Context containing the conversation history
* `format`: Unused for this requirement
* `model_options`: Unused for this requirement

**Returns:**

* ValidationResult with pass/fail status and detailed reason

<div className="w-full h-px bg-gray-200 dark:bg-gray-700 my-4" />
