Core Concepts
Query an engine
Ask a question and get one answer from your own content, with citations and a confidence score.
lynk.query runs the whole pipeline in one call. The engine searches its linked sources, writes an answer from what it finds, and returns the answer with citations and a confidence score.
Ask a question
This example asks one question and prints the answer:
from docklee import Lynk
lynk = Lynk(engine_id="your-engine-id")
result = lynk.query_sync("What is the refund window?")
print(result.answer)
print(result.confidence)The answer comes back with the chunks it was drawn from:
{
"answer": "Customers can request a refund within 30 days of purchase. After 30 days, purchases can be exchanged for store credit.",
"citations": [
{
"chunk_id": "c2a8f5e1-7b39-4d6c-a014-8e3f2b9d61c7",
"page_number": 4,
"section_title": "Refunds and returns"
}
],
"confidence": 0.93
}query options
| Option | Python | TypeScript | Default | Description |
|---|---|---|---|---|
| Question | question | first argument | none | The question, in plain words. |
| Engine | engine_id | engineId | DOCKLEE_ENGINE_ID | The engine to ask for this call. |
| Chunks searched | top_k | topK | 8 | How many chunks to search for, from 1 to 50. |
| Mode | mode | mode | precise | How strictly to stay within your sources. See Answer modes. |
| Stream | stream | stream | False | Send the answer token by token. See Streaming answers. |
Over HTTP, the mode field is query_mode.
The result
| Python | TypeScript | HTTP | Description |
|---|---|---|---|
answer | answer | answer | The answer, written from your sources. |
confidence | confidence | confidence | How well the sources support the answer, from 0 to 1. |
citations | citations | citations | The chunks the answer is based on. |
Each citation identifies a chunk with chunk_id (chunkId) and page_number (pageNumber). Over HTTP it also carries section_title. See Citations and confidence.
When the answer isn't there
In the default mode, the engine doesn't guess. If your sources don't contain the answer, it says the information isn't available, with a confidence of 0.
result = lynk.query_sync("What is the CEO's home address?")
if result.confidence == 0:
print("No answer in the knowledge base.")Show the citations in your UI. People trust an answer more when they can open the page it came from.
Next steps
You can get a cited answer. To show it as it's written, stream it next.