Getting Started
Python quickstart
Install the Python SDK, store a memory, recall it, and query an engine from Python in a few minutes.
In a few minutes you'll install docklee, write a memory with Dock, read it back with Lynk, and ask an engine a question, all from Python.
Prerequisites
- Python 3.9+.
- An API key with the Both capability. See API keys.
- A memory space ID from DUM, and an engine ID from Knowledge Engines, in the Docklee dashboard.
Store and recall from Python
Install the package
pip install dockleeSet your environment
export DOCKLEE_API_KEY="your-api-key"
export DOCKLEE_MEMORY_SPACE_ID="your-memory-space-id"
export DOCKLEE_ENGINE_ID="your-engine-id"Dock and Lynk read these on creation, so your code never holds the key.
Write a memory
capture returns at once. flush_sync() sends the buffer and waits for the result:
from docklee import Dock
dock = Dock()
dock.capture("Maya prefers email over phone calls.", type="preference", end_user="user_8f2c")
result = dock.flush_sync()
print(result.accepted, result.rejected)1 0Recall it
from docklee import Lynk
lynk = Lynk()
for record in lynk.recall_sync("How does Maya like to be contacted?", end_user="user_8f2c"):
print(record.confidence, record.content)0.87 Maya prefers email over phone calls.Ask an engine
result = lynk.query_sync("What is the refund window?")
print(result.answer)Customers can request a refund within 30 days of purchase.Use it from async code
Every Lynk method has an async form, and Dock has flush and close. In an async app, such as FastAPI, use those instead of the _sync methods:
import asyncio
from docklee import Dock, Lynk
async def main() -> None:
dock = Dock()
lynk = Lynk()
dock.capture("Maya renewed her plan.", type="event", end_user="user_8f2c")
await dock.flush()
records = await lynk.recall("What did Maya do recently?", end_user="user_8f2c")
answer = await lynk.query("What is the refund window?")
print(records, answer.answer)
await dock.close()
await lynk.close()
asyncio.run(main())Close Dock before your process exits, or call flush_sync(). Events still in the buffer are never sent.
Next steps
You've used every part of the SDK once. Start with configuration, since every app sets it up a little differently.