Overview

The Knowledge Graph Embedder (KGE) is an intermediary layer positioned between the modality-specific encoders and the universal 512d projection layer. It enables graph-aware encoding without requiring the full knowledge graph to reside in memory.

Problem Statement

Current architecture requires the full knowledge graph to be loaded in memory for GNN reasoning. This limits scalability and increases memory footprint.

Input → Encoder → Projection Layer → 512d Space → GNN → LLM ↑ Full graph in memory (~800MB for 1M nodes)

Issues:

  1. Memory bound: Full graph must be loaded for GNN reasoning
  2. Scalability limit: Cannot grow beyond RAM capacity
  3. Latency: Full graph traversal for each query
  4. Power consumption: Unnecessary memory operations

Target Architecture

Input → Encoder → [KGE] → Projection Layer → 512d Space → GNN → LLM ↓ ┌─────────────────────┐ │ On-Demand Subgraph │ │ Solid State Storage │ │ Incremental Compute │ └─────────────────────┘

Storage Layer

Technology: SQLite with FTS5 for full-text search, plus HNSW index for approximate nearest neighbor (ANN) search.

Schema

-- Core node storage CREATE TABLE nodes ( node_id TEXT PRIMARY KEY, embedding BLOB, -- 512d float32 vector modality TEXT, -- 'text' | 'audio' | 'video' | 'ocr' timestamp INTEGER, source TEXT, metadata JSON, novelty_score REAL, created_at INTEGER ); -- Edge storage with type information CREATE TABLE edges ( edge_id INTEGER PRIMARY KEY AUTOINCREMENT, source_id TEXT, target_id TEXT, edge_type INTEGER, -- 0-10 (11 types) weight REAL, created_at INTEGER, FOREIGN KEY (source_id) REFERENCES nodes(node_id), FOREIGN KEY (target_id) REFERENCES nodes(node_id) ); -- HNSW index for ANN search CREATE VIRTUAL TABLE node_hnsw USING hnsw( embedding, metric='cosine', m=16, -- connections per node ef_construction=200 -- build-time accuracy ); -- FTS5 for text search CREATE VIRTUAL TABLE node_fts USING fts5( node_id, content, content=nodes, content_rowid=rowid );

Storage Optimization

Subgraph Loader

Load only relevant subgraph for each query, using ANN search + graph traversal.

Algorithm

function loadRelevantSubgraph(query_embedding, max_nodes=100, hops=1): # Step 1: Find k nearest nodes via ANN seed_nodes = hnns_search(query_embedding, k=max_nodes) # Step 2: Load 1-hop neighbors subgraph_nodes = set(seed_nodes) for node in seed_nodes: neighbors = get_neighbors(node, edge_types=ALL) subgraph_nodes.update(neighbors) # Step 3: Load from disk (cache check first) subgraph = [] for node_id in subgraph_nodes: if node_id in cache: subgraph.append(cache[node_id]) else: node_data = load_from_disk(node_id) cache[node_id] = node_data subgraph.append(node_data) # Step 4: Load edges within subgraph edges = load_edges(subgraph_nodes) return Subgraph(nodes=subgraph, edges=edges)

Cache Strategy

Performance Characteristics

Memory Usage

ComponentCurrentWith KGEReduction
Full graph in memory800 MB0 MB100%
Active subgraphN/A20 MBN/A
Cache (hot nodes)N/A20 MBN/A
HNSW indexN/A100 MBN/A
Total800 MB140 MB82.5%

Latency

OperationCurrentWith KGEChange
ANN search (100 nodes)N/A5 msNew
Subgraph load (100 nodes)N/A10 msNew
GNN on subgraph50 ms15 ms-70%
Total query100 ms30 ms-70%

Scalability

MetricCurrentWith KGE
Max nodes (8GB RAM)1M10M
Max nodes (32GB RAM)4M40M
Query latency (1M nodes)200 ms30 ms
Query latency (10M nodes)OOM45 ms