A LlamaIndex query pipeline ends by turning retrieved nodes into a response. The response synthesizer controls that last stage, including how the model combines source chunks and whether it refines, summarizes, or returns retrieved context.

The get_response_synthesizer() factory accepts a response_mode and an explicit LLM. The compact mode repacks retrieved text into as few prompt chunks as the context window permits, then refines the answer only when more than one chunk remains.

One known support-policy sentence supplies the retrieved context for a credential-free check with MockLLM. This isolates response synthesis from embeddings and vector storage; production code can substitute the application's LLM without changing the tested response_mode handoff.

Steps to configure a LlamaIndex response synthesizer:

  1. Create response_synth.py with the imports and controlled retrieved node.
    response_synth.py
    from llama_index.core import get_response_synthesizer
    from llama_index.core.llms import MockLLM
    from llama_index.core.schema import NodeWithScore, TextNode
     
     
    nodes = [
        NodeWithScore(
            node=TextNode(text="Refund requests are handled by the support portal."),
            score=1.0,
        )
    ]
  2. Add the compact response synthesizer below the nodes list.
    response_synthesizer = get_response_synthesizer(
        response_mode="compact",
        llm=MockLLM(max_tokens=None),
    )

    Production code should pass the application's LLM explicitly. Without llm=, the factory resolves the configured default LLM, which may require a separate provider integration and credentials.

  3. Add the synthesis call below the response synthesizer configuration.
    response = response_synthesizer.synthesize(
        "Where are refund requests handled?",
        nodes=nodes,
    )
  4. Add the result checks below the synthesis call.
    print(f"response_synthesizer={type(response_synthesizer).__name__}")
    print(f"contains_context={'support portal' in str(response)}")
    print(f"source_count={len(response.source_nodes)}")

    The implementation name confirms the selected mode, while the context and source checks confirm that synthesis consumed the controlled retrieved node.

  5. Compare the completed response_synth.py file with the consolidated source.
    response_synth.py
    from llama_index.core import get_response_synthesizer
    from llama_index.core.llms import MockLLM
    from llama_index.core.schema import NodeWithScore, TextNode
     
     
    nodes = [
        NodeWithScore(
            node=TextNode(text="Refund requests are handled by the support portal."),
            score=1.0,
        )
    ]
     
    response_synthesizer = get_response_synthesizer(
        response_mode="compact",
        llm=MockLLM(max_tokens=None),
    )
    response = response_synthesizer.synthesize(
        "Where are refund requests handled?",
        nodes=nodes,
    )
     
    print(f"response_synthesizer={type(response_synthesizer).__name__}")
    print(f"contains_context={'support portal' in str(response)}")
    print(f"source_count={len(response.source_nodes)}")
  6. Run the completed response synthesizer test.
    $ python response_synth.py
    response_synthesizer=CompactAndRefine
    contains_context=True
    source_count=1

    A different implementation name means response_mode did not select compact. A false context check or a source count other than 1 means the controlled node did not reach the synthesized response.