Friday, May 22, 2026

What is AWS Escrow Account

In AWS, escrow refers to dedicated, isolated AWS accounts used by third-party model providers (like Anthropic or Cohere) to safely host their proprietary AI models. You access these models securely via Amazon Bedrock without ever transferring the model weights directly to your own AWS account. 


Amazon Web Services (AWS)

 +1

Where Are the Models Available?

Foundational and custom AI models are hosted in AWS regions supporting Amazon Bedrock. Some commonly used regions include: 

US East (N. Virginia & Ohio)

US West (Oregon)

Europe (Frankfurt & Paris)

Asia Pacific (Tokyo, Singapore, & Sydney)

How Escrow and Amazon Bedrock Work

When you use a third-party foundation model in Bedrock, the service is designed with the following security guarantees:

Model Tenancy: The third-party model provider hosts their models and data in an isolated AWS environment, commonly referred to as their escrow account.

Access via API: Amazon Bedrock has the permissions necessary to route your API inference requests to the provider's escrow account.

Data Privacy: Your prompts, continuations, and training data are never used to train any of the base models. The model providers cannot access your Bedrock inference logs or your prompt details.

Network Isolation: All traffic between your environment and the escrow model passes securely over the AWS internal network. 


d1.awsstatic.com

 +3

How to Get Started

To access these escrowed models, you need to enable them in the Bedrock console: 

Open the AWS Management Console.

Navigate to Amazon Bedrock.

Go to Model access on the left menu.

Click Manage model access, review the terms, and check the models you want to enable (e.g., Anthropic Claude, Meta Llama, AI21 Labs).

Request access and wait for confirmation (usually granted instantly). 

Once enabled, you can interact with these models using the Bedrock API or the AWS SDKs in your applications. 


3 sites

Improve your productivity with Amazon Q and Bedrock for SAP use ...

3 Jul 2024 — What security standard does Amazon Q and Bedrock support ? * Amazon Q Business supports access control for your data so that users...



Amazon Web Services (AWS)

Securely build generative AI applications and control data with ...

9 Jul 2023 — o Generative AI and foundation models (FMs) o Introducing Amazon Bedrock o Data privacy and security o Model tenancy o Client conn...



d1.awsstatic.com

Overview of Amazon Bedrock with networking, security and ...

24 Jan 2024 — Overview of Amazon Bedrock with networking, security and observability considerations. ... Amazon Bedrock is a managed service by ...



Aviatrix Community

Show all







Thursday, May 21, 2026

SAGEConv Details

 GraphSAGE is a scalable Graph Neural Network architecture designed to learn node embeddings efficiently on large and evolving graphs.


In  (or more specifically, PyTorch Geometric),  implements the GraphSAGE operator. It generates node embeddings by sampling and aggregating local neighborhood features, allowing models to generalize inductively to entirely unseen nodes without retraining on the whole graph. [1, 2, 3]  

How  Works 

Instead of using fixed structural whole-graph weights like traditional spectral models,  works in two phases: 


1. Aggregate: Condenses features from a node's neighbors into a single representative vector using methods like  (default), , or . 

2. Update: Performs separate linear transformations on the node's own features and its aggregated neighbor features, and then combines them: 

3. $x^{\prime}_i = W_1 x_i + W_2 \cdot \mathrm{aggregate}(x_j)$ [1, 3, 5, 6, 7]  


How it differs from other Conv layers 

Here is how  compares to other standard convolution operators available in the PyTorch Geometric Conv Layers module: 


• Vs.  (Graph Convolutional Network): is transductive, relying on the symmetric normalized Laplacian of the entire graph and a single weight matrix for both the node and its neighbors. In contrast,  processes graphs inductively, decoupling the central node's weights from the neighbor weights using separate matrices. 

• Vs. : applies an additive combination of node and neighbor features based on the Weisfeiler-Lehman isomorphism test.  uses distinct, separate weight projections for self-features and neighbor-features before combining them. 

• Vs. : is primarily used for point clouds and dynamically constructs local graphs, computing messages across edges based on relative spatial distances.  works on static, pre-defined edge topology and relies strictly on neighborhood aggregation. [1, 2, 4, 8, 9]  


Check out the PyTorch Geometric SAGEConv Documentation for detailed implementation parameters like  (aggregation type) and . [5]  


AI responses may include mistakes.


[1] https://kumo.ai/pyg/layers/sage-conv/

[2] https://patricknicolas.substack.com/p/graph-convolutional-or-sage-networks

