Skip to content

Abstract Class: IngestionSessionHandle

@kortexya/reasoninglayer


@kortexya/reasoninglayer / IngestionSessionHandle

Defined in: src/resources/ingestion-session.ts:199

What a handle of a queued ingestion session shares, whether the session tracks one document or a batch.

Provides methods to poll for completion, check progress, and retrieve final stats. Wraps the session tracking endpoints. The handle does not hold an open connection: every method is an independent HTTP request.

The engine derives the session status from the statuses of its documents: active while any document is pending or in progress, then failed if any document failed, else complete.

function track(handle: IngestionSessionHandle) {
return handle.waitForCompletion({ pollIntervalMs: 3000 });
}

readonly sessionId: string

Defined in: src/resources/ingestion-session.ts:201

The session ID (UUID).


readonly status: string

Defined in: src/resources/ingestion-session.ts:204

The status at enqueue time. The engine always sends "pending".


readonly statusUrl: string

Defined in: src/resources/ingestion-session.ts:207

Path of the session resource (/api/v1/ingest/sessions/<sessionId>).

getDocumentStats(documentId, requestOptions?): Promise<DocumentStatsDto | null>

Defined in: src/resources/ingestion-session.ts:315

Get the stats of one document of the session.

string

The document’s session-tracking id (the documentId the 202 answer, or DocumentStatsDto.documentId, names).

RequestOptions

Per-call request options.

Promise<DocumentStatsDto | null>

The document’s stats once it completed, or null while it is still pending or in progress (HTTP 204).

404 if the session or the document does not exist, the document is an RDF import (its receipt is on IngestionSessionHandle.getSession), or it completed without recording stats.

409 if the document failed or was cancelled; the reason is documents[].error on IngestionSessionHandle.getSession.

Maps to GET /api/v1/ingest/sessions/{session_id}/documents/{document_id}/stats. The engine publishes DocumentStatsDto as the 200 body; a 204 (still pending or in progress) reads as null. DocumentStatsDto.alreadyIngested tells a duplicate upload from a fresh ingestion.

const stats = await session.getDocumentStats(documentId);
if (stats?.alreadyIngested) console.log(`already in the library as ${stats.documentTermId}`);

getProgress(requestOptions?): Promise<SessionProgressResponse>

Defined in: src/resources/ingestion-session.ts:263

Get live pipeline progress for all documents in the session.

RequestOptions

Promise<SessionProgressResponse>

Progress snapshots for each document being processed.

Maps to GET /api/v1/ingest/sessions/{session_id}/progress. Returns real-time counters, current pipeline step, and step log.


getSession(requestOptions?): Promise<IngestionSessionDetailResponse>

Defined in: src/resources/ingestion-session.ts:246

Get the current session details: status, document counts, and every document with how its ingestion ended.

RequestOptions

Per-call request options.

Promise<IngestionSessionDetailResponse>

The session, with documents[]: each document’s status, its failure reason (error) and, once complete, its receipt.

404 if the session does not exist.

If the request fails.

Maps to GET /api/v1/ingest/sessions/{session_id}. A receipt is tagged by kind: markdown carries the document stats, rdf the RDF import counts (an RDF document has no other stats route).

const session = await handle.getSession();
for (const doc of session.documents) {
if (doc.receipt?.kind === 'rdf') console.log(`${doc.receipt.sortsCreated} sorts`);
}

getStats(requestOptions?): Promise<SessionStatsResponse>

Defined in: src/resources/ingestion-session.ts:280

Get stats for all completed documents in the session.

RequestOptions

Promise<SessionStatsResponse>

Per-document stats (term IDs, sort names, token usage, etc.).

Maps to GET /api/v1/ingest/sessions/{session_id}/stats. May be empty if no documents have completed yet.


waitForCompletion(options?): Promise<SessionStatsResponse>

Defined in: src/resources/ingestion-session.ts:351

Poll the session until it completes or fails, then return final stats.

IngestionPollOptions

Polling configuration (interval, timeout, progress callback, abort signal).

Promise<SessionStatsResponse>

Final session stats once all documents are complete. These are the markdown pipeline’s stats: an RDF document has none, so for an ingestRdf session use IngestionSessionHandle.waitForSession, whose documents carry the RDF receipt.

IngestionFailedError If the session status becomes "failed".

TimeoutError If timeoutMs is exceeded.

ReasoningLayerError If the abort signal is triggered.

const stats = await session.waitForCompletion({
pollIntervalMs: 2000,
timeoutMs: 300_000,
onProgress: (p) => {
const doc = p.documents[0];
if (doc) console.log(`${doc.currentStepLabel} — chunk ${doc.chunksProcessed}/${doc.totalChunks}`);
},
});
console.log(`Created ${stats.documents[0]?.termIds.length} terms`);

Polls getSession() to check status, and calls onProgress with live progress data between checks. Terminal states are "complete" and "failed".


waitForSession(options?): Promise<IngestionSessionDetailResponse>

Defined in: src/resources/ingestion-session.ts:382

Poll the session until it completes or fails, then return the session with every document’s receipt.

IngestionPollOptions

Polling configuration (interval, timeout, progress callback, abort signal).

Promise<IngestionSessionDetailResponse>

The completed session. Each document carries its receipt: kind: 'markdown' with the document stats, or kind: 'rdf' with the RDF import counts.

IngestionFailedError If the session status becomes "failed"; its session.documents[].error names each reason.

TimeoutError If timeoutMs is exceeded.

ReasoningLayerError If the abort signal is triggered.

Polls getSession() the same way IngestionSessionHandle.waitForCompletion does, and returns its last answer instead of fetching the markdown stats. Use it for an ingestRdf session queued with sync: false.

const handle = await client.ingestion.ingestRdf(request, { sync: false });
const session = await handle.waitForSession();
const receipt = session.documents[0]?.receipt;
if (receipt?.kind === 'rdf') console.log(`${receipt.termsCreated} terms`);