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

# Chunking RAG Bridge Query Stage

export const schema = {
  "type": "object",
  "title": "Chunking RAG Bridge Stage",
  "description": "Bridges the Chunking Neural Hybrid Query stage and the LWAI Prediction stage in a RAG pipeline, performing a second-pass vector similarity search over chunks and assembling context for the LLM.",
  "required": ["vectorContextKey", "chunkTextField", "chunkVectorField", "topK", "chunkSpansField", "secondPassChunksContextKey"],
  "properties": {
    "skip": {
      "type": "boolean",
      "title": "Skip This Stage",
      "description": "Controls whether this stage executes during pipeline processing at runtime. When set to `true`, the stage is completely bypassed and documents pass through unchanged to the next stage. Useful for A/B testing, gradual rollouts, or temporarily disabling a stage without removing it from the pipeline.",
      "default": false,
      "hints": ["advanced"]
    },
    "label": {
      "type": "string",
      "title": "Label",
      "description": "Human-readable identifier displayed in the Fusion Admin UI, monitoring dashboards, and log messages. Use descriptive labels like `Parse Product PDFs` to aid debugging and team collaboration. Labels appear in performance metrics and error reports, making it easier to identify which stage failed.",
      "hints": ["advanced"],
      "maxLength": 255
    },
    "condition": {
      "type": "string",
      "title": "Condition",
      "description": "JavaScript expression evaluated at runtime on each document to conditionally execute this stage. The expression must return `true` to execute or `false` to skip. Access document fields using `doc.getFieldValue('fieldName')` and request parameters via `request.getFirstParam('paramName')`. For example, `doc.getFieldValue('type') === 'premium'` executes this stage only for premium content.",
      "hints": ["code", "code/javascript", "advanced"]
    },
    "legacy": {
      "type": "boolean",
      "title": "Legacy",
      "description": "When `true`, this stage operates in legacy mode only.",
      "hints": ["readonly", "hidden"]
    },
    "firstPassDocsContextKey": {
      "type": "string",
      "title": "First Pass Results",
      "description": "Specifies the context key from which the first-pass query results are retrieved."
    },
    "parentDocsTitleField": {
      "type": "string",
      "title": "Parent Docs Title Field",
      "description": "Specifies the document field containing the parent document title. Default is `title_t`.",
      "default": "title_t"
    },
    "vectorContextKey": {
      "type": "string",
      "title": "Vector Context Key",
      "description": "Specifies the context key holding the query vector, as generated by a preceding Vectorize stage, used for the second-pass kNN search.",
      "default": "vector"
    },
    "chunkTextField": {
      "type": "string",
      "title": "Chunk Text Field",
      "description": "Specifies the document field containing the text of each chunk."
    },
    "chunkVectorField": {
      "type": "string",
      "title": "Chunk Vector Field",
      "description": "Specifies the document field containing the vector embedding of each chunk."
    },
    "topK": {
      "type": "integer",
      "title": "Top K",
      "description": "Sets the number of top-ranked chunks returned by the second-pass vector similarity search.",
      "default": 10
    },
    "chunkSpansField": {
      "type": "string",
      "title": "Chunk Spans Field",
      "description": "Specifies the document field containing span information for each chunk."
    },
    "secondPassChunksContextKey": {
      "type": "string",
      "title": "Second Pass Results",
      "description": "Specifies the context key where the results of the second-pass chunk search are stored."
    }
  },
  "category": "AI",
  "categoryPriority": 10,
  "unsafe": false
};

