Abstract
Retrieval-Augmented Generation (RAG) systems predominantly retrieve information according to semantic or lexical relevance. Dense vector retrieval asks which stored representations are semantically closest to a query, while sparse retrieval identifies lexical correspondence. Graph-based approaches extend this model by explicitly representing entities and relationships. More recently, BasinRAG introduced a topological retrieval architecture based on functional graphs, dynamical basins of attraction, and topological confinement, demonstrating that retrieval can exploit the structural organization of information rather than treating chunks as independent observations.
This article proposes Causal-Topological Retrieval-Augmented Generation (CT-RAG), an architecture in which retrieval operates over an evolving memory terrain constructed from semantic proximity, temporal order, structural topology, and, crucially, observed causal relationships.
The central hypothesis is that, for stateful autonomous agents and event-driven systems, the most useful memory is not necessarily the memory most semantically similar to the current query. It may instead be the memory that explains how the system reached its current state.
Unlike approaches that infer relationships exclusively from textual similarity or LLM-generated knowledge graphs, CT-RAG exploits causal evidence already produced by execution: events, actions, transitions, intents, failures, retries, healing operations, and their consequences. These observations form a causal graph from which topological regions, basins, attractors, trajectories, and recurrent behavioral patterns can emerge.
Retrieval consequently becomes a problem of navigation through an experiential terrain, rather than nearest-neighbor search alone.
- Introduction
Retrieval-Augmented Generation solves an important limitation of Large Language Models: the model does not need to encode all relevant knowledge within its parameters if external information can be retrieved and inserted into its context.
The conventional architecture is approximately:
Documents → Chunks → Embeddings → Vector Search → Context → LLM
Given a query q, a dense retriever searches for stored chunks x_i maximizing semantic similarity:
[
R(q)=\operatorname{TopK}_{x_i}; sim(E(q),E(x_i))
]
where E represents an embedding function.
This formulation is effective but makes a strong implicit assumption:
«semantic proximity is a useful approximation of contextual relevance.»
Frequently it is. Frequently it is not.
Consider an autonomous agent executing the following process:
[
A \rightarrow B \rightarrow C \rightarrow H \rightarrow C' \rightarrow D
]
where C fails, H represents a healing operation, C' represents a successful re-execution, and D is the subsequent action.
Suppose that the agent later needs to understand why D has its current state.
The most semantically similar historical event may have little explanatory value. The relevant events are likely those located along the causal trajectory that produced D.
This distinction motivates CT-RAG.
Rather than asking only:
«What stored information resembles the current query?»
CT-RAG introduces two additional questions:
«Where in the memory terrain is the current problem located?»
and:
«What trajectory caused the system to arrive there?»
- From Vector Space to Information Topology
Dense retrieval already constructs a type of geometry.
Every item becomes a vector:
[
x_i \mapsto \mathbf{v}_i \in \mathbb{R}^d
]
and semantic similarity induces a metric landscape.
Concepts with similar representations occupy nearby regions.
This gives RAG systems a semantic geography, but not necessarily a topology corresponding to the history or structure of the underlying process.
Two events can be semantically distant while being causally adjacent.
For example:
[
PaymentAuthorized \rightarrow InventoryReserved
]
Their textual representations may differ substantially, while their causal distance can be exactly one transition.
Conversely:
[
PaymentAuthorized_t
]
and
[
PaymentAuthorized_{t-10000}
]
may be nearly identical in embedding space while belonging to completely unrelated executions.
Semantic distance and causal distance therefore encode fundamentally different information.
- BasinRAG and Topological Retrieval
An important motivation for this proposal comes from BasinRAG: High-Performance Topological Retrieval-Augmented Generation via Dynamical Basins, by Alex Martins, released in September 2026. The work introduces topological organization into retrieval using functional graphs, attractors, \rho-trees, and dynamical basins of attraction.
"BasinRAG repository" (https://reference-url-citation.invalid/1)
"BasinRAG publication — DOI 10.5281/zenodo.22664948" (https://reference-url-citation.invalid/2)
BasinRAG combines sparse BM25 retrieval, dense FAISS embeddings and the sequential topology of documents. Its functional graph \phi partitions information into basins of attraction, while semantic virtual edges can enrich the topology. During retrieval, lexical and dense results are fused using RRF and subsequently influenced by a topological hop prior.
Conceptually, this is significant because chunks cease to be completely independent retrieval units.
A relevant chunk provides information about the region in which retrieval should continue.
The architecture therefore moves from:
[
query \rightarrow nearest\ chunks
]
toward:
[
query \rightarrow relevant\ region \rightarrow local\ navigation
]
CT-RAG adopts this topological intuition but changes the nature of the underlying terrain.
- From Topological Retrieval to Causal-Topological Retrieval
BasinRAG derives useful topology primarily from document structure and semantic transitions.
For autonomous agents, distributed systems, workflows, event-sourced applications and other executable environments, another source of topology is available:
observed causality.
Consider an execution trace:
[
Intent
\rightarrow Action_A
\rightarrow Event_{A.Ok}
\rightarrow Action_B
\rightarrow Event_{B.Error}
\rightarrow Healing_B
\rightarrow Action_B'
\rightarrow Event_{B.Ok}
\rightarrow Action_C
]
These relationships do not need to be inferred from embeddings.
They occurred.
The system possesses evidence that one transition preceded and enabled another.
CT-RAG therefore proposes constructing a heterogeneous memory topology:
[
G=(V,E_s,E_c,E_t,E_b)
]
where:
- V represents memories, events, states, actions or observations;
- E_s represents semantic relationships;
- E_c represents causal relationships;
- E_t represents temporal relationships;
- E_b represents behavioral or execution relationships.
This produces a memory space in which several notions of distance coexist.
- Multiple Distances
For two memories x_i and x_j, CT-RAG can define:
[
d_s(x_i,x_j)
]
as semantic distance,
[
d_c(x_i,x_j)
]
as causal distance,
[
d_t(x_i,x_j)
]
as temporal distance, and
[
d_b(x_i,x_j)
]
as behavioral or execution distance.
A composite retrieval distance can then be expressed as:
[
D(x_i,x_j)=
\alpha d_s+
\beta d_c+
\gamma d_t+
\delta d_b
]
with weights determined dynamically according to retrieval intent.
This last property is important.
There should not necessarily be one universal terrain.
A factual query may prioritize semantic proximity:
[
\alpha \gg \beta
]
while a diagnostic query such as:
«Why did this operation fail?»
should increase causal weighting:
[
\beta \gg \alpha
]
A question such as:
«What happened immediately before this state?»
increases temporal and causal relevance.
The geometry of retrieval therefore becomes intent-dependent.
- The Memory Terrain
We call the resulting structure the Memory Terrain.
The term terrain is intentional.
A graph describes nodes and edges. A terrain additionally provides a useful abstraction for:
- regions;
- distances;
- gradients;
- boundaries;
- trajectories;
- valleys;
- basins;
- attractors;
- erosion;
- reinforcement.
A conceptual representation is:
Semantic proximity
↑
│
Temporal ← MEMORY → Causal
│
↓
Behavioral
│
↓
Terrain
/ | \
Basin Paths Attractors
The terrain is not necessarily represented as a literal two- or three-dimensional manifold. It is an operational abstraction over multiple graph and metric structures.
Its purpose is to make retrieval navigational.
- Retrieval as Navigation
Traditional RAG performs approximately:
[
q \rightarrow embedding(q) \rightarrow kNN \rightarrow context
]
CT-RAG instead proposes:
[
q
\rightarrow anchors
\rightarrow basin
\rightarrow causal/topological traversal
\rightarrow context
]
The first stage locates one or more anchor memories.
Anchors can still be discovered using conventional mechanisms:
- dense vector retrieval;
- BM25;
- entity identifiers;
- event identifiers;
- execution identifiers;
- temporal filters.
The important difference occurs afterward.
Rather than simply retrieving additional nearest neighbors, CT-RAG explores the topology surrounding those anchors.
For anchor a, define a local causal neighborhood:
[
N_c(a,h)=
{v\in V \mid d_c(a,v)\leq h}
]
where h represents a causal hop budget.
A decay function analogous to topological hop priors can then be introduced:
[
P_c(v|a)=e^{-\lambda d_c(a,v)}
]
but causal direction can also matter.
Therefore:
[
d_c^{past}(a,v)
]
and
[
d_c^{future}(a,v)
]
need not have equivalent retrieval weight.
When diagnosing an error, ancestors may receive greater weight than descendants.
When predicting consequences, the opposite may apply.
- Causal Basins
The next concept is the Causal Basin.
A causal basin is a region of memory whose states or events converge toward a common behavioral outcome, state or attractor.
Suppose thousands of executions produce variations of:
Payment
|
+---- Authorized ----> Reservation ----> Success
|
+---- Timeout --------> Retry ----------> Success
|
+---- Rejected -------> Recovery -------> Aborted
|
+---- Authorized -----> Stock Error ----> Compensation
Over time, recurrent trajectories emerge.
They may converge toward outcomes such as:
[
A_{success}
]
[
A_{recovery}
]
[
A_{aborted}
]
[
A_{compensation}
]
These outcomes can behave as attractors over the execution topology.
Consequently:
[
B(A)={x\in V : trajectory(x)\rightarrow A}
]
defines a causal basin associated with attractor A.
This is substantially different from clustering semantically similar events.
Events inside a basin may use entirely different vocabulary while belonging to the same behavioral phenomenon.
- Semantic Similarity Is Not Causality
CT-RAG deliberately avoids equating correlation, temporal adjacency or semantic similarity with causation.
The existence of:
[
A \rightarrow B
]
in a chronological log alone does not prove that A caused B.
Therefore causal edges should have provenance.
We define a causal edge:
[
e_c=(u,v,p,c)
]
where:
- u is the antecedent;
- v is the consequence;
- p is provenance;
- c is confidence.
Possible provenance classes include:
[
p \in
{
execution,
dependency,
workflow,
event,
inferred,
hypothesized
}
]
This allows CT-RAG to distinguish:
observed execution causality
from
inferred causal hypotheses.
For example:
Action A emitted Event X
Event X triggered Action B
provides substantially stronger structural evidence than:
Event A happened shortly before Event B.
This distinction is critical if CT-RAG is used for autonomous systems.
- Event Sourcing as Native Causal Evidence
Event-sourced architectures are particularly suitable for CT-RAG.
An Event Store already records sequences of state transitions.
If events contain identifiers such as:
- "event_id";
- "causation_id";
- "correlation_id";
- "execution_id";
- "intent_id";
- "actor_id";
- "action_id";
then substantial portions of the causal topology can be reconstructed deterministically.
For example:
Intent I42
↓
Action A17
↓
Event E21 [causation=A17]
↓
Action A18 [triggered_by=E21]
↓
Event E22 [causation=A18]
creates the causal chain:
[
I42 \rightarrow A17 \rightarrow E21 \rightarrow A18 \rightarrow E22
]
without requiring an LLM to infer the relationship.
This is one of the central architectural claims of CT-RAG:
«When causality is available as execution evidence, retrieval systems should preserve and exploit it rather than reconstructing relationships exclusively from semantic representations.»
- Stateful Agents
This becomes particularly relevant for stateful AI agents.
An agent executing a graph of actions produces an experiential history:
[
S_0
\xrightarrow{A_1}
S_1
\xrightarrow{A_2}
S_2
\xrightarrow{A_3}
S_3
]
Failures introduce branches:
[
S_2
\xrightarrow{A_3}
Error
\xrightarrow{Healing}
S_2'
\xrightarrow{A_3'}
S_3
]
Traditional agent memory might store textual descriptions of these experiences and retrieve them using embeddings.
CT-RAG stores both their semantic representations and their position within the execution topology.
The agent can consequently answer fundamentally different classes of questions:
Semantic retrieval
«Have I encountered something similar before?»
Causal retrieval
«What produced my current state?»
Counterfactual exploration
«Which alternative trajectories previously avoided this failure?»
Behavioral retrieval
«Which execution patterns usually converge toward this outcome?»
Recovery retrieval
«Which healing trajectories historically transformed this failure state into a successful state?»
The memory system consequently becomes part of the agent's state model rather than merely an external document search engine.
- Experiential Topology
Repeated execution modifies the terrain.
Suppose an agent repeatedly encounters:
[
A \rightarrow B \rightarrow Error_X
]
and successful recovery frequently follows:
[
Error_X \rightarrow H_3 \rightarrow B' \rightarrow Success
]
The trajectory becomes increasingly significant.
We can associate an edge weight:
[
w_{ij}(t)
]
with transitions and update it according to observed usage:
[
w_{ij}(t+1)=w_{ij}(t)+\eta
]
for reinforced paths.
Unused or obsolete paths can decay:
[
w_{ij}(t+1)=w_{ij}(t)e^{-\mu\Delta t}
]
This provides a computational interpretation of terrain evolution.
Frequently traversed paths become stronger.
Rare paths weaken.
Repeated outcomes form attractors.
New experiences reshape local topology.
This leads to a useful conceptual mapping:
[
remember \rightarrow reinforce
]
[
forget \rightarrow erode
]
[
learn \rightarrow reshape
]
[
retrieve \rightarrow navigate
]
[
experience \rightarrow modify\ terrain
]
Forgetting therefore does not necessarily require deletion.
A memory can remain historically preserved while losing navigational influence.
- Proposed Retrieval Function
A CT-RAG candidate score can combine several signals:
[
Score(v|q,a)=
\alpha S_{dense}(q,v)
+
\beta S_{lexical}(q,v)
+
\gamma P_{topological}(a,v)
+
\delta P_{causal}(a,v)
+
\epsilon P_{temporal}(v)
+
\zeta P_{behavioral}(v)
]
where:
- S_{dense} represents embedding similarity;
- S_{lexical} represents lexical relevance;
- P_{topological} measures terrain proximity;
- P_{causal} measures causal relevance;
- P_{temporal} captures temporal relevance;
- P_{behavioral} captures similarity between execution trajectories.
This should not be interpreted as the final formulation.
A central research question is whether these signals should be combined linearly, hierarchically or through staged retrieval.
A particularly promising architecture is staged:
[
Semantic/Lexical Search
\rightarrow Anchor Detection
\rightarrow Basin Selection
\rightarrow Causal Expansion
\rightarrow Reranking
\rightarrow Context
]
This avoids traversing the entire causal graph for every query.
- Architecture
A practical implementation can separate storage responsibilities:
┌──────────────────┐
│ Event Log │
│ authoritative ES │
└────────┬─────────┘
│
▼
┌──────────────────┐
│ Causal Projector │
└────────┬─────────┘
│
┌────────────┴────────────┐
▼ ▼
┌────────────────┐ ┌────────────────┐
│ Causal Graph │ │ Vector Index │
└───────┬────────┘ └───────┬────────┘
│ │
└────────────┬────────────┘
▼
┌──────────────────┐
│ Terrain Builder │
└────────┬─────────┘
▼
┌──────────────────┐
│ Basin Detection │
└────────┬─────────┘
▼
┌──────────────────┐
│ CT-RAG Retriever │
└────────┬─────────┘
▼
Context
↓
LLM
The event log remains the historical authority.
Vector and graph structures are projections optimized for retrieval.
This separation also prevents embedding infrastructure from becoming the authoritative representation of memory.
- CT-RAG versus Existing Retrieval Paradigms
Property| Vector RAG| GraphRAG| BasinRAG| CT-RAG
Primary unit| chunk| entity/relation| chunk/topological region| event/state/memory
Semantic retrieval| yes| yes| yes| yes
Explicit graph| no| yes| yes| yes
Topological confinement| no| partial| yes| yes
Basins/attractors| no| usually no| yes| yes
Observed causality| no| not necessarily| no| central
Temporal trajectories| weak| optional| structural sequence| central
Execution provenance| no| optional| no| central
Evolving behavioral terrain| no| limited| limited| proposed
Stateful-agent memory| generic| possible| possible| primary target
The purpose of CT-RAG is therefore not to replace BasinRAG.
It extends the underlying intuition:
«information retrieval benefits from preserving structure.»
BasinRAG demonstrates this for topological document retrieval. CT-RAG proposes that autonomous systems can exploit an even stronger structural signal: their own observed history of causes and consequences.
- Research Hypotheses
The proposal generates several experimentally testable hypotheses.
H1 — Causal retrieval improves diagnostic tasks
For queries asking why a state occurred:
[
CT\text{-}RAG > VectorRAG
]
in retrieval recall of causally relevant events.
H2 — Causal basins improve recovery retrieval
When selecting previous successful recovery strategies, retrieval constrained to the current causal basin should outperform global semantic nearest-neighbor retrieval.
H3 — Behavioral topology reduces irrelevant context
Topological confinement should reduce the number of retrieved memories required to reconstruct an execution.
H4 — Provenance-aware causality reduces false explanations
Explicitly separating observed and inferred causal edges should reduce unsupported causal explanations generated by the downstream LLM.
H5 — Terrain reinforcement enables experiential adaptation
Agents using reinforced successful trajectories should require fewer exploratory retrieval operations as experience accumulates.
- Evaluation
CT-RAG requires benchmarks different from conventional document QA.
Standard metrics such as:
[
Recall@K,\ Precision@K,\ MRR,\ nDCG
]
remain useful but are insufficient.
We propose additional metrics.
Causal Recall@K
Fraction of ground-truth causal ancestors retrieved:
[
CR@K =
\frac{|Retrieved_K \cap CausalAncestors|}
{|CausalAncestors|}
]
Causal Distance Error
Difference between retrieved and true causal proximity.
Trajectory Reconstruction Accuracy
Ability to reconstruct the execution path leading to a target state.
Basin Purity
Fraction of events inside a detected basin belonging to the same behavioral outcome.
Recovery Path Precision
Probability that a retrieved historical recovery trajectory is applicable to the current failure state.
Counterfactual Utility
Ability to retrieve alternative historical trajectories that diverged before an undesirable outcome.
These metrics shift evaluation from:
«Did retrieval find relevant text?»
toward:
«Did retrieval reconstruct the relevant experience?»
- Limitations
Several challenges remain.
First, execution order does not automatically establish causality.
Second, causal graphs can become extremely large in continuously operating agents.
Third, basin definitions may drift as agent behavior changes.
Fourth, old but critical experiences must not disappear merely because their paths are infrequently traversed.
Fifth, inferred causal relationships require uncertainty representation.
Finally, counterfactual reasoning requires more than historical causality. Observational trajectories cannot automatically establish what would have happened under an intervention.
CT-RAG therefore should distinguish clearly among:
[
observed\ causality
]
[
inferred\ causality
]
and
[
counterfactual\ hypothesis
]
rather than collapsing them into a single graph relation.
- Discussion
RAG began primarily as a mechanism for connecting language models to external documents.
As autonomous systems become long-lived and stateful, this framing becomes increasingly restrictive.
An autonomous agent does not merely possess documents.
It possesses experience.
Experience has order.
Experience has consequences.
Experience contains successful and unsuccessful trajectories.
And, when properly instrumented, experience contains causal evidence.
A vector database can tell an agent:
«“This resembles something you encountered before.”»
A causal-topological memory should additionally be able to tell it:
«“You have reached this region before, this is the path that brought you there, these trajectories usually leave this region, and this previous intervention produced a successful outcome.”»
This is a qualitatively different memory capability.
- Conclusion
Causal-Topological RAG proposes moving retrieval from semantic similarity toward experiential navigation.
The progression can be summarized as:
[
VectorRAG
\rightarrow
GraphRAG
\rightarrow
TopologicalRAG
\rightarrow
CausalTopologicalRAG
]
Vector retrieval provides semantic geometry.
Graphs provide explicit relationships.
Topological retrieval introduces regions, paths, basins and structural confinement.
Causal-topological retrieval adds observed causes, consequences and behavioral trajectories.
The resulting memory is not simply a collection of searchable observations.
It becomes an evolving terrain.
Within that terrain:
[
\textbf{retrieval becomes navigation}
]
[
\textbf{learning becomes terrain modification}
]
[
\textbf{repetition becomes path reinforcement}
]
[
\textbf{forgetting becomes erosion}
]
and
[
\textbf{reasoning about experience becomes causal traversal}
]
For stateful autonomous agents, the central retrieval question may therefore no longer be:
«What do I remember that looks like this?»
but:
«Where am I, how did I get here, and what happened the last time I traversed this terrain?»
Reference
Martins, A. (2026). BasinRAG: High-Performance Topological Retrieval-Augmented Generation via Dynamical Basins. Version 1.0.3. DOI: 10.5281/zenodo.22664948. The accompanying implementation describes functional graph topology \phi, dynamical basins of attraction, \rho-trees, semantic virtual edges, RRF fusion and topological hop priors.
Top comments (0)