MemorySyncMemorySync
Advanced

Explainability

For every query your application runs, MemorySync captures a structured, immutable record describing how the query was answered — which intent was detected, which knowledge path was used, which memories were selected, and whether the query was refused. These records are exposed through an admin-only API for audit, debugging, and recall-quality investigations.

The Explainability Contract

Every POST /memory/query call produces exactly one explanation record. The record is written asynchronously after the response is returned to the caller, so explainability never adds latency to the query itself. The captured fields are strictly structured — IDs, enum values, scores, and timestamps — with no free-text reasoning, prompts, or chain-of-thought.

Design invariants
  • Explainability is read-only. There is no API to create, modify, or delete records.
  • Capture happens after the response is returned, in a background task. Failures are swallowed and never affect the query result.
  • Records are immutable. No update or upsert path exists.
  • No free-text fields. No prose, no LLM output, no prompts are ever stored or exposed.

The Explanation Record

Every record contains the following structured fields, and only these fields:

FieldDescription
query_idUUID assigned to the query at request time. Use this to correlate explanation records with your own request logs.
query_timestampWhen the query was received.
processing_time_msTotal processing time for the query, in milliseconds.
intent_classificationThe detected intent: factual, analytical, hybrid, or conversational.
knowledge_pathWhich knowledge sources were used to answer the query: canonical, structured, hybrid, or refused.
confidence_scoreThe result confidence score (0.0–1.0) as computed by the retrieval pipeline. Read-only — never recomputed by explainability.
canonical_memory_idsIDs of canonical memories that were used to answer the query.
structured_source_idsIDs of structured knowledge rows that were used.
refusedWhether the query was refused.
refusal_reasonIf refused, one of low_confidence, missing_data, conflict_detected, policy_restricted, or ambiguous_intent. Null otherwise.
created_atWhen the explanation record itself was written.

Intent Classifications

Each query is classified into exactly one intent before retrieval runs. The intent steers routing inside the query pipeline:

IntentWhat it means
factualA direct lookup over canonical memories — e.g. “What is the user’s preferred timezone?”.
analyticalAn aggregation or computation over structured knowledge — e.g. “How many tickets were resolved last week?”.
hybridA question that requires both canonical memories and structured knowledge.
conversationalA free-form conversational query that may not have a single retrievable answer.

Knowledge Paths

The knowledge path describes which retrieval sources actually contributed to the answer. It is derived deterministically from the sources the pipeline consulted — there is no inference involved.

Knowledge PathMeaning
canonicalThe answer came from canonical memories only.
structuredThe answer came from structured knowledge only.
hybridBoth sources contributed.
refusedNo sources contributed because the query was refused before retrieval completed.

Refusal Reasons

When a query is refused, the record captures the reason as one of a small set of enumerated values. Refusal decisions are made by the query router before retrieval runs; explainability only records what happened.

ReasonWhen it is used
low_confidenceThe best-ranked result fell below the configured confidence threshold.
missing_dataNo relevant memories or rows exist to answer the query.
conflict_detectedMultiple candidate answers contradicted one another and no single answer could be selected.
policy_restrictedThe query violates a configured refusal policy for the project or organization.
ambiguous_intentThe query intent could not be resolved unambiguously.

API Endpoints

All explainability endpoints are admin-only and tenant-scoped. They live under /api/v1/explainability and require a JWT with admin privileges.

EndpointPurpose
GET /api/v1/explainability/explanationsList explanation records with paging and filters (intent, knowledge path, date range, user, refused-only).
GET /api/v1/explainability/explanations/{query_id}Fetch a single explanation record by query_id.
GET /api/v1/explainability/statsAggregated statistics over the last N days: total queries, breakdown by intent and knowledge path, refusal rate, average confidence, average processing time.
GET /api/v1/explainability/metricsInternal capture metrics: write success/failure counts and capture latency. Used to verify that explainability never blocks query execution.

All list and detail responses use the same structured field set described above. There is no field for free-text reasoning, prompt traces, or LLM output — by design.

Non-Blocking Capture

Explainability capture is intentionally decoupled from the query path:

  • Post-response. The query response is built and returned to the caller first. Only afterwards does the platform queue the explanation write.
  • Background task. The write executes in a background task and is independent of the caller’s connection.
  • Failure isolation. If the capture fails for any reason, the failure is logged and silently swallowed. The query result is never affected.
  • Verifiable. The metrics endpoint surfaces write success/failure counts and latency so operators can confirm capture health.

What Explainability Never Stores

Several categories of information are explicitly excluded from explanation records as a matter of design:

  • Raw query strings. Queries may contain PII; only the query_id appears in records.
  • Free-text reasoning or “why this answer” prose.
  • Prompts, prompt fragments, or any model-call payloads.
  • LLM output, chain-of-thought, or scratchpad content.
  • Decrypted memory content. Records only reference memories by ID.
Why structured-only?
Structured records are auditable, queryable, exportable, and safe to ship to SIEM systems. Free-text reasoning would leak content into observability infrastructure and could not be reliably redacted on data-subject deletion.