[3] https://pytorch-geometric.readthedocs.io/en/2.7.0/generated/torch_geometric.nn.conv.SAGEConv.html

[4] https://medium.com/analytics-vidhya/ohmygraphs-graphsage-in-pyg-598b5ec77e7b

[5] https://pytorch-geometric.readthedocs.io/en/latest/generated/torch_geometric.nn.conv.SAGEConv.html

[6] https://medium.com/analytics-vidhya/ohmygraphs-graphsage-in-pyg-598b5ec77e7b

[7] https://apxml.com/courses/introduction-to-graph-neural-networks/chapter-2-the-message-passing-mechanism/common-aggregation-functions

[8] https://pytorch-geometric.readthedocs.io/en/latest/generated/torch_geometric.nn.conv.GraphConv.html

[9] https://pytorch-geometric.readthedocs.io/en/latest/generated/torch_geometric.nn.conv.EdgeConv.html


Wednesday, May 20, 2026

What is Timescale and ClickHouse Databases

TimescaleDB and ClickHouse are both highly optimized databases built to handle massive amounts of time-series data (like IoT sensor metrics, server logs, or financial tickers), but they take completely different architectural approaches to solve the problem. 

1. TimescaleDB

TimescaleDB is a relational database designed specifically for time-series data. 

Architecture: It is built as an extension on top of PostgreSQL. It operates primarily as a row-oriented database.

Key Feature: It automatically splits large tables into smaller, time-based chunks (called hypertables), giving you the scalability of a NoSQL database while retaining the standard SQL syntax and reliability of Postgres.

Best Used For: Teams that already use PostgreSQL, need to join time-series data with traditional relational data (like users or devices), and require strict ACID compliance and powerful SQL tooling. 


Tinybird

 +5

2. ClickHouse

ClickHouse is a specialized, open-source columnar database designed for high-performance analytics. 

Architecture: Unlike Postgres, ClickHouse is column-oriented. Instead of saving a full row across a disk, it stores the data for each column separately.

Key Feature: Because it only reads the specific columns required for a query (e.g., just reading a price column instead of an entire row), it can perform lightning-fast aggregations on billions of rows.

Best Used For: Large-scale, read-heavy workloads where you need to do heavy data crunching, run real-time dashboards, and analyze massive volumes of logs or clickstreams. 


Tinybird

 +4

At a Glance Comparison

Feature TimescaleDB ClickHouse

Foundation PostgreSQL extension Purpose-built columnar OLAP

Data Structure Row-oriented Column-oriented

Query Language Standard SQL SQL-like (but less standard/compatible)

Best Use Case Relational data mixed with time-series; IoT Real-time observability, logs, and massive analytics

Top Advantage Full SQL ecosystem, easy to integrate Incredible processing speed across billions of rows

Which one to choose?

Choose TimescaleDB if you want to use the PostgreSQL ecosystem you already know and you need to combine time-series events with traditional relational business data.

Choose ClickHouse if you are building heavy analytics dashboards, processing massive volumes of logs, and need maximum performance at a massive scale. 


ClickHouse

 +1

What is HITL and how they are used

 A HITL (Human-in-the-Loop) gate is a strategic checkpoint in an automated workflow or AI agent process where the system pauses and waits for a human to review, approve, or correct its action.

It balances machine autonomy with safety by intercepting high-stakes, irreversible, or ambiguous decisions before they are executed.
How the HITL Gate Process Works
  1. The Checkpoint: As an AI agent or automated workflow runs, it reaches a pre-defined step (e.g., executing a financial transaction, sending an email, or modifying code).
  2. Suspension: The system pauses the process and saves its current state so it doesn't waste computing resources.
  3. Notification: The human reviewer is alerted via a dashboard, Slack, email, or other communication tool, providing them with context and the agent's proposed action.
  4. The Decision: The human evaluates the request and responds with a choice: approve, reject, or modify the instructions.
  5. Resumption: The workflow restores its state and continues based on the human’s input.
Common Use Cases
  • Approval Gates: Requiring a human manager to sign off on a consequential action, such as deploying software to production or executing a high-value purchase.
  • Compliance: Enforcing human sign-off for heavily regulated decisions, like data privacy compliance checks or sensitive medical diagnoses.
  • Review Checkpoints: Allowing domain experts to inspect intermediate AI results before an agent finalizes a larger task.
Why They Are Used
HITL gates prevent AI "hallucinations" or autonomous errors from causing real-world damage. They act as a safeguard to control the "blast radius" of autonomous systems while still allowing organizations to reap the efficiency benefits of automation

