Skip to Content

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

OptionPythonTypeScriptDefaultDescription
Questionquestionfirst argumentnoneThe question, in plain words.
Engineengine_idengineIdDOCKLEE_ENGINE_IDThe engine to ask for this call.
Chunks searchedtop_ktopK8How many chunks to search for, from 1 to 50.
ModemodemodepreciseHow strictly to stay within your sources. See Answer modes.
StreamstreamstreamFalseSend the answer token by token. See Streaming answers.

Over HTTP, the mode field is query_mode.

The result

PythonTypeScriptHTTPDescription
answeransweranswerThe answer, written from your sources.
confidenceconfidenceconfidenceHow well the sources support the answer, from 0 to 1.
citationscitationscitationsThe 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.

On this page