# Knowledge

Where Liya's answers come from: ingested sources, approved articles, feedback, gap reports and integrity checks.

## Sources of knowledge

- **Connector sources:** mailboxes, CSV exports, Jira and ServiceNow history, synced with `POST /api/sources/{id}/sync`.
- **Mail archives:** `POST /api/mailserver/ingest`, or `ingest_full.py` for a large one-time backfill.
- **Articles:** written by people, or drafted by Liya Scribe from resolved tickets.

## Review article drafts

1. Open the **Inbox** (Home's **Needs attention**, then **View all**, or `/inbox`) and pick the **Drafts** lane. Choose **Draft now** to have Liya Scribe draft from recently resolved tickets.
2. Open a draft in the drawer, edit it (`PATCH /api/kb/articles/{id}`), then approve or reject it with a reason (`POST /api/kb/articles/{id}/approve` or `/reject`).
3. Approved articles are used for answers straight away.

> [!NOTE]
> Nothing Liya Scribe writes is used until a person approves it.

## Improve answers

| Tool | What it tells you | Endpoint |
| --- | --- | --- |
| Feedback | Thumbs on each recommendation | `POST /api/recommendations/{ref_id}/feedback` |
| Gaps | Questions nothing answered well | `GET /api/kb/gaps` |
| Quarantine | Items disliked 3 times are taken out of use (`TICKETIQ_KB_QUARANTINE_AFTER_DISLIKES`, 0 for never) | `POST /api/kb/{ref_id}/quarantine` |
| Evaluation | Retrieval quality against a question bank, daily by default | `GET` / `POST /api/kb/eval` |
| Integrity | Checks the index matches the source records | `POST /api/kb/integrity/run` |

Thresholds: an answer is quoted directly at similarity 0.76 (`TICKETIQ_KB_QUOTE_THRESHOLD`) and listed as related at 0.66 (`TICKETIQ_KB_RELATED_THRESHOLD`).

## Sensitivity

Each item carries a label (public, internal, confidential, restricted). A channel only retrieves items at or below its ceiling. See [Redaction](/docs/govern/redaction).

## Citations and sources

When Liya answers from your data, each citation leads back to the item in your own system as well as to the copy the answer quoted. Every item records where it lives when it is ingested: the system, the item's own key there and its address.

| Source | Key | Link to the original |
| --- | --- | --- |
| Jira (Cloud and Data Center) | Issue key | `{base URL}/browse/{KEY}` |
| ServiceNow incident or other table | Record number | `{instance}/nav_to.do?uri={table}.do?sys_id={sys_id}` |
| ServiceNow knowledge | KB number | `{instance}/kb_view.do?sysparm_article={number}` |
| REST API, SQL, SQLite, CSV | Record key or row | The source's [link template](/docs/connect/erp-sql#link-to-the-original-record), if set |
| Email | Message-ID | None. Email has no address. |
| Files | File name | The console's **Files** page |
| Approved articles | `KBA-<id>` | The article in the console |
| HR policies | Policy reference | The policy's own page, if its entry or the HR link template has one |
| Tickets opened in TicketIQ | Ticket ID | The ticket in the console |

How each surface shows it:

- **Microsoft Teams and web chat.** Each citation opens a signed, expiring page with the full copy. When the original is known, the page leads with **Open in Jira ↗** (or ServiceNow, the ERP and so on) and the item's key, and notes that opening it needs access in that system. The copy works for people without a console account. A link is signed for the workspace that cited the source, and never opens another workspace's source.
- **Console and co-pilot.** Fix cards and the co-pilot's similar cases link the original directly. A ticket imported from Jira or ServiceNow shows **Original** in its details.
- **Answer API, MCP and A2A.** Each recommendation carries `source_system`, `source_key` and `source_url`. A2A answers that quote sources carry them in a `citations` data part and in the task metadata.

Links are withheld in these cases:

- The item was quarantined, retracted or kept out of the knowledge base.
- On surfaces that answer people outside the service desk, the item is labelled at or above the level that PII and secrets raise to (confidential by default).
- The address would carry a credential, personal data or a secret. Only `http` and `https` addresses are used.

On those surfaces the key is PII-masked like the text beside it, and a cited email shows no Message-ID. Records synced before keys and links were kept are backfilled once per source by the scheduler, without re-embedding. `POST /api/sources/{id}/relink` runs the backfill now.

## Research questions across the knowledge base

One search is not always enough. **Knowledge research** runs the steps a person would: search, read the closest entries, search again with what they mention (an error code, a product name), and answer only from what was read, citing it.

- **Research API.** `POST /api/kb/research` with `{"question": "...", "max_steps": 4}` returns the answer, its citations (entry refs), every source read, and each step's queries, hits and reads. The internal **Liya Research** agent plans each step through the governed path (its own binding, budget and transcript). An answer whose citations are not among the entries it read is refused, and the result abstains instead.
- **Agent tools.** Managed agents can be offered `kb_overview` (what collections there are and what they hold), `kb_search`, `kb_read` (one entry in full) and `kb_grep` (every entry containing literal terms such as `VPN-4012`, which similarity search can rank low). Every read is trimmed to the entries the person may see and scoped to the agent's tenant. They are **off by default**, so agents already in production keep the tools they have: set `TICKETIQ_KB_AGENT_TOOLS=true` to offer them. Cedar decides each call as `Tool::"ticketiq.knowledge/<op>"`.

### Extract fields from documents

`POST /api/kb/extract` fills a schema you declare (`{"po_number": {"type": "string", "required": true}, "amount": "number"}`) from a document. Every value comes back with the exact words it was taken from; a value whose quote is not in the document, or that does not fit its type, is left empty and flagged rather than guessed.

Send `documents` (each `{id, title, text}`) and a `record_type` instead, with `sources.write`, and the complete results are stored as typed records. Ask them with a [metric model](/docs/connect/metric-layer) on that record type: schema at ingest, SQL at question time. A document missing a required field is not stored, so a total never includes a guess.

Research is audited as `kb.research` (the refs read and cited, never the question or answer) and extraction as `kb.extract` and `kb.extract.records`.

## Next steps

- [Data handling](/docs/govern/data-handling)

## Is it search or the answer?

Search evaluation asks whether the right entry came back. It cannot tell you whether a bad answer is search's fault or the model's. The **oracle gap** can. It asks each question twice: once with the gold passages (the entries the question was drawn from) and once with the top three passages search actually returned. Both answers are scored against the gold fix without a model. The score is the overlap of their content words, together with the share of the fix's codes and versions the answer carries.

`POST /api/kb/eval/oracle-gap` with `{"sample": 20}` runs it as a background job, and `GET /api/kb/eval/oracle-gap` reads the report:

| Field | Meaning |
|---|---|
| `oracle_quality`, `retrieved_quality` | Mean answer quality with the gold passages, and with what search found |
| `gap`, `gap_ci` | The difference between them, with a paired 95% interval: what perfect retrieval would be worth |
| `gap_when_missed` | The gap on the questions where search did not return the gold entry |
| `diagnosis` | How many questions are `retrieval` (the oracle answer is good and the retrieved one at least 0.2 worse), `generation` (even the oracle answer is poor, so the prompt or model is at fault), or `ok` |

Each question is two governed calls of the `kb-answer-eval` agent, with its own binding and budget. A run asks at most 100 questions.