Tuesday, May 19, 2026

Monitoring solution ideas

 Building an enterprise-grade agentic application for network traffic, logs, and telemetry monitoring requires a clear separation of labor between **Machine Learning (ML) models** and **Generative AI Agents**.

A common pitfall is over-relying on LLM agents to process raw, high-throughput streaming data, which leads to high latency, astronomical token costs, and catastrophic failures due to context window saturation. Instead, think of **ML as your high-speed sensory nervous system** and **Agents as your conscious reasoning brain**.

The foundational architecture balancing these components addresses four core enterprise problems:

## 1. Data Ingestion & Velocity Overload

 * **The Problem:** Network telemetry (NetFlow/IPFIX, Syslogs, Prometheus metrics) generates millions of events per second. LLMs are far too slow and expensive to process raw, packet-level data or streaming logs directly.

 * **The Solution (Hybrid ML + Agent Architecture):**

   * **ML Layer (Sensory Engine):** Deploy lightweight statistical ML models (like Isolation Forests, Autoencoders, or XGBoost) directly at the stream layer (e.g., Kafka or Flink). These models compress, clean, and run real-time anomaly detection, flagging only the top 0.1% of suspicious traffic spikes or log anomalies.

   * **Agent Layer (Reasoning Engine):** Agents remain dormant until an ML model triggers an alert. The agent then receives a structured, pre-filtered summary block of the anomaly context rather than raw bytes.

## 2. Alert Fatigue & "Stitch-less" Correlation

 * **The Problem:** A single root-cause network issue (like a failing microservice or a localized DDoS attack) can trigger thousands of separate alerts across different firewalls, routers, and application logs. Humans or traditional SIEMs struggle to stitch these together quickly.

 * **The Solution (The Multi-Agent Triage Fleet):**

   Implement a specialized **Multi-Agent Orchestration Router** that spins up focused worker agents to investigate cross-layer telemetry.

```

                  +--------------------------------+

                  |  Kafka / Flink Telemetry Stream|

                  +--------------------------------+

                                  |

                                  v

                  +--------------------------------+

                  |  ML Layer: Isolation Forest /  |

                  |  Autoencoders (Anomaly Spotter)|

                  +--------------------------------+

                                  | (Flags 0.1% Outliers)

                                  v

+-----------------------------------------------------------------------+


| AGENTIC LAYER (Orchestration & Investigation) |

| :--- |

| +-------------------------------+ |

|  | Orchestration Agent |  |

|  | (Validates & Dispatches) |  |

| +-------------------------------+ |

| / | \ |

| / | \ |

| v           v             v |

| +---------------+ +---------------+ +---------------+ |

|  | Traffic Agent |  | Log Agent |  | Topology Agent |  |

|  | (NetFlow/PCAP) |  | (Syslog RAG) |  | (Graph Metrics) |  |

| +---------------+ +---------------+ +---------------+ |


+-----------------------------------------------------------------------+

```

 * **Orchestration Agent:** Receives the ML anomaly flag and analyzes the threat scope. It dispatches sub-agents to specific silos.

 * **Traffic Agent:** Uses specialized Python tools to fetch and query NetFlow data or run packet analysis on the flagged time frame.

 * **Log Agent:** Queries your vectorized historical log store using RAG to check if this pattern matches known software bugs or past incident post-mortems.

 * **Topology Agent:** Evaluates network topology using graph metrics (like Betweenness Centrality or Relational Graph Attention Networks) to determine if the anomaly affects a critical core node or an isolated edge device.

## 3. High False-Positive Rates in Security & Faults

 * **The Problem:** Traditional ML anomaly detection tools are notoriously hyper-sensitive. A scheduled backup or an infrastructure scaling event looks exactly like a data exfiltration attempt or a system failure to a basic ML model, generating endless false alarms.

 * **The Solution (Agentic Verification & Tool Use):**

   * Give your agents access to your internal ecosystem tools (such as your deployment management APIs, CI/CD pipelines, or Kubernetes cluster states).

   * When the ML layer alerts on a huge traffic spike, the **Orchestration Agent** doesn't ping your engineers immediately. Instead, it queries the cluster API: *"Was there a scheduled Cron job, database backup, or a new microservice deployment at 14:00 UTC?"*

   * If yes, the agent auto-resolves the alert with a log entry: *"Traffic spike validated as scheduled backup; closing alert."* If no, it elevates the alert with a fully formed incident brief.

