Last modified by Robert Schaub on 2026/02/08 08:12

From version 2.1
edited by Robert Schaub
on 2026/01/02 10:01
Change comment: There is no comment for this version
To version 1.1
edited by Robert Schaub
on 2026/01/02 09:59
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,17 +2,16 @@
1 -= FactHarbor POC1 Architecture Analysis =
2 2  
2 += FactHarbor POC1 Architecture Analysis=
3 3  
4 +
4 4  **Version:** 2.6.17
5 5  **Analysis Date:** January 2026
6 6  **Document Purpose:** Technical diagrams, gap analysis, and optimization recommendations
7 7  
8 ------
9 +---
9 9  
10 -----
11 +== 1. AKEL Flow Diagram (with LLM and WebSearch Interactions)==
11 11  
12 -== 1. AKEL Flow Diagram (with LLM and WebSearch Interactions) ==
13 13  
14 -
15 15  {{mermaid}}
16 16  flowchart TB
17 17   subgraph Input["📥 Input Layer"]
... ... @@ -93,10 +93,10 @@
93 93   class UNDERSTAND,DECIDE,FETCHSRC,EXTRACT,VERDICT,REPORT step
94 94  {{/mermaid}}
95 95  
96 ------
95 +---
97 97  
98 98  
99 -== 2. ERD Data Model (Current POC1 Implementation) ==
98 +== 2. ERD Data Model (Current POC1 Implementation)==
100 100  
101 101  
102 102  {{mermaid}}
... ... @@ -188,10 +188,10 @@
188 188   }
189 189  {{/mermaid}}
190 190  
191 ------
190 +---
192 192  
193 193  
194 -== 3. Overall Architecture with Interactions ==
193 +== 3. Overall Architecture with Interactions==
195 195  
196 196  
197 197  {{mermaid}}
... ... @@ -287,74 +287,77 @@
287 287   class ANALYZE_API,JOBS_API,JOB_API,EVENTS_API,RUN_JOB api
288 288  {{/mermaid}}
289 289  
290 ------
289 +---
291 291  
292 292  
293 -== 4. Specification vs Implementation Gap Analysis ==
292 +== 4. Specification vs Implementation Gap Analysis==
294 294  
295 295  
296 296  
297 -=== 4.1 Data Model Gaps ===
296 +=== 4.1 Data Model Gaps===
298 298  
299 299  
300 -| Specification Entity | POC1 Status | Gap Description |
301 -|-|-|-|
302 -| **Claim** | ⚠️ Partial | No persistent storage; claims exist only in JSON result. Missing: `status`, `confidence_score`, `risk_score`, `completeness_score`, `version`, `views`, `edit_count` |
303 -| **Evidence** | ⚠️ Partial | Implemented as `ExtractedFact` but lacks: `supports` enum, proper `relevance_score` |
304 -| **Source** | ⚠️ Partial | `FetchedSource` exists but missing: `type` enum, `accuracy_history`, `correction_frequency`, weekly update scheduler |
305 -| **Scenario** | ❌ Missing | Not implemented. Claims are evaluated directly without scenario contexts |
306 -| **Verdict** | ⚠️ Partial | `ClaimVerdict` exists but missing: `likelihood_range`, `uncertainty_factors` array, proper `explanation_summary` |
307 -| **User** | ❌ Missing | No user authentication or role system |
308 -| **Edit** | ❌ Missing | No audit trail for changes |
299 +| Specification Entity | POC1 Status | Gap Description |
300 +|---------------------|-------------|-----------------|
301 +| **Claim** | ⚠️ Partial | No persistent storage; claims exist only in JSON result. Missing: `status`, `confidence_score`, `risk_score`, `completeness_score`, `version`, `views`, `edit_count` |
302 +| **Evidence** | ⚠️ Partial | Implemented as `ExtractedFact` but lacks: `supports` enum, proper `relevance_score` |
303 +| **Source** | ⚠️ Partial | `FetchedSource` exists but missing: `type` enum, `accuracy_history`, `correction_frequency`, weekly update scheduler |
304 +| **Scenario** | ❌ Missing | Not implemented. Claims are evaluated directly without scenario contexts |
305 +| **Verdict** | ⚠️ Partial | `ClaimVerdict` exists but missing: `likelihood_range`, `uncertainty_factors` array, proper `explanation_summary` |
306 +| **User** | ❌ Missing | No user authentication or role system |
307 +| **Edit** | ❌ Missing | No audit trail for changes |
309 309  
309 +
310 310  === 4.2 AKEL Component Gaps ===
311 311  
312 -| Spec Component | POC1 Status | Gap Description |
313 -| |-|-|
314 -| **AKEL Orchestrator** | ✅ Implemented | `runAnalysis()` function serves this role |
315 -| **Claim Extractor** | ✅ Implemented | `understandClaim()` with claim role/dependency tracking |
316 -| **Claim Classifier** | ⚠️ Partial | Risk tier (A/B/C) assigned, but no domain classification |
317 -| **Scenario Generator** | ❌ Missing | Claims evaluated without scenario extraction |
318 -| **Evidence Summarizer** | ✅ Implemented | `extractFacts()` function |
319 -| **Contradiction Detector** | ⚠️ Partial | `isContestedClaim` flag exists but no active contradiction search |
320 -| **Quality Gate Validator** | ❌ Missing | No source quality gates, no mandatory checks |
321 -| **Audit Sampling Scheduler** | ❌ Missing | No audit system |
322 -| **Embedding Handler** | ❌ Missing | Not needed for POC |
323 -| **Federation Sync** | ❌ Missing | Not needed for POC |
312 +| Spec Component | POC1 Status | Gap Description |
313 +|----------------|-------------|-----------------|
314 +| **AKEL Orchestrator** | ✅ Implemented | `runAnalysis()` function serves this role |
315 +| **Claim Extractor** | ✅ Implemented | `understandClaim()` with claim role/dependency tracking |
316 +| **Claim Classifier** | ⚠️ Partial | Risk tier (A/B/C) assigned, but no domain classification |
317 +| **Scenario Generator** | ❌ Missing | Claims evaluated without scenario extraction |
318 +| **Evidence Summarizer** | ✅ Implemented | `extractFacts()` function |
319 +| **Contradiction Detector** | ⚠️ Partial | `isContestedClaim` flag exists but no active contradiction search |
320 +| **Quality Gate Validator** | ❌ Missing | No source quality gates, no mandatory checks |
321 +| **Audit Sampling Scheduler** | ❌ Missing | No audit system |
322 +| **Embedding Handler** | ❌ Missing | Not needed for POC |
323 +| **Federation Sync** | ❌ Missing | Not needed for POC |
324 324  
325 -=== 4.3 Architecture Gaps ===
326 326  
326 +=== 4.3 Architecture Gaps===
327 327  
328 -| Spec Requirement | POC1 Status | Gap Description |
329 -||-|-|
330 -| **Three-Layer Architecture** | ✅ Implemented | Interface (Next.js) → Processing (AKEL) → Data (SQLite) |
331 -| **LLM Abstraction Layer** | ✅ Implemented | AI SDK supports multiple providers with failover |
332 -| **PostgreSQL Primary DB** | ⚠️ Different | Using SQLite for simplicity (acceptable for POC) |
333 -| **Redis Caching** | ❌ Missing | No caching layer |
334 -| **S3 Archival** | ❌ Missing | No long-term storage |
335 -| **Background Jobs** | ❌ Missing | No scheduler for source updates, cache warming |
336 -| **Quality Monitoring** | ⚠️ Partial | LLM call counting exists, but no anomaly detection |
337 337  
338 -=== 4.4 Publication & Review Gaps ===
329 +| Spec Requirement | POC1 Status | Gap Description |
330 +|------------------|-------------|-----------------|
331 +| **Three-Layer Architecture** | ✅ Implemented | Interface (Next.js) → Processing (AKEL) → Data (SQLite) |
332 +| **LLM Abstraction Layer** | ✅ Implemented | AI SDK supports multiple providers with failover |
333 +| **PostgreSQL Primary DB** | ⚠️ Different | Using SQLite for simplicity (acceptable for POC) |
334 +| **Redis Caching** | ❌ Missing | No caching layer |
335 +| **S3 Archival** | ❌ Missing | No long-term storage |
336 +| **Background Jobs** | ❌ Missing | No scheduler for source updates, cache warming |
337 +| **Quality Monitoring** | ⚠️ Partial | LLM call counting exists, but no anomaly detection |
339 339  
340 340  
341 -| Spec Feature | POC1 Status | Gap Description |
342 -||-|-|
343 -| **Risk Tier Publication Rules** | ❌ Missing | All results published immediately regardless of tier |
344 -| **Human Review Queue** | ❌ Missing | No review workflow |
345 -| **AI-Generated Labeling** | ⚠️ Partial | Results show "AI analysis" but no formal labeling system |
346 -| **Audit Rate Sampling** | ❌ Missing | No sampling audits |
340 +=== 4.4 Publication & Review Gaps===
347 347  
348 ------
349 349  
343 +| Spec Feature | POC1 Status | Gap Description |
344 +|--------------|-------------|-----------------|
345 +| **Risk Tier Publication Rules** | ❌ Missing | All results published immediately regardless of tier |
346 +| **Human Review Queue** | ❌ Missing | No review workflow |
347 +| **AI-Generated Labeling** | ⚠️ Partial | Results show "AI analysis" but no formal labeling system |
348 +| **Audit Rate Sampling** | ❌ Missing | No sampling audits |
350 350  
351 -== 5. Optimization Recommendations ==
350 +---
352 352  
353 353  
353 +== 5. Optimization Recommendations==
354 354  
355 -=== 5.1 Cost Optimizations ===
356 356  
357 357  
357 +=== 5.1 Cost Optimizations===
358 +
359 +
358 358  {{mermaid}}
359 359  pie title Current LLM Cost Distribution (Estimated per Analysis)
360 360   "Step 1: Understand" : 15
... ... @@ -362,17 +362,18 @@
362 362   "Step 3: Verdicts" : 25
363 363  {{/mermaid}}
364 364  
365 -| Optimization | Estimated Savings | Implementation Effort |
366 -||-----||
367 -| **Cache claim understanding** | 30-50% on repeated claims | Medium |
368 -| **Use Haiku for fact extraction** | 40% on Step 2 costs | Low (config change) |
369 -| **Batch fact extraction** | 20% fewer API calls | Medium |
370 -| **Skip search for known claims** | 50%+ for cached claims | High (needs claim DB) |
371 -| **Reduce max iterations** | Linear reduction | Low (config change) |
367 +| Optimization | Estimated Savings | Implementation Effort |
368 +|--------------|-------------------|----------------------|
369 +| **Cache claim understanding** | 30-50% on repeated claims | Medium |
370 +| **Use Haiku for fact extraction** | 40% on Step 2 costs | Low (config change) |
371 +| **Batch fact extraction** | 20% fewer API calls | Medium |
372 +| **Skip search for known claims** | 50%+ for cached claims | High (needs claim DB) |
373 +| **Reduce max iterations** | Linear reduction | Low (config change) |
372 372  
373 -=== 5.2 Timing Optimizations ===
374 374  
376 +=== 5.2 Timing Optimizations===
375 375  
378 +
376 376  {{mermaid}}
377 377  gantt
378 378   title Current Analysis Timeline (Typical)
... ... @@ -398,17 +398,18 @@
398 398   Generate Verdicts :b5, after b4, 10s
399 399  {{/mermaid}}
400 400  
401 -| Optimization | Time Savings | Notes |
402 -|||-----|
403 -| **Parallel source fetching** | Already implemented | Currently fetches 3 sources in parallel |
404 -| **Streaming LLM responses** | 20-30% perceived | User sees progress faster |
405 -| **Search query batching** | 10-15% | Send multiple queries to search API |
406 -| **Reduce prompt size** | 5-10% per call | Optimize system prompts |
407 -| **Use faster models for extraction** | 30-40% on Step 2 | Claude Haiku vs Sonnet |
404 +| Optimization | Time Savings | Notes |
405 +|--------------|--------------|-------|
406 +| **Parallel source fetching** | Already implemented | Currently fetches 3 sources in parallel |
407 +| **Streaming LLM responses** | 20-30% perceived | User sees progress faster |
408 +| **Search query batching** | 10-15% | Send multiple queries to search API |
409 +| **Reduce prompt size** | 5-10% per call | Optimize system prompts |
410 +| **Use faster models for extraction** | 30-40% on Step 2 | Claude Haiku vs Sonnet |
408 408  
409 -=== 5.3 Priority Recommendations ===
410 410  
413 +=== 5.3 Priority Recommendations===
411 411  
415 +
412 412  1. **HIGH PRIORITY - Implement Claim Caching**
413 413   - Cache claim verdicts by content hash
414 414   - Reduces costs for repeated/similar claims
... ... @@ -424,14 +424,14 @@
424 424   - Cache search results (1h TTL)
425 425   - Reduces external API calls
426 426  
427 ------
431 +---
428 428  
429 429  
430 -== 6. Separated Verdict Architecture Proposal ==
434 +== 6. Separated Verdict Architecture Proposal==
431 431  
432 432  
433 433  
434 -=== 6.1 Current Architecture ===
438 +=== 6.1 Current Architecture===
435 435  
436 436  
437 437  {{mermaid}}
... ... @@ -450,7 +450,7 @@
450 450  - Article verdict tightly coupled to claim extraction
451 451  
452 452  
453 -=== 6.2 Proposed Separated Architecture ===
457 +=== 6.2 Proposed Separated Architecture===
454 454  
455 455  
456 456  {{mermaid}}
... ... @@ -506,26 +506,29 @@
506 506  {{/mermaid}}
507 507  
508 508  
509 -=== 6.3 Benefits Analysis ===
513 +=== 6.3 Benefits Analysis===
510 510  
511 511  
512 -| Benefit | Impact | Rationale |
513 -|-| |-----|
514 -| **Cost Reduction** | 40-70% for repeated claims | Many articles share common claims (e.g., "COVID vaccines are safe") |
515 -| **Faster Analysis** | 50%+ for cached claims | Skip research + LLM calls for known claims |
516 -| **Consistency** | High | Same claim always gets same verdict (until cache expires) |
517 -| **Freshness Control** | Configurable TTL | Balance consistency vs. new evidence |
518 -| **Scalability** | Linear improvement | More users = higher cache hit rate |
516 +| Benefit | Impact | Rationale |
517 +|---------|--------|-----------|
518 +| **Cost Reduction** | 40-70% for repeated claims | Many articles share common claims (e.g., "COVID vaccines are safe") |
519 +| **Faster Analysis** | 50%+ for cached claims | Skip research + LLM calls for known claims |
520 +| **Consistency** | High | Same claim always gets same verdict (until cache expires) |
521 +| **Freshness Control** | Configurable TTL | Balance consistency vs. new evidence |
522 +| **Scalability** | Linear improvement | More users = higher cache hit rate |
519 519  
524 +
520 520  === 6.4 Implementation Considerations ===
521 521  
522 522  **Claim Hashing Strategy:**
523 -{{code language="typescript"}}function getClaimHash(claim: string): string {
528 +{{code language="typescript"}}
529 +function getClaimHash(claim: string): string {
524 524   // Normalize: lowercase, remove punctuation, stem words
525 525   const normalized = normalize(claim);
526 526   // Hash for cache key
527 527   return crypto.createHash('sha256').update(normalized).digest('hex').slice(0, 16);
528 -}{{/code}}
534 +}
535 +{{/code}}
529 529  
530 530  **Cache Invalidation Triggers:**
531 531  - TTL expiration (default 7 days)
... ... @@ -538,7 +538,7 @@
538 538  - Same claims in different article contexts may yield different article verdicts
539 539  - Example: "Vaccines are safe" + "Vaccines cause autism" → article may be misleading even if first claim is true
540 540  
541 -### 6.5 Recommendation##
548 +### 6.5 Recommendation
542 542  
543 543  **YES, separating is beneficial** with the following caveats:
544 544  
... ... @@ -554,14 +554,14 @@
554 554   - Phase 2: Semantic similarity caching (embedding-based)
555 555   - Phase 3: Federated claim sharing across instances
556 556  
557 ------
564 +---
558 558  
559 559  
560 -== 7. Summary ==
567 +== 7. Summary==
561 561  
562 562  
563 563  
564 -=== Current State ===
571 +=== Current State===
565 565  
566 566  - POC1 implements core AKEL pipeline successfully
567 567  - Claim dependency tracking is implemented
... ... @@ -569,7 +569,7 @@
569 569  - No persistent claim storage or caching
570 570  
571 571  
572 -=== Key Gaps from Specification ===
579 +=== Key Gaps from Specification===
573 573  
574 574  - No scenario extraction
575 575  - No user/role system
... ... @@ -578,7 +578,7 @@
578 578  - No review queue
579 579  
580 580  
581 -=== Recommended Next Steps ===
588 +=== Recommended Next Steps===
582 582  
583 583  1. Implement claim caching layer
584 584  2. Separate claim vs article verdict generation
... ... @@ -585,3 +585,5 @@
585 585  3. Add Redis for source/search caching
586 586  4. Implement tiered model selection
587 587  5. Add basic audit logging
595 +
596 +