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 dockleefrom docklee import Dock, LynkDock
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",
)| Parameter | Type | Default | Description |
|---|---|---|---|
content | str | none | The text to store. |
type | str | "conversation" | conversation, document, event, preference, entity, or knowledge. |
metadata | dict | None | Your own key and value pairs. |
dedup_key | str | None | Your own key for deciding when two captures are the same. |
end_user | str | the Dock default | The 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"])| Parameter | Type | Default |
|---|---|---|
connection_string | str | none |
tables | list[str] | none |
poll_interval | int | 5 |
capture_inserts | bool | True |
capture_updates | bool | True |
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"])| Parameter | Type | Default |
|---|---|---|
port | int | 8080 |
parsers | dict[str, str] | None |
secret | str | None |
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")| Parameter | Type | Default | Description |
|---|---|---|---|
question | str | none | The question. |
engine_id | str | the Lynk default | The engine to ask. |
top_k | int | 8 | Chunks to search for, from 1 to 50. |
mode | str | "precise" | See Answer modes. |
stream | bool | False | query 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)| Parameter | Type | Default | Description |
|---|---|---|---|
question | str | none | The question. |
engine_id | str | the Lynk default | The engine to search. |
top_k | int | 8 | Chunks 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")| Parameter | Type | Default | Description |
|---|---|---|---|
query | str | none | The question. |
memory_space_id | str | the Lynk default | The space to read. |
top_k | int | 5 | Memories to return, from 1 to 50. |
end_user | str | the Lynk default | Returns 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.