CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-llamaindex

Data framework for your LLM application

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

response-synthesis.mddocs/

Response Synthesis

Response generation and synthesis strategies for combining retrieved information into coherent answers in LlamaIndex.TS.

Import

import { ResponseSynthesizer } from "llamaindex";

Overview

Response synthesis combines retrieved information from multiple sources into coherent, comprehensive answers using various strategies optimized for different use cases.

Base Synthesizer Interface

interface BaseSynthesizer {
  synthesize(query: string, nodes: BaseNode[]): Promise<EngineResponse>;
}

Response Synthesizer

class ResponseSynthesizer implements BaseSynthesizer {
  constructor(options?: {
    responseMode?: ResponseMode;
    serviceContext?: ServiceContext;
  });
  
  synthesize(query: string, nodes: BaseNode[]): Promise<EngineResponse>;
  
  responseMode: ResponseMode;
}

type ResponseMode = "refine" | "compact" | "tree_summarize" | "simple_summarize";

Response Modes

Tree Summarize

Best for comprehensive answers from multiple sources.

const treeSynthesizer = new ResponseSynthesizer({
  responseMode: "tree_summarize",
});

Refine Mode

Iteratively refines answers with each chunk.

const refineSynthesizer = new ResponseSynthesizer({
  responseMode: "refine",
});

Compact Mode

Combines chunks to maximize context usage.

const compactSynthesizer = new ResponseSynthesizer({
  responseMode: "compact",
});

Usage with Query Engines

import { RetrieverQueryEngine, ResponseSynthesizer } from "llamaindex";

const queryEngine = new RetrieverQueryEngine({
  retriever: index.asRetriever(),
  responseSynthesizer: new ResponseSynthesizer({
    responseMode: "tree_summarize",
  }),
});

Factory Function

function createResponseSynthesizer(mode: ResponseMode): BaseSynthesizer;

Best Practices

// Choose mode based on use case
const synthesizer = createResponseSynthesizer(
  documents.length > 10 ? "tree_summarize" : "refine"
);

docs

chat-engines.md

document-processing.md

embeddings.md

index.md

llm-integration.md

query-engines.md

response-synthesis.md

settings.md

storage.md

tools.md

vector-indexing.md

tile.json