## 4. Turning Actionable Data Into Clear Narratives

 * **The Problem:** When an outage occurs, SREs and Network Operators waste precious minutes running ad-hoc commands, tracing dependencies, and writing down incident logs manually.

 * **The Solution (Autonomous Root-Cause Synthesis):**

   * Because your agents are hooked into the investigation loop, they synthesize their findings using standard OpenTelemetry semantic conventions.

   * Instead of a cryptic error code, the agent generates a comprehensive Markdown report detailing the narrative breakdown of the incident, complete with timelines, impacted dependencies, and explicit remediation commands.

## Technical Stack Blueprint

To make this solution highly reliable, scalable, and observable, look to construct your agentic backend around this modern framework blueprint:


| Layer | Recommended Technology | Role in the Solution |

| :--- | :--- | :--- |

| **Data Stream** | Apache Kafka / Vector | Ingests high-velocity network logs and metrics. |

| **ML/Observability** | FastAPI + Prometheus + Scikit-Learn | Exposes ML endpoints, handles fast math operations, and tracks system resource health. |

| **Agent Framework** | LangGraph / CrewAI | Manages stateful, multi-agent execution loops and tool routing. |

| **Telemetry Standard** | OpenTelemetry (GenAI Semantic Conventions) | Traces every agent step, LLM call, and tool invocation to prevent loops and track token spend. |


> **Operational Warning:** When designing the agentic layer, never give an agent raw subprocess or bash tool access to execute changes on your enterprise production routers without explicit human-in-the-loop (HITL) clearance. Keep agents in a "Read-Only + Suggestion" mode for mitigation, requiring a engineer to click an approval button before pushing configurations.

>

What LiteLLM

 Here are the essential practical takeaways about LiteLLM, LiteLLM Agent Platform, and the broader architecture ideas behind them.


1. What LiteLLM Actually Is

LiteLLM is basically a universal abstraction layer / gateway for LLMs.

Instead of writing separate SDK integrations for:

you write ONE OpenAI-style API call.

LiteLLM translates requests internally to provider-specific formats. (Doolpa)


2. Core Problem LiteLLM Solves

Without LiteLLM:

if provider == "openai":
    ...
elif provider == "anthropic":
    ...
elif provider == "gemini":
    ...

Every provider has:

  • different auth

  • different SDK

  • different request schema

  • different response structure

  • different streaming behavior

  • different errors

LiteLLM standardizes this.

So your app code becomes provider-independent. (Doolpa)


3. Two Main Parts of LiteLLM

A) LiteLLM SDK

Simple Python library.

Example:

from litellm import completion

response = completion(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello"}]
)

You can swap to Claude/Gemini/etc without rewriting logic.

Good for:

  • applications

  • agents

  • notebooks

  • prototypes


B) LiteLLM Proxy / Gateway

This is the BIG production feature.

Instead of apps calling providers directly:

Application
   ↓
LiteLLM Gateway
   ↓
OpenAI / Claude / Gemini / Bedrock

This gateway adds enterprise capabilities:

  • routing

  • retries

  • fallback

  • cost tracking

  • rate limits

  • observability

  • auth

  • RBAC

  • caching

  • logging

  • load balancing

(litellm.ai)


4. Most Important Real-World Concept

LiteLLM is becoming the:

“API Gateway for AI”

similar to how Kong/Apigee/NGINX became API gateways.

This is the KEY architectural insight.


5. Why Companies Use It

Major benefit:

Avoid Vendor Lock-in

You can dynamically route:

  • cheap model

  • fast model

  • high-quality model

  • fallback model

without rewriting application code.

Example:

Normal requests → Gemini Flash
Complex requests → GPT-4
Failure → Claude

6. Practical Enterprise Features

Routing

Send requests intelligently.

Example:

  • summarization → cheap model

  • coding → Claude

  • reasoning → GPT-4


Fallbacks

If OpenAI fails:

Try Claude automatically

Important for production reliability.


Budget Controls

Per:

  • user

  • team

  • org

  • API key

Useful for enterprises.


Observability

Tracks:

  • latency

  • tokens

  • cost

  • failures

  • provider usage


Guardrails

Add:

  • moderation

  • PII filtering

  • safety checks


7. Why LiteLLM Became Popular

The AI ecosystem changes extremely fast.

New models appear every week.

LiteLLM lets companies:

  • swap models fast

  • benchmark providers

  • avoid rewrites

  • centralize governance

