Skip to Content

Reference

TypeScript reference

Every class and method in the TypeScript SDK, with its options and what it returns.

The TypeScript SDK runs on Node.js 18 and later, using the built-in fetch. Every network method returns a promise. It ships ES module and CommonJS builds with TypeScript definitions.

Install

npm install docklee
import { Dock, Lynk } from 'docklee';

Call the SDK from your server. An API key in browser code can be read by anyone who opens the page.

Dock

Dock writes into a container or a memory space. See Configuration for its options.

capture

Adds an event to the buffer and returns at once. Blank content is ignored, and identical content within 60 seconds is skipped.

dock.capture('Customer asked to move the renewal date to June.', {
  type: 'event',
  metadata: { ticket_id: 'T-4821' },
  endUser: 'user_8f2c',
});
OptionTypeDefaultDescription
type'conversation' | 'document' | 'event' | 'preference' | 'entity' | 'knowledge''conversation'What kind of event this is.
metadataRecord<string, unknown>noneYour own key and value pairs.
dedupKeystringnoneYour own key for deciding when two captures are the same.
endUserstringthe Dock defaultThe person this memory belongs to.

Returns void. Throws if the Dock is closed.

flush

Sends the buffer and waits. On failure, the events go back into the buffer for the next flush.

const result = await dock.flush();
if (result) {
  console.log(result.accepted, result.rejected);
}

Returns a DockIngestResult, or null when the buffer was empty or the request failed.

The buffer is also sent every flushInterval milliseconds, 5,000 by default.

close

Stops the timer and sends the buffer. Call it when you're done, so your process can exit.

await dock.close();

instrument

Attaches a middleware to an Express app, or any app with Express-style use middleware, that captures write requests. Register your body parser first. See Instrument your app.

app.use(express.json());
dock.instrument(app);

Lynk

Lynk reads from an engine or a memory space. See Configuration for its options.

query

Asks an engine a question and returns a cited answer. See Query an engine.

import { Lynk, type KnowledgeResult } from 'docklee';

const lynk = new Lynk();
const result = (await lynk.query('What is the refund window?', { mode: 'blended' })) as KnowledgeResult;
OptionTypeDefaultDescription
engineIdstringthe Lynk defaultThe engine to ask.
topKnumber8Chunks to search for, from 1 to 50.
modestring'precise'See Answer modes.
streambooleanfalseReturns an async generator of answer text.

Returns Promise<KnowledgeResult | AsyncGenerator<string>>. Cast the result to the shape that matches stream. Throws when no engine ID is set.

const stream = (await lynk.query('Summarize the refund policy.', {
  stream: true,
})) as AsyncGenerator<string>;
for await (const token of stream) {
  process.stdout.write(token);
}

retrieve

Returns the ranked chunks for a question, without writing an answer. See Retrieve context.

const chunks = await lynk.retrieve('refund window', { topK: 5 });
OptionTypeDefaultDescription
engineIdstringthe Lynk defaultThe engine to search.
topKnumber8Chunks to return, from 1 to 100.

Returns Promise<KnowledgeChunk[]>. Throws when no engine ID is set.

recall

Returns the memories that answer a question. See Recall memory.

const records = await lynk.recall('display preferences', { endUser: 'user_8f2c' });
OptionTypeDefaultDescription
memorySpaceIdstringthe Lynk defaultThe space to read.
topKnumber5Memories to return, from 1 to 50.
endUserstringthe Lynk defaultReturns only this person's memories.

Returns Promise<MemoryRecord[]>. Throws when no memory space ID is set.

Types

Import the result and option types alongside the classes:

import type {
  Citation,
  DockConfig,
  DockIngestResult,
  KnowledgeChunk,
  KnowledgeResult,
  LynkConfig,
  MemoryRecord,
} from 'docklee';

See Types for every field.

Next steps

You've seen every TypeScript method. See the shapes they return next.

On this page