Brain Docs

Reference

TypeScript SDKInstallationHTTP clientWire client
ErrorsRetriesPagination
Brain/Docs
✦ ASKBrain on GitHubDashboard
TypeScript SDKPagination

Pagination

Cursor-based enumeration on the HTTP tier, frame-based streaming on the wire, and the terminator each one uses.

PURPOSE

Brain never returns an unbounded list. The two tiers bound them differently: the HTTP tier pages with an opaque cursor, the wire tier streams frames. This page documents both, and the termination rule that is easy to get wrong.

HTTP: cursors

Every listing verb takes limit and cursor, and returns nextCursor.

ParameterTypeRequired
limitnumberoptional

Page size. The server caps it — ask for more and you get the cap, not an error.

cursorstringoptional

Opaque. Pass back exactly what the previous page returned. Do not parse, construct, or persist one across a schema change.

An absent nextCursor is the terminator — not an empty page

items.length === 0 is a valid intermediate page: a filter can exclude everything on one page while later pages still have rows. Stop when nextCursor is undefined, never when the page came back empty.

async function* allMemories(brain: BrainHttpClient) {
  let cursor: string | undefined;
  do {
    const page = await brain.memoryList({ limit: 200, cursor });
    yield* page.items;
    cursor = page.nextCursor;
  } while (cursor !== undefined);
}

Which verbs page

VerbReturns
memoryList{ items, nextCursor? }
listEntities{ entities, count, nextCursor? }
listStatements{ statements, count, nextCursor? }
statementHistory{ items, chainRoot, totalVersions, nextCursor? }
listRelations{ relations, nextCursor? }
graphFetch{ nodes, edges, nextCursor? }
listSchemas{ namespace, items, total, nextCursor? }

listSpaces, listSessions and listExtractors take a limit but do not page — they return the whole bounded set. listSpaces instead reports crossShardComplete, which is a different kind of incompleteness: not "there is more", but "this listing covered one shard".

Wire: frames

The wire tier streams. Every enumerating verb has two forms:

OptionTypeDefault / Env
listEntities(request)concatenated

Awaits the whole stream and returns one flat array. Simplest, and what you want when the result is small.

listEntitiesFrames(request)per-frame

Returns the frames as they arrived, so you can render progressively or read the per-frame counters.

The pairs: memoryList, graphFetch, recall, plan, reason, statementHistory, traverseRelations, listEntities, listStatements, listRelationsFrom, listRelationsTo, listSchemas.

Wire cursors are Uint8Array, not strings, and the wire listing requests carry filters the HTTP tier does not expose — timeAxis and a record/event time range on memoryList, time ranges on the statement and relation listings.

const frames = await client.listEntitiesFrames({
  entityTypeId: personTypeId,
  namePrefix: "",
  mentionCountMin: 2,
  includeTombstoned: false,
  includeMerged: false,
  limit: 500,
  cursor: new Uint8Array(),
});

for (const f of frames) render(f.items);
Cancel a stream you stopped reading

Abandoning the promise does not stop the server computing. Call cancelStream with the stream id when you bail out of a long enumeration.

See also
Memories and edgesEntitiesSubscriptions

Was this page helpful?

Retries

Both retry layers — the HTTP client's built-in policy with its idempotent-only verb list, and the wire tier's backoff primitives.

Python SDK

The hand-written Python client for Brain — two clients over one verb vocabulary, and every operation's reference page.

On this page

HTTP: cursorsWhich verbs pageWire: frames
Suggest an editOpen in Playground