1. System Architecture Overview
The Document Management System (DMS) intelligence module operates as a decoupled, high-performance pipeline built on ASP.NET Core (.NET 8) and PostgreSQL 16 + PGVector, exposed via REST APIs and consumed by the responsive Next.js 15 / TypeScript portal (compatible with Angular/SPA and React Native WebViews).
2. AI-Powered Document Intelligence (RAG Pipeline)
A. Ingestion & Smart Chunking
Uploaded documents are normalized, split at paragraph and sentence boundaries (~500–750 chars per chunk), and tagged with page estimations and token counts. Pre-seeded clinical documents include ACS Triage, Medication Reconciliation, Pediatric Sedation, and HIPAA Security policies.
B. Vector Embedding & PGVector Search
Each chunk is transformed into an L2-normalized 128-dimensional dense vector combining clinical domain anchors and subword n-gram projections. Vectors are stored natively in PostgreSQL vector(128) columns and queried using the cosine distance operator (<=>).
C. Grounded Prompt & Citations
Retrieved chunks above the cosine similarity threshold are synthesized into structured clinical answers with inline source citations ([Source: Document Title, P.X]) and confidence metrics, preventing hallucination.
D. Live Chunk & Vector Inspector
Users can inspect every document's extracted chunks, token counts, and raw vector previews directly from the RAG Portal, or ingest custom policies in real time.
PostgreSQL PGVector Similarity Query
SELECT c.id AS "ChunkId",
d.title AS "DocumentTitle",
c.page_number AS "PageNumber",
c.content AS "Content",
(1.0 - (c.embedding <=> @queryVector::vector)) AS "Similarity"
FROM dms_document_chunks c
JOIN dms_documents d ON c.document_id = d.id
WHERE c.embedding IS NOT NULL
ORDER BY c.embedding <=> @queryVector::vector ASC
LIMIT @topK;
3. Implemented .NET 8 RAG API Reference
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/rag/documents |
List all indexed DMS documents with page/chunk counts and ingestion status. |
| GET | /api/rag/documents/{id}/chunks |
Inspect extracted text chunks, token counts, and 128-dim vector previews. |
| POST | /api/rag/documents/upload |
Ingest a new document, chunk content, generate embeddings, and save to PGVector. |
| POST | /api/rag/query |
Run vector cosine similarity search and return a grounded answer with citations & latency. |
| GET | /api/rag/stats |
Return document count, chunk count, vector dimensions, and PGVector version. |
4. Generic Workflow Engine Plan (Cloud Orchestration)
Per architectural scope, the Generic Workflow Engine is designed to integrate with managed cloud orchestrators (GCP Workflows, Azure Logic Apps, or Temporal) rather than duplicating orchestration state inside the transactional web API. The complete technical blueprint is stored in docs/generic-workflow-engine-plan.md.
Planned State Machine Lifecycle (Document Governance)
[Upload & OCR] --> (1. Draft) --[SubmitForReview]--> (2. Compliance Review)
^ |
|------[RejectWithFeedback]-----------|
| [ApproveCompliance]
v
(5. Archived) <--[Retire]-- (4. Published) <-- (3. Medical Director Approval)
|
[Automated Post-Action]
Trigger PGVector Re-Index
Configurable Entities (Planned)
WorkflowDefinition: Versioned blueprint & categoryWorkflowState: Initial, Intermediate, Terminal statesWorkflowTransition: Guard conditions & required rolesWorkflowTask&WorkflowHistory: Role-based inbox & audit trail
Cloud Integration Hooks
- GCP Workflows / Pub/Sub: Multi-day human-in-the-loop sign-off & SLA escalations
- Webhook Bridge:
POST /api/webhooks/workflow-eventstriggers automatic RAG re-indexing upon document approval