Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Const

LlamaIndex

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.

How it works

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.

Syntax

toUIMessageStream(stream)

Returns

A UI message stream response suitable for returning to an AI SDK client.

Key points

  • LlamaIndex provides the application framework, while the AI SDK adapter handles interoperability with UI streaming.
  • It is useful when an application must retrieve and work with private or specialized data.
  • The TypeScript implementation targets current JavaScript runtimes, including Node.js, Deno, and Bun.
  • Install and import the dedicated @ai-sdk/llamaindex package for the integration.
  • A ChatEngine can supply the adapter input through its streaming chat method.
  • A QueryEngine can also supply compatible streamed output through its query method.

Example: Adapt a ChatEngine stream

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.

When to use it

Stream chat completions

An AI SDK web application needs incremental answers from a LlamaIndex ChatEngine.

Stream query results

A retrieval application uses a LlamaIndex QueryEngine and needs AI SDK UI compatibility.

Build domain-specific LLM applications

A project combines private-data retrieval with modern JavaScript application runtimes.

Interview questions

QWhat problem does the LlamaIndex adapter solve?

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.

QHow do you adapt a ChatEngine 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.

QWhy combine LlamaIndex with the AI SDK?

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/llamaindex
  • toUIMessageStream
  • createUIMessageStreamResponse
  • ChatEngine
  • QueryEngine
  • useCompletion

Source: LlamaIndex. Checked 2026-10-15.