Skip to Content

Reference

Python reference

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

The Python SDK runs on Python 3.9 and later. Lynk methods are async, and each has a _sync twin for code without an event loop. Results are typed models.

Install

pip install docklee
from docklee import Dock, Lynk

Dock

Dock writes into a container or a memory space. See Configuration for its constructor 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"},
    end_user="user_8f2c",
)
ParameterTypeDefaultDescription
contentstrnoneThe text to store.
typestr"conversation"conversation, document, event, preference, entity, or knowledge.
metadatadictNoneYour own key and value pairs.
dedup_keystrNoneYour own key for deciding when two captures are the same.
end_userstrthe Dock defaultThe person this memory belongs to.

Returns None. Raises RuntimeError if the Dock is closed.

flush_sync

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

result = dock.flush_sync()
if result is not None:
    print(result.accepted, result.rejected)

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

flush

The async form of flush_sync. It raises on failure instead of returning None.

result = await dock.flush()

close

Sends the buffer, closes connections, and stops the Dock from accepting more captures.

await dock.close()

instrument

Attaches a middleware to a FastAPI, Starlette, or other Starlette-based app that captures write requests. See Instrument your app.

dock.instrument(app)

watch

Starts a background thread that captures new and changed rows from database tables. See Watch a database.

dock.watch(connection_string=os.environ["ORDERS_DATABASE_URL"], tables=["orders"])
ParameterTypeDefault
connection_stringstrnone
tableslist[str]none
poll_intervalint5
capture_insertsboolTrue
capture_updatesboolTrue

listen

Starts a background thread that receives webhooks and captures them. See Listen for webhooks.

dock.listen(port=8080, secret=os.environ["WEBHOOK_SIGNING_SECRET"])
ParameterTypeDefault
portint8080
parsersdict[str, str]None
secretstrNone

Lynk

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

query and query_sync

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

result = await lynk.query("What is the refund window?")
result = lynk.query_sync("What is the refund window?", mode="blended")
ParameterTypeDefaultDescription
questionstrnoneThe question.
engine_idstrthe Lynk defaultThe engine to ask.
top_kint8Chunks to search for, from 1 to 50.
modestr"precise"See Answer modes.
streamboolFalsequery only. Returns an async iterator of answer text.

Returns a KnowledgeResult, or an async iterator of str when stream=True. Raises ValueError when no engine ID is set.

stream = await lynk.query("Summarize the refund policy.", stream=True)
async for token in stream:
    print(token, end="", flush=True)

retrieve and retrieve_sync

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

chunks = lynk.retrieve_sync("refund window", top_k=5)
ParameterTypeDefaultDescription
questionstrnoneThe question.
engine_idstrthe Lynk defaultThe engine to search.
top_kint8Chunks to return, from 1 to 100.

Returns a list of KnowledgeChunk. Raises ValueError when no engine ID is set.

recall and recall_sync

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

records = lynk.recall_sync("display preferences", end_user="user_8f2c")
ParameterTypeDefaultDescription
querystrnoneThe question.
memory_space_idstrthe Lynk defaultThe space to read.
top_kint5Memories to return, from 1 to 50.
end_userstrthe Lynk defaultReturns only this person's memories.

Returns a list of MemoryRecord. Raises ValueError when no memory space ID is set.

close

Closes connections.

await lynk.close()

Logging

The SDK logs through the standard logging module, under docklee.dock, docklee.lynk, and docklee.http. Turn on debug logging to see retries and skipped duplicates:

import logging

logging.getLogger("docklee").setLevel(logging.DEBUG)

Next steps

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

On this page