Explainability
beginnerUnderstand 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:
- Text Explanation — a simple, human-readable answer for end users and logs
- 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
| Field | Type | Description |
|---|---|---|
query | string | The natural-language query to explain. Required. |
lang | "en" | "fr" | null | Language for the explanation text. Defaults to null (auto-detect). |
Response fields
| Field | Type | Description |
|---|---|---|
explanation | string | A human-readable sentence explaining why the result matched. |
method | string | The similarity method used (e.g., "cosine_similarity"). |
confidence | float | A 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 range | Meaning | Action |
|---|---|---|
| 0.90 - 1.00 | Near-certain match | Trust fully, display to user |
| 0.75 - 0.89 | High confidence | Trust, but consider showing alternatives |
| 0.60 - 0.74 | Moderate confidence | Useful but verify — may need user confirmation |
| 0.40 - 0.59 | Low confidence | Weak match — ask user for clarification |
| 0.00 - 0.39 | Very low | Likely not relevant — don't show to user |
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
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
| Field | Type | Description |
|---|---|---|
pathway_chosen | string | Which pathway won the routing decision: "exact", "energy", or "attention". |
pathway_scores | object | Raw scores for each pathway. The highest score wins. |
surprise | float | How unexpected this result is given the query. Low = expected match. |
regime | string | Current operating regime (e.g., "normal", "novelty", "consolidation"). |
head_contributions | array of floats | How much each attention head contributed to the final decision. |
neuromodulation | object | signal (neuromodulatory activation) and gate (plasticity gate value). |
phi_b_validation | object | Geometric 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())| Level | Use case |
|---|---|
simple | One-line summary of the routing decision |
detailed | Pathway scores, head contributions, and regime info |
technical | Full internal state including neuromodulation and Phi-B validation |
Additional XAI endpoints
| Endpoint | Method | Description |
|---|---|---|
/v1/memory/xai/surprise | POST | Get the surprise score for a query/result embedding pair |
/v1/memory/xai/heads | GET | Current attention head weights |
/v1/memory/xai/routing | GET | Current routing decisions and pathway preferences |
/v1/memory/xai/report | GET | Comprehensive 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
| Scenario | Use |
|---|---|
| Show users why the AI remembered something | POST /v1/memory/text/explain |
| Log retrieval reasoning for audits | POST /v1/memory/text/explain |
| Debug why a wrong result was returned | POST /v1/memory/xai/explain |
| Understand pathway routing decisions | GET /v1/memory/xai/routing |
| Investigate unexpected or surprising matches | POST /v1/memory/xai/surprise |
| Compliance report for stakeholders | GET /v1/memory/xai/report |
| Tune attention head behavior | GET /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