Skip to content

Explainability

beginner

Understand why a memory matched. Use the text explanation endpoint for human-readable answers, or the advanced XAI layer for debugging pathways, surprise scores, and attention heads.

Understand every result

When Engramma returns a memory, you can always ask why. Unlike black-box systems that return a similarity score with no context, Engramma provides explainability at two layers:

  1. Text Explanation — a simple, human-readable answer for end users and logs
  2. Advanced XAI — raw pathway diagnostics, attention head weights, and surprise scores for debugging and compliance

This matters for:

  • Debugging — understanding why the wrong result was returned
  • Trust — showing users why the AI "remembered" something
  • Compliance — enterprise requirements for explainable AI decisions

Layer 1: Text Explanation

The simplest way to understand a retrieval result. Send a natural-language query and get back a human-readable explanation with a confidence score.

Endpoint: POST /v1/memory/text/explain

import requests

response = requests.post(
    "https://api.engramma.ai/v1/memory/text/explain",
    headers={"X-API-Key": "your-api-key"},
    json={
        "query": "What's our cloud budget?",
        "lang": "en"
    }
)

data = response.json()
print(data["explanation"])
print(data["method"])
print(data["confidence"])

Response:

{
  "explanation": "The stored memory about AWS infrastructure costs closely matches your query about cloud spending. The match was found through direct semantic similarity between the query and the stored fact.",
  "method": "cosine_similarity",
  "confidence": 0.94
}

Request body

FieldTypeDescription
querystringThe natural-language query to explain. Required.
lang"en" | "fr" | nullLanguage for the explanation text. Defaults to null (auto-detect).

Response fields

FieldTypeDescription
explanationstringA human-readable sentence explaining why the result matched.
methodstringThe similarity method used (e.g., "cosine_similarity").
confidencefloatA score between 0 and 1 indicating match quality.

Understanding confidence scores

The confidence value from the text explanation endpoint tells you how strongly the query matched stored memories.

Score rangeMeaningAction
0.90 - 1.00Near-certain matchTrust fully, display to user
0.75 - 0.89High confidenceTrust, but consider showing alternatives
0.60 - 0.74Moderate confidenceUseful but verify — may need user confirmation
0.40 - 0.59Low confidenceWeak match — ask user for clarification
0.00 - 0.39Very lowLikely not relevant — don't show to user
Tip

The text explanation endpoint is the right choice for most applications. Use it to show users why the AI remembered something, or to log retrieval reasoning for audits.

Layer 2: Advanced XAI

The XAI layer works with raw embeddings, not text. It exposes the internal routing machinery: which pathway was chosen, how attention heads contributed, and how surprising the match was. Use this for:

  • Deep debugging of unexpected retrieval behavior
  • Compliance audits that need internal decision traces
  • Understanding the routing engine's pathway selection
Warning

The XAI endpoints accept and return embedding vectors. They are not meant for typical application code — they are diagnostic tools for developers and platform engineers.

Explain a query/result pair

Endpoint: POST /v1/memory/xai/explain

Send the raw embeddings of a query and result to see the full routing decision.

import requests

# query_embedding and result_embedding are vectors
# obtained from your retrieval pipeline
response = requests.post(
    "https://api.engramma.ai/v1/memory/xai/explain",
    headers={"X-API-Key": "your-api-key"},
    json={
        "query": query_embedding,
        "result": result_embedding
    }
)

data = response.json()
print(f"Pathway chosen: {data['pathway_chosen']}")
print(f"Pathway scores: {data['pathway_scores']}")
print(f"Surprise: {data['surprise']}")
print(f"Regime: {data['regime']}")
print(f"Head contributions: {data['head_contributions']}")
print(f"Neuromodulation: {data['neuromodulation']}")
print(f"Phi-B validation: {data['phi_b_validation']}")

Response:

{
  "pathway_chosen": "energy",
  "pathway_scores": {
    "exact": 0.23,
    "energy": 0.89,
    "attention": 0.45
  },
  "surprise": 0.34,
  "regime": "normal",
  "head_contributions": [0.4, 0.35, 0.25],
  "neuromodulation": {
    "signal": 0.67,
    "gate": 0.82
  },
  "phi_b_validation": {
    "geometric_surprise": 0.12,
    "valid": true
  }
}

XAI response fields

FieldTypeDescription
pathway_chosenstringWhich pathway won the routing decision: "exact", "energy", or "attention".
pathway_scoresobjectRaw scores for each pathway. The highest score wins.
surprisefloatHow unexpected this result is given the query. Low = expected match.
regimestringCurrent operating regime (e.g., "normal", "novelty", "consolidation").
head_contributionsarray of floatsHow much each attention head contributed to the final decision.
neuromodulationobjectsignal (neuromodulatory activation) and gate (plasticity gate value).
phi_b_validationobjectGeometric surprise metric and whether the result passes Phi-B validation.

Layered explanations

Endpoint: POST /v1/memory/xai/explain/layered

Get the XAI explanation formatted at a chosen detail level.

import requests

response = requests.post(
    "https://api.engramma.ai/v1/memory/xai/explain/layered",
    headers={"X-API-Key": "your-api-key"},
    json={
        "query": query_embedding,
        "result": result_embedding,
        "level": "detailed"
    }
)

print(response.json())
LevelUse case
simpleOne-line summary of the routing decision
detailedPathway scores, head contributions, and regime info
technicalFull internal state including neuromodulation and Phi-B validation

Additional XAI endpoints

EndpointMethodDescription
/v1/memory/xai/surprisePOSTGet the surprise score for a query/result embedding pair
/v1/memory/xai/headsGETCurrent attention head weights
/v1/memory/xai/routingGETCurrent routing decisions and pathway preferences
/v1/memory/xai/reportGETComprehensive XAI report for your tenant
response = requests.post(
    "https://api.engramma.ai/v1/memory/xai/surprise",
    headers={"X-API-Key": "your-api-key"},
    json={
        "query": query_embedding,
        "result": result_embedding
    }
)
print(response.json())

When to use which layer

ScenarioUse
Show users why the AI remembered somethingPOST /v1/memory/text/explain
Log retrieval reasoning for auditsPOST /v1/memory/text/explain
Debug why a wrong result was returnedPOST /v1/memory/xai/explain
Understand pathway routing decisionsGET /v1/memory/xai/routing
Investigate unexpected or surprising matchesPOST /v1/memory/xai/surprise
Compliance report for stakeholdersGET /v1/memory/xai/report
Tune attention head behaviorGET /v1/memory/xai/heads

Key concept: Pathways live in XAI

An important architectural distinction: the pathway concept (exact, energy, attention) only exists in the XAI layer. The text-level endpoints (/text/explain, /text/retrieve, /text/recall) do not expose pathway information — they give you a confidence score and a human-readable explanation.

If you need to know which pathway was used, you must call the XAI layer with the raw embeddings.

Next steps

  • Memory Types — Understand the three pathways that XAI diagnostics reference
  • Regimes — How regime state affects routing and confidence
  • API Reference — Full endpoint documentation