export const SchemaParamFields = ({schema}) => {
  const sanitize = str => {
    if (typeof str !== "string") return str;
    return str.replace(/^"(.*)"$/s, "$1").replace(/\\/g, "").replace(/"/g, "'");
  };
  const renderMd = str => {
    const s = sanitize(str);
    const text = (/[.!?]\)*$/).test(s) ? s : `${s}.`;
    return text.split(/(\*\*[^*]+\*\*|_[^_]+_|`[^`]+`)/g).map((part, i) => {
      if (part.startsWith("**")) return <strong key={i}>{part.slice(2, -2)}</strong>;
      if (part.startsWith("_")) return <em key={i}>{part.slice(1, -1)}</em>;
      if (part.startsWith("`")) return <code key={i}>{part.slice(1, -1)}</code>;
      return part;
    });
  };
  const {description, properties = {}, required: requiredProps = []} = schema;
  const visibleProps = useMemo(() => Object.entries(properties).filter(([, prop]) => !prop.hints?.includes("hidden")), [properties]);
  const renderProp = ([name, prop]) => {
    const isRequired = requiredProps.includes(name);
    const hasDefault = prop.default !== undefined;
    const rawDefault = prop.default;
    const hints = prop.hints || [];
    const isComplexDefault = hasDefault && (typeof rawDefault === "object" || typeof rawDefault === "string" && (rawDefault.length > 20 || rawDefault.includes('"')));
    const postBadges = [];
    if (prop.title) {
      postBadges.push(<><span className="text-stone-400 dark:text-stone-500">API property: </span>{name}</>);
    }
    const constraints = [];
    if (prop.minimum !== undefined && prop.maximum !== undefined) {
      constraints.push(`Range: ${prop.minimum} – ${prop.maximum}`);
    } else if (prop.minimum !== undefined) {
      constraints.push(`Min: ${prop.minimum}`);
    } else if (prop.maximum !== undefined) {
      constraints.push(`Max: ${prop.maximum}`);
    }
    if (prop.minLength !== undefined && prop.maxLength !== undefined) {
      constraints.push(`Length: ${prop.minLength} – ${prop.maxLength}`);
    } else if (prop.minLength !== undefined) {
      constraints.push(`Min length: ${prop.minLength}`);
    } else if (prop.maxLength !== undefined) {
      constraints.push(`Max length: ${prop.maxLength}`);
    }
    const fieldProps = {
      key: name,
      body: prop.title || name,
      type: prop.type,
      ...postBadges.length > 0 && ({
        post: postBadges
      }),
      ...isRequired && ({
        required: true
      }),
      ...!isComplexDefault && hasDefault ? {
        default: sanitize(String(rawDefault))
      } : {}
    };
    const isObject = prop.type === "object" && prop.properties;
    const isArrayOfObjects = prop.type === "array" && prop.items?.type === "object" && prop.items.properties;
    return <ParamField {...fieldProps}>
        {prop.description && <p>{renderMd(prop.description)}</p>}

        {prop.enum && <p>
            Allowed values: 
            {prop.enum.map((v, i) => <>{i > 0 && ", "}<code key={i}>{String(v)}</code></>)}
          </p>}

        {constraints.length > 0 && <p className="text-stone-500 dark:text-stone-400 text-sm">
            {constraints.join(" · ")}
          </p>}

        {isComplexDefault && <div className="flex">
            <p>
              <strong>Default:</strong>
            </p>
            <pre className="!my-0">
              <code>
                {JSON.stringify(rawDefault, null, 2)}
              </code>
            </pre>
          </div>}

        {isArrayOfObjects && <Expandable title="item properties">
            <SchemaParamFields schema={{
      properties: prop.items.properties,
      required: prop.items.required
    }} />
          </Expandable>}

        {isObject && <Expandable title="properties">
            <SchemaParamFields schema={{
      properties: prop.properties,
      required: prop.required
    }} />
          </Expandable>}
      </ParamField>;
  };
  return <div>
      {description && <p>{renderMd(description)}</p>}

      {visibleProps.map(renderProp)}
    </div>;
};

export const LwTemplate = ({title = "Key questions to get you started", icon = "sparkles", cta = "Powered by Agent Studio", linkHref = "https://lucidworks.com/demo/?utm_source=docs&utm_medium=referral&utm_campaign=docs_cta_ai"}) => {
  const [isLoaded, setIsLoaded] = useState(false);
  useEffect(() => {
    const timer = setTimeout(() => {
      setIsLoaded(true);
    }, 500);
    return () => clearTimeout(timer);
  }, []);
  return <div className="lw-template-container">
      <Card title={title} icon={icon}>
        {isLoaded && <span dangerouslySetInnerHTML={{
    __html: `<lw-template id="a029c1a9-28be-427e-b0e1-5d918920246a"></lw-template
            >`
  }} />}
        <Link href={linkHref} className="agent-studio-link text-left text-gray-600 gap-2 dark:text-gray-400 text-sm font-medium flex flex-row items-center hover:text-primary dark:hover:text-primary-light group-hover:text-primary group-hover:dark:text-primary-light">Powered by Lucidworks Agent Studio</Link>
      </Card>
    </div>;
};

