> ## 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

> Lucidworks AI

export const schema = {
  "type": "object",
  "title": "Chunking RAG Bridge Stage",
  "description": "The bridge between Chunking NHQ and the LWAI Prediction stage  when using the RAG (Retrieval-Augmented Generation) approach. ",
  "required": ["vectorContextKey", "chunkTextField", "chunkVectorField", "topK", "chunkSpansField", "secondPassChunksContextKey"],
  "properties": {
    "skip": {
      "type": "boolean",
      "title": "Skip This Stage",
      "description": "Set to true to skip this stage.",
      "default": false,
      "hints": ["advanced"]
    },
    "label": {
      "type": "string",
      "title": "Label",
      "description": "A unique label for this stage.",
      "hints": ["advanced"],
      "maxLength": 255
    },
    "condition": {
      "type": "string",
      "title": "Condition",
      "description": "Define a conditional script that must result in true or false. This can be used to determine if the stage should process or not.",
      "hints": ["code", "code/javascript", "advanced"]
    },
    "legacy": {
      "type": "boolean",
      "title": "Legacy",
      "description": "True if this stage only supports legacy mode",
      "hints": ["readonly", "hidden"]
    },
    "firstPassDocsContextKey": {
      "type": "string",
      "title": "First Pass Results",
      "description": "Location from which to fetch the results of first pass query."
    },
    "parentDocsTitleField": {
      "type": "string",
      "title": "Parent Docs Title Field",
      "description": "The name of the field in the parent documents that contains the title.",
      "default": "title_t"
    },
    "vectorContextKey": {
      "type": "string",
      "title": "Vector Context Key",
      "description": "The context key for the vector corresponding to the query, as generated by the Vectorize stage. This is used for knn vector similarity search.",
      "default": "vector"
    },
    "chunkTextField": {
      "type": "string",
      "title": "Chunk Text Field",
      "description": "The field name that contains the text which has been chunked.  This will be used with chunkSpans to retrieve the text of any given chunk."
    },
    "chunkVectorField": {
      "type": "string",
      "title": "Chunk Vector Field",
      "description": "The name of the vector field in the chunk documents used for vector similarity search (e.g., 'chunk_vector' or 'vector')."
    },
    "topK": {
      "type": "integer",
      "title": "Top K",
      "description": "The number of top chunks to return based on the vector similarity search. This is used to limit the number of chunks returned in the second pass.",
      "default": 10
    },
    "chunkSpansField": {
      "type": "string",
      "title": "Chunk Spans Field",
      "description": "The field in the parent documents that contains the span information (start/end offsets) for each chunk. This is crucial for extracting the chunk's text."
    },
    "secondPassChunksContextKey": {
      "type": "string",
      "title": "Second Pass Results",
      "description": "Location in which to store the results of second pass query."
    }
  },
  "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 formatDescription = str => {
    const s = sanitize(str);
    return (/[.!?]\)*$/).test(s) ? s : `${s}.`;
  };
  const {description, properties = {}, required: requiredProps = []} = schema;
  const visibleProps = useMemo(() => Object.entries(properties).filter(([, prop]) => !prop.hints?.includes("hidden")), [properties]);
  return <div>
      {description && <p>{formatDescription(description)}</p>}

      {visibleProps.map(([name, prop]) => {
    const isRequired = requiredProps.includes(name);
    const hasDefault = prop.default !== undefined;
    const rawDefault = prop.default;
    const isComplexDefault = hasDefault && (typeof rawDefault === "object" || typeof rawDefault === "string" && (rawDefault.length > 20 || rawDefault.includes('"')));
    const fieldProps = {
      key: name,
      body: prop.title || name,
      type: prop.type,
      ...prop.title && ({
        post: [<><span className="text-stone-400 dark:text-stone-500">API property: </span>{name}</>]
      }),
      ...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>{formatDescription(prop.description)}</p>}

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

            {isArrayOfObjects && <div className="flex">
              <p>
                <strong>Object attributes:</strong>
              </p>
              <pre className="!my-0">
                <code>
                  {'{\n'}
                  {Object.entries(prop.items.properties).map(([iname, iprop]) => <>
                      {`  ${iname}`}
                      {prop.items?.required?.includes(iname) && <span style={{
      color: 'red'
    }}> required</span>}
                      {`: {\n    display name: ${sanitize(iprop.title || '')}\n    type: ${iprop.type}\n  }\n`}
                    </>)}
                  {'}'}
                </code>
              </pre>
              </div>}

            {isObject && <Expandable title="properties">
                <SchemaParamFields schema={{
      properties: prop.properties,
      required: prop.required
    }} />
              </Expandable>}
          </ParamField>;
  })}
    </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/lw-platform/lw-ai/lw-ai-stages/chunking-rag-bridge

[mintlify link]: https://doc.lucidworks.com/docs/lw-platform/lw-ai/lw-ai-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/lucidworks-search/09-developer-documentation/config-specs/query-pipeline-stages/chunking-neural-hybrid-query-stage), 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.

<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>

## 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/lucidworks-search/09-developer-documentation/config-specs/query-pipeline-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} />
