How abhi9199-tech42/scdl-rag-enhanced-architecture works
This repository is a hybrid monorepo for a contradiction-aware RAG system. The main production-facing code is in src/ (TypeScript), while api/ and embedding/ contain Python service components, and isre/, urcm/, and reference/ hold reference implementations and migration/validation material.
1. External entry points
The system is consumed by Python and JavaScript SDKs (sdk/python, sdk/javascript), direct HTTP clients, and the test/load scripts. The documented API surface is a detection service that accepts a question, answer, and source documents, then returns a hallucination verdict, score, and explanation.
2. HTTP/API boundary
The TypeScript server in src/api/ is the main request edge: server.ts, routes.ts, middleware/auth.ts, middleware/rateLimit.ts, validation.ts, swagger.ts, and metrics.ts define request handling, auth, throttling, schema validation, API docs, and observability. Async endpoints are part of this boundary as well.
3. Orchestration layer
src/system/core.ts and src/system/performance.ts coordinate runtime behavior and performance-sensitive paths. This is the point where request-level work is handed off to retrieval, context assembly, and contradiction analysis, and where async/background processing is likely coordinated.
4. Context and retrieval pipeline
src/context/assembler.ts and src/retrieval/engine.ts form the evidence-preparation path. Documents and query material are normalized, assembled into a working context, and then scored/retrieved before the reasoning layers operate on them.
5. Storage and persistence
src/storage/ provides two backing modes (memory_store.ts and file_store.ts) plus deduplication logic. The checked-in data/vector_store.json indicates a local vector/cache artifact rather than a separate database service, so persistence is lightweight and embedded in-process or file-backed.
6. Hallucination/contradiction reasoning
The core reasoning subsystems are split into src/isre/ and src/urcm/. src/isre/bridge.ts, src/isre/processor.ts, and the compression/graph/multilang modules implement semantic reasoning, while src/urcm/processor.ts and src/urcm/contradiction/* handle contradiction detection and resolution. This is the main analytic boundary of the system.
7. Explainability and audit trail
src/audit/explainable.ts and src/audit/trail.ts capture why a result was produced, not just the result itself. This is important because the product’s output is meant to be human-readable and auditable, especially for detected contradictions and auto-fix suggestions.
8. Shared primitives and utilities
Common types, IDs, logging, and vector utilities live in src/types, src/utils/id.ts, src/utils/logger.ts, and src/utils/vector.ts. These are cross-cutting support modules used by API, retrieval, storage, and reasoning code.
9. Python service components
The api/ and embedding/ directories are separate Python service runtimes with their own requirements and Dockerfiles. The README describes them as the API service and the embedding/NLI inference service, so in deployment diagrams they should be treated as distinct services connected over HTTP rather than as libraries.
10. Reference implementations and compatibility layers
isre/, urcm/, and the large reference/ subtree mirror the same architecture in Python and include validation suites, docs, and examples. These are useful for understanding intent and for migration/benchmarking, but they are not the only runtime path.
11. Offline evaluation and performance harness
experiments/ and loadtest/ contain benchmark runners, datasets, CSV/MD reports, and pressure tests. These are an offline analytics boundary: they exercise the API and model services to measure recall, throughput, endurance, and auto-fix behavior.
12. Deployment and packaging
Docker is first-class (docker/api.Dockerfile, docker/embedding.Dockerfile, docker/docker-compose.yml), and CI is defined in .github/workflows/ci.yml. The repo also ships docs/landing pages and SDK packaging, so the architecture spans service runtime, client libraries, and documentation/static site delivery.
In diagram terms, the key flow is: client/SDK → API gateway/server → validation/auth/rate limit → context assembly/retrieval/storage → ISRE/URCM reasoning and contradiction detection → audit/explanation → response, with a separate embedding/inference service and offline evaluation/load-testing tooling around it.
Main entry points: api API Server · types Shared Primitives · system System Core · isre ISRE Engine
Components 20
Clients & SDKs
Entry points that call the detection system
- Python SDK · Python client wrapper for the detection API
sdk/python - JS SDK · JavaScript client wrapper for the detection API
sdk/javascript - HTTP Clients · Direct callers using the HTTP surface
TypeScript Runtime
Main production-facing implementation
- API Server · Main request edge for detection and async endpoints
src/api - System Core · Coordinates request handling and runtime flow
src/system - Context Builder · Normalizes and assembles evidence for reasoning
src/context - Retrieval Engine · Scores and retrieves source material before analysis
src/retrieval - Storage Layer · In-process and file-backed stores with deduplication
src/storage - ISRE Engine · Intent and semantic reasoning subsystem
src/isre - URCM Engine · Contradiction detection and resolution subsystem
src/urcm - Audit Trail · Captures explanations and provenance for outputs
src/audit - Shared Primitives · Common types, IDs, logging, and vector helpers
src/types
Python Services
Separate service runtimes for API and embeddings
- Python API · Python service component for API-facing runtime
api - Embedding Service · Python inference service for embeddings and NLI
embedding
Reference Material
Migration and validation implementations
- ISRE Reference · Python reference implementation and validation suite
reference/isre - URCM Reference · Python reference implementation and integration bridge
reference/urcm
Offline Ops
Evaluation, load testing, and deployment assets
- Eval Harness · Experiments for benchmark runs and report generation
experiments - Load Tests · Async, HTTP, endurance, and stress testing scripts
loadtest - Deploy Assets · Docker and compose definitions plus CI workflow
docker - Docs Site · Product, API, system, and deployment documentation
docs
Connections 27
- Python SDK → API Server: detect · Python SDK calls the main detection API
- JS SDK → API Server: detect · JavaScript SDK calls the main detection API
- HTTP Clients → API Server: HTTP request · Direct clients hit the API boundary
- API Server → System Core: dispatch · API layer hands work to orchestration
- System Core → Context Builder: assemble · Runtime prepares evidence context
- System Core → Retrieval Engine: retrieve · Runtime invokes scoring and retrieval
- System Core → ISRE Engine: analyze · Runtime forwards evidence to semantic reasoning
- System Core → URCM Engine: contradict · Runtime forwards evidence to contradiction analysis
- Context Builder → Storage Layer: read/write · Context assembly uses local persistence and deduplication
- Retrieval Engine → Storage Layer: fetch · Retrieval reads cached or file-backed vectors
- ISRE Engine → Audit Trail: explain · Reasoning contributes to human-readable explanation
- URCM Engine → Audit Trail: audit · Contradiction detection contributes trace and rationale
- Shared Primitives → API Server: support · Shared primitives underpin request handling
- Shared Primitives → Context Builder: support · Shared primitives underpin context assembly
- Shared Primitives → Retrieval Engine: support · Shared primitives underpin retrieval logic
- Shared Primitives → ISRE Engine: support · Shared primitives underpin ISRE reasoning
- Shared Primitives → URCM Engine: support · Shared primitives underpin URCM reasoning
- Python API → Embedding Service: HTTP · Python service boundary connects to embedding/NLI inference
- ISRE Reference → ISRE Engine: reference · Reference implementation mirrors ISRE architecture
- URCM Reference → URCM Engine: reference · Reference implementation mirrors URCM architecture
- Eval Harness → API Server: exercise · Benchmark runners drive the production API
- Load Tests → API Server: stress · Pressure tests exercise request paths and throughput
- Deploy Assets → Python API: build/run · Deployment assets package the Python API service
- Deploy Assets → Embedding Service: build/run · Deployment assets package the embedding service
- Docs Site → API Server: describe · Documentation explains the API and system contracts
- Docs Site → ISRE Engine: describe · Documentation explains the ISRE reasoning layer
- Docs Site → URCM Engine: describe · Documentation explains the URCM contradiction layer