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 dockleeimport { 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',
});| Option | Type | Default | Description |
|---|---|---|---|
type | 'conversation' | 'document' | 'event' | 'preference' | 'entity' | 'knowledge' | 'conversation' | What kind of event this is. |
metadata | Record<string, unknown> | none | Your own key and value pairs. |
dedupKey | string | none | Your own key for deciding when two captures are the same. |
endUser | string | the Dock default | The 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;| Option | Type | Default | Description |
|---|---|---|---|
engineId | string | the Lynk default | The engine to ask. |
topK | number | 8 | Chunks to search for, from 1 to 50. |
mode | string | 'precise' | See Answer modes. |
stream | boolean | false | Returns 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 });| Option | Type | Default | Description |
|---|---|---|---|
engineId | string | the Lynk default | The engine to search. |
topK | number | 8 | Chunks 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' });| Option | Type | Default | Description |
|---|---|---|---|
memorySpaceId | string | the Lynk default | The space to read. |
topK | number | 5 | Memories to return, from 1 to 50. |
endUser | string | the Lynk default | Returns 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.