That is why many frameworks internally depend on LiteLLM now. (ChatForest)


8. What LiteLLM Agent Platform Is

This is newer and VERY important.

The Agent Platform extends beyond routing.

It is infrastructure for running AI agents securely. (docs.litellm-agent-platform.ai)


9. Main Problem Agent Platform Solves

Modern coding agents like:

  • Claude Code

  • Codex

  • autonomous agents

need:

  • GitHub access

  • API keys

  • cloud credentials

  • filesystem access

Huge security risk.


10. LiteLLM Agent Platform Architecture

Core idea:

Agents run inside isolated sandboxes

Usually Kubernetes pods.

But:

agents NEVER directly see real credentials.


11. The Most Important Innovation: Vault Sidecar

Architecture:

Agent
   ↓
Stub credentials only
   ↓
Vault Sidecar
   ↓
Real credentials injected at network layer

Meaning:

  • agent sees fake token

  • sidecar swaps with real secret

  • real secret never exposed to agent memory

This is VERY important for secure autonomous agents. (docs.litellm-agent-platform.ai)


12. Why This Matters

Future enterprise AI systems will have:

  • autonomous agents

  • coding agents

  • infrastructure agents

  • DevOps agents

  • network agents

You cannot safely give them root credentials directly.

LiteLLM Agent Platform tries to solve:

  • isolation

  • credential security

  • sandbox execution

  • persistent sessions


13. Architectural Layers (VERY Important)

Think of the stack like this:

Applications / Agents
        ↓
Agent Platform
        ↓
LiteLLM Gateway
        ↓
LLM Providers

Gateway Layer

Handles:

  • routing

  • costs

  • retries

Agent Platform Layer

Handles:

  • sandboxing

  • isolation

  • secrets

  • sessions

  • execution environments


14. Connection To Your Interests

This aligns VERY closely with your:

  • multi-agent architecture work

  • network automation agents

  • planner/supervisor agents

  • enterprise AI orchestration

  • secure execution systems

Especially relevant for:

  • Cisco automation agents

  • infrastructure agents

  • telecom agents


15. Important Industry Trend

We are moving from:

Prompt engineering

to:

AI Infrastructure Engineering

Meaning:

  • routing

  • observability

  • governance

  • agent isolation

  • security

  • cost optimization

  • orchestration

become the real engineering challenge.


16. Important Weaknesses Mentioned

Some community discussions mention challenges at scale:

  • Python/GIL throughput limits

  • logging bottlenecks

  • latency growth

  • scaling issues

  • security incidents in 2026

(Reddit)

Important lesson:

AI middleware becomes critical infrastructure.

So:

  • security

  • dependency management

  • observability

  • supply-chain trust

become extremely important.


17. Biggest Conceptual Takeaway

LiteLLM is not “just another SDK”.

It represents a shift toward:

Standardized AI Infrastructure

Where:

  • models become interchangeable

  • agents become deployable workloads

  • AI systems become governed infrastructure

similar to:

  • Kubernetes for containers

  • API gateways for microservices


18. Most Important Things To Learn Practically

For your background, focus on:

  1. LiteLLM Gateway

  2. Model routing

  3. Multi-model fallback

  4. Cost-aware routing

  5. Agent sandboxing

  6. Secret isolation

  7. Observability

  8. Agent session management

  9. Kubernetes-based agent execution

  10. AI infrastructure security

These are becoming core enterprise AI engineering skills.

Sunday, May 17, 2026

Friend prediction using pytorch geometry

 Implementing a "Friend Prediction" (also known as **Link Prediction**) system using GNNs, GraphSAGE, or GAT follows a highly structured pipeline. In this setup, your users are **nodes**, existing friendships are **edges**, and the goal is to predict the probability that an edge *should* exist between two currently unconnected nodes.

Here is a step-by-step guide on how to design and implement this application.

## 1. The Core Architecture (The Encoder-Decoder Framework)

Most GNN-based link prediction models use an **Encoder-Decoder** workflow:

 1. **The Encoder (GNN / GraphSAGE / GAT):** Takes the graph structure and node features (e.g., user age, location, interests) and outputs a low-dimensional vector (embedding) for every single user.

 2. **The Decoder:** Takes the embeddings of two users (User A and User B) and computes a similarity score (using Dot Product or a small Multi-Layer Perceptron). A high score means they are likely to become friends.

