Skip to main content

Intelligence Layer Overview

Seven Dimensions, One Intelligence Layer


The Framing That Must Survive Every Session

Every PropTech product says “AI assists.” That framing puts AI in the same category as a spell checker — useful, background, invisible. That is not what AI is in Leja. AI is not a product category and not a standalone surface. This folder documents the intelligence layer that runs across Leja’s surfaces. Leja will eventually hold the deepest, most continuously updated, multi-dimensional witnessed dataset of Nigerian residential behavior in existence. Three tracks per person. Every tenancy event. Every service transaction. Every market interaction. All witnessed, not self-reported. All accumulating over years. Most AI products are intelligent but data-poor. Leja will be the opposite: witnessed data of extraordinary depth, from which AI can extract signals that no other system in Nigeria can see. The Trust Graph is the data. The blockchain is the integrity guarantee. AI is what makes the whole system genuinely intelligent. Without AI, Leja is still a witnessed record system with institutional memory. With AI at depth, Leja understands the Nigerian residential economy better than any other system in existence. And that understanding compounds.

Dimension Contract

Every AI dimension must answer three questions before it becomes doctrine:
  1. Which witnessed records does it read?
  2. Which human decision does it support?
  3. Which surface becomes more useful?
If a dimension cannot answer all three, it is a feature idea, not a Leja intelligence dimension.

The Seven Dimensions

Dimension A: Intelligence layer of the Trust Graph
             Trajectory analysis, contextual interpretation, cross-track synthesis

Dimension B: Witnessing model scale engine
             Submission triage, consistency checking, regional pattern learning

Dimension C: Resident advocate intelligence layer
             Supports decisions across all three Resident tracks

Dimension D: Professional operator intelligence layer
             Supports agents, principals, organisations, and formal operators

Dimension E: Network-level fraud detection
             Velocity anomalies, geographic clustering, cross-party patterns

Dimension F: Federated computation engine
             Bank models run on Leja data — raw data never leaves

Dimension G: Service participation trust matcher
             Trust compatibility for service, space, and stay participation

AI Model Selection

Use CasePrimary ModelFallbackSync/Async
Payment evidence extraction (Vision)claude-sonnet-4-5gpt-4o-visionAsync (BullMQ)
Document parsing (agreements)claude-sonnet-4-5gpt-4o-visionAsync (BullMQ)
Narrative generationclaude-haiku-4-5claude-sonnet-4-5Sync (< 3s)
Anomaly detectionclaude-sonnet-4-5Async (scheduled)
NL query translationclaude-haiku-4-5claude-sonnet-4-5Sync (< 2s)
Payment predictionclaude-haiku-4-5Async (scheduled)
Score explanationclaude-haiku-4-5claude-sonnet-4-5Sync (< 2s)
Fraud detection (image)claude-sonnet-4-5Async (BullMQ)
Agreement generationclaude-haiku-4-5claude-sonnet-4-5Sync (< 30s)

The Intelligence Module Structure

apps/backend/src/modules/intelligence/
├── intelligence.module.ts          NestJS module — exported to all other modules
├── intelligence.service.ts         Core: model selection, rate limiting, cost tracking
├── extraction/
│   ├── extraction.processor.ts     BullMQ worker
│   ├── extraction.prompts.ts       Bank-specific prompts (GTB, Access, UBA, etc.)
│   └── extraction.schemas.ts       Zod schemas for generateObject output
├── document-parser/
│   ├── parser.processor.ts         BullMQ worker
│   ├── parser.prompts.ts           Agreement parsing prompts
│   └── parser.schemas.ts           Zod schemas
├── narrative/
│   ├── narrative.service.ts        Sync service
│   └── narrative.prompts.ts        Nigerian English register prompts
├── anomaly/
│   ├── anomaly.processor.ts        BullMQ scheduled worker
│   └── anomaly.schemas.ts          Zod schemas for anomaly output
├── prediction/
│   ├── prediction.processor.ts     BullMQ scheduled worker
│   └── prediction.schemas.ts       Zod schemas
├── fraud/
│   ├── fraud.processor.ts          BullMQ worker (post-payment)
│   └── fraud.schemas.ts            Zod schemas
├── query/
│   ├── query.service.ts            Sync service (NL → filter)
│   └── query.prompts.ts
└── shared/
    ├── model-selector.ts           Routes to correct model by task
    ├── cost-tracker.ts             Per-org AI cost tracking
    ├── retry-strategy.ts           Exponential backoff, fallback switching
    └── prompt-utils.ts             Template helpers, context builders
Rule: All modules consume IntelligenceService — never call Vercel AI SDK directly.

Cost Model (Milestone Wave 1 Estimate)

OperationModelEst. TokensCost/Op75 ops/customer/month
Payment evidence extractionclaude-sonnet-4-5~2,000~$0.008~$0.60
Document parsingclaude-sonnet-4-5~5,000~$0.020~$0.30
Narrative generationclaude-haiku-4-5~500~$0.001~$0.08
NL query translationclaude-haiku-4-5~300~$0.0005~$0.04
Anomaly scan (daily)claude-sonnet-4-5~3,000~$0.012~$0.36
Total per customer~$1.38/month
At ₦25,000/month subscription (≈ $16 USD), AI cost is < 9% of revenue. Margin: > 90% before other costs.

Structured Output with Vercel AI SDK

All AI output uses generateObject with Zod schemas — never raw text parsing.
import { generateObject } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';
import { z } from 'zod';

const PaymentSignalSchema = z.object({
  amount: z.number().positive(),
  paymentDate: z.string().date(),
  reference: z.string().optional(),
  payerName: z.string().optional(),
  institution: z.string().optional(),
  rail: z.enum(['BANK_TRANSFER', 'CARD', 'USSD', 'VIRTUAL_ACCOUNT', 'CASH', 'OTHER']),
  confidence: z.number().min(0).max(1),
  reviewNotes: z.string().describe('Reasoning for confidence level'),
});

const { object } = await generateObject({
  model: anthropic('claude-sonnet-4-5-20251001'),
  schema: PaymentSignalSchema,
  messages: [{
    role: 'user',
    content: [
      { type: 'image', image: normalizedEvidenceUrl },
      { type: 'text', text: PAYMENT_REVIEW_PROMPT },
    ],
  }],
});
// object is fully typed and validated — no parsing needed

Sharp for Image Preprocessing

When payment evidence includes an image artifact, it can be normalized before Claude Vision review. Sharp (libvips-based) handles this quickly inside the shared intelligence pipeline.
import sharp from 'sharp';

async function preprocessPaymentEvidence(buffer: Buffer): Promise<Buffer> {
  return sharp(buffer)
    .greyscale()
    .normalize()                    // Auto-contrast
    .sharpen({ sigma: 1.5 })       // Sharpen text edges
    .resize(1200, null, { withoutEnlargement: true })
    .png()
    .toBuffer();
}