Stream chat completions
An AI SDK web application needs incremental answers from a LlamaIndex ChatEngine.
AI Tools · Const
The LlamaIndex adapter connects LlamaIndex ChatEngine or QueryEngine streams to AI SDK UI integrations. Use @ai-sdk/llamaindex to convert engine output into a client-consumable UI message stream.
The @ai-sdk/llamaindex adapter bridges LlamaIndex engine output with the AI SDK UI streaming model. Pass the asynchronous result from a ChatEngine chat call or QueryEngine query call to toUIMessageStream, then wrap that stream with createUIMessageStreamResponse for delivery to an AI SDK client.
toUIMessageStream(stream)A UI message stream response suitable for returning to an AI SDK client.
@ai-sdk/llamaindex package for the integration.chat method.query method.import { toUIMessageStream } from '@ai-sdk/llamaindex';
import { createUIMessageStreamResponse } from 'ai';
const stream = await chatEngine.chat({
message: prompt,
stream: true,
});
return createUIMessageStreamResponse({
stream: toUIMessageStream(stream),
});Converts a LlamaIndex ChatEngine stream into an AI SDK UI message stream response.
An AI SDK web application needs incremental answers from a LlamaIndex ChatEngine.
A retrieval application uses a LlamaIndex QueryEngine and needs AI SDK UI compatibility.
A project combines private-data retrieval with modern JavaScript application runtimes.
The adapter connects LlamaIndex engine streams to AI SDK UI streaming. Its current package is @ai-sdk/llamaindex, and the stream is converted with toUIMessageStream before creating the response.
Follow-up: How would you support a QueryEngine? Pass the asynchronous result of its query method to the same conversion flow, then return it through an AI SDK UI message response.
A ChatEngine produces a stream through its chat method when called with streaming enabled. The adapter transforms that stream so AI SDK UI functions can consume it.
Follow-up: Why should the call use streaming? Because the adapter is intended to pipe incremental engine output to the client rather than wait for one completed result.
LlamaIndex is a framework for building LLM-powered applications that can ingest, structure, and access private or domain-specific data. The adapter lets that framework work with AI SDK UI integrations.
Follow-up: Which runtimes does LlamaIndex.TS target? The page identifies modern JavaScript runtimes such as Node.js, Deno, and Bun.
@ai-sdk/llamaindextoUIMessageStreamcreateUIMessageStreamResponseChatEngineQueryEngineuseCompletion