MemoryKit

Streaming

Stream RAG responses with Server-Sent Events for real-time UI updates.

Stream a query

POST /v1/memories/stream — Same as query but returns Server-Sent Events for real-time UI updates.

for await (const event of mk.memories.stream({
  query: "What happened in our last meeting?",
})) {
  if (event.event === "text") {
    process.stdout.write(event.data.content);
  }
  if (event.event === "sources") {
    console.log("Sources:", event.data);
  }
}

Event types

EventDescription
textA chunk of the generated answer
sourcesThe retrieved sources used for the answer
usageToken usage information
doneStream complete
errorAn error occurred

On this page