```

[Graph Data: Nodes & Edges] 

         │

         ▼

 ┌───────────────┐

 │    ENCODER    │ ──► Generates User Embeddings ($z_u, z_v$)

 │(SAGE/GAT/GCN) │

 └───────────────┘

         │

         ▼

 ┌───────────────┐

 │    DECODER    │ ──► Computes Link Score (e.g., $Score = z_u^T \cdot z_v$)

 │ (Dot Product) │

 └───────────────┘

         │

         ▼

 [Friend Prediction Probability]


```

## 2. Choosing the Right Layer for the Job

While the pipeline remains identical, changing the model type changes how the **Encoder** aggregates information:

 * **GraphSAGE (Best for Large Scale):** If your user base is massive or constantly growing, GraphSAGE is the practical choice. It will sample a subset of a user's current friends to update their embedding, preventing memory bottlenecks.

 * **GAT (Best for Feature-Driven Matches):** If you want the model to learn *why* people are friends (e.g., "User A and User B are friends because they share a niche hobby, ignoring the fact that they live in different cities"), GAT’s attention mechanism dynamically weights neighbor importance based on profile features.

## 3. Step-by-Step Implementation Workflow

If you are implementing this in Python, the gold standard libraries are **PyTorch Geometric (PyG)** or **DGL (Deep Graph Library)**.

### Step A: Graph Setup & Data Splitting

Unlike standard machine learning where you split rows of data, in link prediction, you must **split the edges**.

 * **Training Edges:** The friendships the GNN is allowed to "see" and message-pass through.

 * **Positive Validation/Test Edges:** Real friendships held out to evaluate if the model can predict them.

 * **Negative Validation/Test Edges:** Randomly sampled pairs of users who are *not* friends, used to teach the model what a "non-friendship" looks like.

### Step B: Defining the Model (PyTorch Geometric Style)

Here is a conceptual implementation using PyG. You can easily swap SAGEConv for GATConv or GCNConv.

```python

import torch

import torch.nn as nn

import torch.nn.functional as F

from torch_geometric.nn import SAGEConv


class FriendPredictor(nn.Module):

    def __init__(self, in_channels, hidden_channels, out_channels):

        super().__init__()

        # Encoder Layers (Using GraphSAGE as an example)

        self.conv1 = SAGEConv(in_channels, hidden_channels)

        self.conv2 = SAGEConv(hidden_channels, out_channels)


    def encode(self, x, edge_index):

        # Generates node embeddings

        x = self.conv1(x, edge_index)

        x = F.relu(x)

        x = self.conv2(x, edge_index)

        return x


    def decode(self, z, edge_label_index):

        # Decoder: Dot product between source and target node embeddings

        src = z[edge_label_index[0]]

        dst = z[edge_label_index[1]]

        return (src * dst).sum(dim=-1) # Returns a similarity score for each pair


```

### Step C: The Training Loop

To train the network, you need to pass both **positive edges** (real friends) and **negative edges** (random users) through the decoder, forcing the model to score positive edges close to 1 and negative edges close to 0.

```python

model = FriendPredictor(in_channels=num_features, hidden_channels=64, out_channels=32)

optimizer = torch.optim.Adam(model.parameters(), lr=0.01)

criterion = torch.nn.BCEWithLogitsLoss()


def train():

    model.train()

    optimizer.zero_grad()

    

    # 1. Encode: Pass the training graph structure to get node embeddings

    z = model.encode(train_data.x, train_data.edge_index)

    

    # 2. Decode Positive Edges

    pos_out = model.decode(z, train_data.pos_edge_label_index)

    

    # 3. Decode Negative Edges (sampled on the fly or pre-sampled)

    neg_out = model.decode(z, train_data.neg_edge_label_index)

    

    # 4. Combine predictions and calculate Binary Cross Entropy Loss

    predictions = torch.cat([pos_out, neg_out], dim=0)

    targets = torch.cat([torch.ones(pos_out.size(0)), torch.zeros(neg_out.size(0))], dim=0)

    

    loss = criterion(predictions, targets)

    loss.backward()

    optimizer.step()

    return loss.item()


```

## 4. Serving Recommendations in Production

Once trained, generating "People You May Know" recommendations for a specific user follows this deployment logic:

 1. Run the **Encoder** pass over your graph once (e.g., nightly or in mini-batches) to generate updated embeddings for all active users.

 2. To suggest friends for User A, extract their embedding (z_A).

 3. Calculate the dot product of z_A against the embeddings of candidates (e.g., friends-of-friends who aren't currently connected to User A).

 4. Sort the candidates by their score in descending order and serve the top 5 as friend recommendations.