KOS — FRD: Query Engine¶
KOS — FRD: Query Engine¶
Parent: KOS PRD
Owner: Digital Office
Status: Phase 1b
Overview¶
The query engine retrieves relevant knowledge from the graph and optionally synthesises a prose answer using a local LLM.
Functional Requirements¶
FR-QRY-01: Hybrid Retrieval¶
Queries MUST use Graphiti's hybrid search: semantic similarity + BM25 keyword + graph traversal.
FR-QRY-02: Query Modes¶
| Mode | Description | Used By |
|---|---|---|
| Raw | Returns structured chunks + citations, no LLM | Agent API |
| Synthesised | LLM composes a cited prose answer | Chat UI |
FR-QRY-03: Authority Filtering¶
Callers MAY specify min_authority_score (0.0-1.0) to exclude low-authority sources from results.
FR-QRY-04: Jurisdiction Filtering¶
Callers MAY specify jurisdiction_filter (list of ISO codes). Validated against the systems catalogue. Invalid codes return 400.
FR-QRY-05: Wiki Context Injection¶
If a compiled wiki is available, relevant pre-compiled pages are injected into the retrieval context before LLM synthesis. Keyword scoring with section weighting (jurisdictions 1.4x, systems 1.2x).
FR-QRY-06: Web Search Fallback¶
If internal retrieval confidence is below 0.5 AND the request is in synthesised mode, a DuckDuckGo search is performed as supplementary context. Results are clearly labelled as external.
FR-QRY-07: Confidence Scoring¶
Every query result carries a confidence score: min(citations / 3, 1.0). This is a heuristic — not a calibrated probability.
FR-QRY-08: Conflict Tracking¶
Citation conflicts (contradictory facts from different sources) are tracked in the result. Resolution logic is deferred to Phase 2.
FR-QRY-09: Audit¶
Every query is logged: question, answer, mode, citations, confidence, latency_ms, audit_id.
Performance Requirements¶
| Metric | Target |
|---|---|
| Raw query P95 latency | < 500ms |
| Synthesised query P95 latency | < 10s (LLM-bound) |
| Wiki context lookup | < 100ms |