Grand Diomande Research · Full HTML Reader

RAG++ Architecture Diagram

```mermaid flowchart TB subgraph Sources [Data Sources] Claude[Claude Desktop<br/>Response Hooks] Cursor[Cursor/Codex<br/>IDE Integration] Echelon[Echelon Engine<br/>Trajectory Segments] Studio[CC Studio<br/>Session Logs] AgentSDK[Agent SDK<br/>Programmatic Access] end

Agents That Account for Themselves architecture technical paper candidate score 46 .md

Full Public Reader

RAG++ Architecture Diagram

Version: 2.1.0
Last Updated: 2026-01-03
Parent: [08-RAG_PLUS_PLUS.md](../08-RAG_PLUS_PLUS.md)

---

Complete RAG++ Architecture

mermaid
flowchart TB
    subgraph Sources [Data Sources]
        Claude[Claude Desktop<br/>Response Hooks]
        Cursor[Cursor/Codex<br/>IDE Integration]
        Echelon[Echelon Engine<br/>Trajectory Segments]
        Studio[CC Studio<br/>Session Logs]
        AgentSDK[Agent SDK<br/>Programmatic Access]
    end

    subgraph Ingestion [Ingestion Layer]
        Hooks[Response Hooks<br/>[home-path]
        Sync[orbit_sync.py<br/>Async Ingestion]
        Ingester[PromptIngester<br/>Turn Creation]
    end

    subgraph Storage [Storage Layer - Supabase]
        MT[(memory_turns<br/>Primary Table)]
        CV[(conversations<br/>Session Groups)]
        OP[(orbit_projects<br/>Project Registry)]
        CP[(claude_prompts<br/>Raw Prompts)]
    end

    subgraph Core [Rust Core - rag_plusplus_core]
        subgraph Index [Indexing]
            HNSW[HNSWIndex<br/>O(log n) ANN]
            Embed[Embeddings<br/>1536 dims]
        end

        subgraph Trajectory [Trajectory]
            TC[TrajectoryCoordinate5D<br/>temporal, semantic, depth,<br/>homogeneity, salience]
            IRCP[IRCPPropagator<br/>Attention Weights]
        end

        subgraph Scoring [Scoring]
            Sal[SalienceScorer<br/>Dynamic Importance]
            Cons[ConservationMetrics<br/>Memory Validation]
        end
    end

    subgraph ML [Python ML Layer]
        subgraph Twin [CognitiveTwin]
            Encoder[Transformer Encoder]
            StyleHead[Style Projector]
        end

        subgraph Training [Training]
            Trainer[HybridTrainer<br/>Batch + Incremental]
            Sig[GlobalStyleSignature<br/>EMA Learning]
        end
    end

    subgraph Retrieval [Retrieval Layer]
        Ret[MemoryRetriever<br/>Trajectory-Aware]
        Gen[ResponseGenerator<br/>Context Assembly]
    end

    subgraph API [API Layer]
        Fast[FastAPI Service<br/>Port 8000]
        MCP[MCP Server<br/>AI Tool Access]
        Orbit[Orbit Proxy<br/>Port 3847]
    end

    %% Ingestion Flow
    Claude --> Hooks --> Sync --> Ingester --> MT
    Cursor --> Hooks
    Echelon --> Sync
    Studio --> Sync
    AgentSDK --> Fast

    %% Storage Relations
    MT --> CV --> OP
    MT --> CP

    %% Core Processing
    MT --> Embed --> HNSW
    MT --> TC --> IRCP
    IRCP --> Sal

    %% ML Training
    MT --> Encoder --> StyleHead --> Sig
    Trainer --> Twin

    %% Retrieval
    HNSW --> Ret
    IRCP --> Ret
    Ret --> Gen

    %% API
    Gen --> Fast --> MCP
    Orbit --> Fast

---

5D Trajectory Coordinate System

mermaid
flowchart LR
    subgraph Input [Turn Data]
        Turn[MemoryTurn<br/>content, role, timestamp]
        Query[Query Embedding<br/>1536 dims]
        Context[Session Context<br/>project, siblings]
    end

    subgraph Dims [5 Dimensions]
        T[Temporal<br/>time since epoch]
        S[Semantic<br/>cosine similarity]
        D[Depth<br/>conversation nesting]
        H[Homogeneity<br/>sibling similarity]
        Sal[Salience<br/>dynamic importance]
    end

    subgraph Compute [Computation]
        T1[temporal = (turn_time - project_start) / (now - project_start)]
        S1[semantic = dot(turn, query) / norms]
        D1[depth = count_ancestors / max_depth]
        H1[homogeneity = mean(similarity to siblings)]
        Sal1[salience = w_r·recency + w_d·depth + w_i·impact + w_role·role]
    end

    subgraph Output [5D Coordinate]
        Coord[TrajectoryCoordinate5D<br/>[0.3, 0.8, 0.2, 0.6, 0.7]]
    end

    Turn --> T1 --> T
    Query --> S1 --> S
    Context --> D1 --> D
    Context --> H1 --> H
    Turn --> Sal1 --> Sal

    T & S & D & H & Sal --> Coord

---

HNSW Index Structure

mermaid
flowchart TB
    subgraph Layers [Hierarchical Layers]
        L3[Layer 3<br/>Few entry points]
        L2[Layer 2<br/>More nodes]
        L1[Layer 1<br/>Dense]
        L0[Layer 0<br/>All nodes]
    end

    subgraph Params [Parameters]
        M[m = 16<br/>Connections per node]
        EFC[ef_construction = 200<br/>Build-time beam]
        EFS[ef_search = 50<br/>Query-time beam]
    end

    subgraph Query [Query Process]
        EP[Entry Point<br/>Top layer]
        Greedy[Greedy Descent<br/>Per layer]
        Beam[Beam Search<br/>Bottom layer]
        KNN[K Nearest<br/>Results]
    end

    L3 --> L2 --> L1 --> L0
    EP --> Greedy --> Beam --> KNN

---

I-RCP Propagation

Inverse Ring Contextual Propagation computes attention weights based on trajectory distance:

Attention(center, neighbor) = decay_factor ^ distance(center, neighbor)

Where distance is computed in the 5D trajectory space.

mermaid
flowchart LR
    subgraph Center [Query Center]
        C[Current Turn<br/>5D Coordinate]
    end

    subgraph Neighbors [Retrieved Neighbors]
        N1[Neighbor 1<br/>d=0.2]
        N2[Neighbor 2<br/>d=0.5]
        N3[Neighbor 3<br/>d=0.8]
        N4[Neighbor 4<br/>d=1.2]
    end

    subgraph Weights [Attention Weights]
        W1[w = 0.9^0.2 = 0.98]
        W2[w = 0.9^0.5 = 0.95]
        W3[w = 0.9^0.8 = 0.92]
        W4[w = 0.9^1.2 = 0.89]
    end

    subgraph Output [Weighted Context]
        WC[Weighted Average<br/>of neighbor contents]
    end

    C --> N1 --> W1 --> WC
    C --> N2 --> W2 --> WC
    C --> N3 --> W3 --> WC
    C --> N4 --> W4 --> WC

---

Salience Scoring

Dynamic importance based on multiple factors:

rust
pub fn compute_salience(factors: &SalienceFactors, config: &SalienceConfig) -> f32 {
    let base = config.w_recency * factors.recency      // More recent = higher
             + config.w_depth * factors.depth          // Deeper = higher
             + config.w_impact * factors.impact        // Higher impact = higher
             + config.w_role * factors.role_weight;    // User > Assistant > System

    // Length boost (longer content often more important)
    let length_factor = (factors.content_length as f32 / 500.0).min(1.5);

    (base * length_factor).clamp(0.0, 1.0)
}
FactorDefault WeightDescription
recency0.3Time since creation
depth0.2Conversation depth
impact0.3Measured influence
role0.2User > Assistant > System

---

API Endpoints

FastAPI Service (Port 8000)

EndpointMethodPurpose
`/api/rag/health`GETHealth check
`/api/rag/ingest`POSTIngest turn
`/api/rag/search`GETSemantic search
`/api/rag/context/{project_id}`GETProject context
`/api/rag/signature`GETStyle signature
`/api/rag/train`POSTTrigger training

MCP Tools

ToolPurpose
`rag_search`Search memory fabric
`rag_context`Get project context
`rag_style_signature`Get style signature

Agent SDK Tools

The Agent SDK (`@comp-core/agent-sdk`) provides RAG++ tools:

ToolPurpose
`ragSearchTool`Search memory fabric
`ragContextTool`Get project context
`ragStyleSignatureTool`Get style signature
`ragIngestTool`Ingest new turns

See: [17-AGENT_SDK.md](../17-AGENT_SDK.md) for full documentation.

---

Navigation

  • Overview: [system-overview.md](system-overview.md)
  • Deployment: [deployment-topology.md](deployment-topology.md)
  • RAG++ Docs: [08-RAG_PLUS_PLUS.md](../08-RAG_PLUS_PLUS.md)
  • TrajectoryOS: [02-TRAJECTORY_OS.md](../02-TRAJECTORY_OS.md)
  • Agent SDK: [17-AGENT_SDK.md](../17-AGENT_SDK.md)

Promotion Decision

Promote into a technical note or architecture paper with implementation anchors.

Source Anchor

Comp-Core/docs/architecture/diagrams/rag-architecture.md

Detected Structure

Method · Evaluation · Code Anchors · Architecture