Pagination
Cursor-based enumeration on the HTTP tier, frame-based streaming on the wire, and the terminator each one uses.
HTTP: cursors
Every listing verb takes limit and cursor, and returns nextCursor.
limitnumberoptionalPage size. The server caps it — ask for more and you get the cap, not an error.
cursorstringoptionalOpaque. Pass back exactly what the previous page returned. Do not parse, construct, or persist one across a schema change.
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
| Verb | Returns |
|---|---|
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:
listEntities(request)concatenatedAwaits the whole stream and returns one flat array. Simplest, and what you want when the result is small.
listEntitiesFrames(request)per-frameReturns 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);Abandoning the promise does not stop the server computing. Call
cancelStream with the stream
id when you bail out of a long enumeration.
Was this page helpful?