[localhost link]: http://localhost:3000/docs/5/fusion/reference/config-ref/pipeline-stages/query-stages/chunking-rag-bridge

[mintlify link]: https://doc.lucidworks.com/docs/5/fusion/reference/config-ref/pipeline-stages/query-stages/chunking-rag-bridge

<Note>
  This feature is only available in Fusion 5.9.x for versions 5.9.15 and later.
</Note>

The Chunking RAG Bridge query stage extracts relevant snippets from source documents used in RAG responses. When your query pipeline includes document chunking and retrieval via the [Chunking Neural Hybrid Query stage](/docs/5/fusion/reference/config-ref/pipeline-stages/query-stages/chunking-neural-hybrid-query), this stage identifies and includes the most relevant chunk for each cited document in the response.

When used in your query pipeline, searchers can validate the content of the AI-generated response by comparing the response with the relevant section of the source material.

Click **Get Started** below to see how to enable chunking in Fusion:

<iframe src="https://app.supademo.com/embed/cmfzg6uw4009oxx0i1ptmac82?embed_v=2&utm_source=embed" loading="lazy" title="Enable chunking in Fusion" allow="clipboard-write" frameborder="0" webkitallowfullscreen="true" mozallowfullscreen="true" allowfullscreen style={{  width: '100%', height: '500px' }} />

<LwTemplate />

## Example use cases for this stage

### B2B use case

A user asks, "What is the data retention policy for customer financial records?"

<Columns cols={2}>
  <Card title="Before (document-level RAG)">
    **RAG answer:** Customer data is retained according to company policy and applicable regulations. *Source: Enterprise Compliance Manual*

    **Problem:** An entire manual with hundreds of pages is cited. The user still has to search the document to find the actual retention period and rules.
  </Card>

  <Card title="After (chunk-level RAG with snippets)">
    **RAG answer:** Customer financial records must be retained for 7 years in compliance with regulatory requirements. *Source: Enterprise Compliance Manual "...Section 4.2 — Financial records must be stored for a minimum of 7 years before secure archival or disposal..."*

    **Benefit:** The answer is backed by the exact snippet from the compliance manual, so users can immediately validate and take action without reading through the full document.
  </Card>
</Columns>

### B2C use case

A user asks, "Does this laptop support international power adapters?"

<Columns cols={2}>
  <Card title="Before (document-level RAG)">
    **RAG answer:** The laptop is compatible with standard accessories. *Source: Product Specification Sheet*

    **Problem:** The entire product sheet is cited. The shopper still needs to scan through dozens of specifications to find the answer.
  </Card>

  <Card title="After (chunk-level RAG with snippets)">
    **RAG answer:** Yes, this laptop supports international power adapters (100–240V) and includes a universal charger. *Source: Product Specification Sheet "...Power Supply: 100–240V universal adapter included. Supports multiple regional plug types..."*

    **Benefit:** The answer is precise and backed by the exact snippet from the source. The shopper can make a confident purchase decision without reading through unrelated details.
  </Card>
</Columns>

## Prerequisites

### Lucidworks AI Gateway

Make sure you have configured a [Lucidworks AI Gateway](/docs/lw-platform/lw-ai/lw-ai-gateway) integration before you begin.
Lucidworks AI Gateway provides a secure, authenticated connection between Fusion and your hosted models.

### Permissions

To use this stage, non-admin Fusion users must be granted the `PUT,POST,GET:/LWAI-ACCOUNT-NAME/**` permission in Fusion, which is the Lucidworks AI API Account Name defined in [Lucidworks AI Gateway](/docs/lw-platform/lw-ai/lw-ai-gateway) when this stage is configured.

## Order of stage in a pipeline

You can pass on the response of this stage as the `context` field in the [LWAI Prediction stage](/docs/5/fusion/reference/config-ref/pipeline-stages/query-stages/lucidworks-ai-prediction-query-stage) in order to generate relevant results and chunks for searchers.

When using the Chunking RAG Bridge stage, it must be placed between the Chunking Neural Hybrid Query stage and the LWAI Prediction Query stage in your pipeline.

## Configuration

<Tip>
  When entering configuration values in the UI, use *unescaped* characters, such as `\t` for the tab character. When entering configuration values in the API, use *escaped* characters, such as `\\t` for the tab character.
</Tip>

<SchemaParamFields schema={schema} />
