docs(presentation): add system ingestion voice and RAG pipeline diagrams

This commit is contained in:
amirhosein mazaheri
2026-10-14 15:07:27 +03:30
parent 2e8c179efc
commit e9797309f9
15 changed files with 674 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
flowchart LR
U[User / Admin] --> UI[Angular frontend]
UI -->|REST + session cookie + CSRF| API[FastAPI API]
UI <-->|WebSocket: PCM + JSON events| API
API --> AUTH[Authentication / role / organization]
API -->|Upload: independent document + job| DB[(PostgreSQL + pgvector)]
API --> FS[(Immutable originals / extraction artifacts)]
W[Separate ingestion worker] -->|Claim job + lease + heartbeat| DB
W -->|Read original / retain extraction| FS
W --> OCR[OpenRouter vision / Gemini Flash]
W --> EMB[Local Ollama / bge-m3]
W -->|Atomic chunks + vectors publication| DB
API --> RT[OpenAI Realtime adapter]
RT <-->|Provider WebSocket| OAI[OpenAI gpt-realtime-2.1 / Marin]
RT -->|Validated tools| SEARCH[Shared backend SearchService]
SEARCH --> EMB
SEARCH -->|Eligible document chunks| DB
API -->|Selection / revision invalidation| DB
Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

+102
View File
@@ -0,0 +1,102 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1600" height="1000" viewBox="0 0 1600 1000" role="img">
<title>System architecture</title>
<desc>Deployed application boundaries and shared storage</desc>
<defs><marker id="arrow" markerWidth="9" markerHeight="9" refX="8" refY="4.5" orient="auto"><path d="M0,0 L9,4.5 L0,9" fill="#64748b"/></marker></defs>
<rect width="1600" height="1000" fill="#ffffff"/>
<style>text{font-family:Segoe UI,Arial,sans-serif}.title{font-size:38px;font-weight:700;fill:#0f172a}.sub{font-size:21px;fill:#475569}.node{font-size:21px;font-weight:650;fill:#0f172a}.detail{font-size:17px;fill:#475569}.edge{font-size:14px;fill:#475569}</style>
<text x="75" y="75" class="title">System architecture</text>
<text x="75" y="115" class="sub">Deployed application boundaries and shared storage</text>
<path d="M395,262.5 L450,262.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M770,262.5 L825,262.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M1145,262.5 L1200,262.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M610.0,335 L610.0,435" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M610.0,335 L610.0,385.0 L235.0,385.0 L235.0,435" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M596.0,580 L596.0,680" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M610.0,680 L610.0,618 L235.0,618 L235.0,580" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M770,752.5 L825,752.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M610.0,680 L610.0,644 L1360.0,644 L1360.0,580" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M624.0,680 L624.0,580" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M985.0,335 L985.0,435" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M825,507.5 L770,507.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M1145,507.5 L1200,507.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M235.0,680 L235.0,605 L610.0,605 L610.0,580" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<rect x="75" y="190" width="320" height="145" rx="16" fill="#e8f0fe" stroke="#2563eb" stroke-width="1.8"/>
<rect x="75" y="212" width="5" height="101" rx="2" fill="#2563eb"/>
<text x="95" y="230" class="node">Browser / Angular</text>
<text x="95" y="268" class="detail">Admin uploads; user voice</text>
<text x="95" y="298" class="detail">REST and browser WebSocket</text>
<rect x="450" y="190" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="450" y="212" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="470" y="230" class="node">FastAPI API</text>
<text x="470" y="268" class="detail">Auth, lifecycle, selection</text>
<text x="470" y="298" class="detail">Server-derived organization</text>
<rect x="825" y="190" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="825" y="212" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="845" y="230" class="node">VoiceRuntime + adapter</text>
<text x="845" y="268" class="detail">Audio relay and trusted tools</text>
<text x="845" y="298" class="detail">OpenAI Realtime protocol</text>
<rect x="1200" y="190" width="320" height="145" rx="16" fill="#fff2dd" stroke="#c56a08" stroke-width="1.8"/>
<rect x="1200" y="212" width="5" height="101" rx="2" fill="#c56a08"/>
<text x="1220" y="230" class="node">OpenAI Realtime</text>
<text x="1220" y="268" class="detail">gpt-realtime-2.1 / Marin</text>
<text x="1220" y="298" class="detail">Audio, transcripts, tool calls</text>
<rect x="75" y="435" width="320" height="145" rx="16" fill="#f2eaff" stroke="#7c3aed" stroke-width="1.8"/>
<rect x="75" y="457" width="5" height="101" rx="2" fill="#7c3aed"/>
<text x="95" y="475" class="node">Immutable file storage</text>
<text x="95" y="513" class="detail">Originals and extraction artifacts</text>
<text x="95" y="543" class="detail">Checksums and frozen profiles</text>
<rect x="450" y="435" width="320" height="145" rx="16" fill="#f2eaff" stroke="#7c3aed" stroke-width="1.8"/>
<rect x="450" y="457" width="5" height="101" rx="2" fill="#7c3aed"/>
<text x="470" y="475" class="node">PostgreSQL + pgvector</text>
<text x="470" y="513" class="detail">Documents, jobs, chunks, sessions</text>
<text x="470" y="543" class="detail">Evidence and audit records</text>
<rect x="825" y="435" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="825" y="457" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="845" y="475" class="node">Backend SearchService</text>
<text x="845" y="513" class="detail">Shared bounded retrieval</text>
<text x="845" y="543" class="detail">Eligibility and revision checks</text>
<rect x="1200" y="435" width="320" height="145" rx="16" fill="#fff2dd" stroke="#c56a08" stroke-width="1.8"/>
<rect x="1200" y="457" width="5" height="101" rx="2" fill="#c56a08"/>
<text x="1220" y="475" class="node">Local embedding service</text>
<text x="1220" y="513" class="detail">Ollama / bge-m3</text>
<text x="1220" y="543" class="detail">Document and query vectors</text>
<rect x="75" y="680" width="320" height="145" rx="16" fill="#e8f0fe" stroke="#2563eb" stroke-width="1.8"/>
<rect x="75" y="702" width="5" height="101" rx="2" fill="#2563eb"/>
<text x="95" y="720" class="node">Admin knowledge selection</text>
<text x="95" y="758" class="detail">Ready is not yet searchable</text>
<text x="95" y="788" class="detail">Explicit active selection</text>
<rect x="450" y="680" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="450" y="702" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="470" y="720" class="node">Separate ingestion worker</text>
<text x="470" y="758" class="detail">Claim, extract, chunk, embed</text>
<text x="470" y="788" class="detail">Lease-fenced atomic publication</text>
<rect x="825" y="680" width="320" height="145" rx="16" fill="#fff2dd" stroke="#c56a08" stroke-width="1.8"/>
<rect x="825" y="702" width="5" height="101" rx="2" fill="#c56a08"/>
<text x="845" y="720" class="node">Vision extraction adapter</text>
<text x="845" y="758" class="detail">OpenRouter / Gemini 2.5 Flash</text>
<text x="845" y="788" class="detail">Affected PDF pages and images</text>
<rect x="1200" y="680" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="1200" y="702" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="1220" y="720" class="node">Operational control</text>
<text x="1220" y="758" class="detail">Health, structured diagnostics</text>
<text x="1220" y="788" class="detail">Original API retained for rollback</text>
<text x="75" y="890" class="detail">Scope: current voice MVP. Full text chat/history and production multi-API recovery are not presented as complete.</text>
<circle cx="83" cy="962" r="7" fill="#2563eb"/><text x="100" y="968" class="detail">Frontend / admin</text>
<circle cx="458" cy="962" r="7" fill="#0f766e"/><text x="475" y="968" class="detail">Backend logic</text>
<circle cx="833" cy="962" r="7" fill="#7c3aed"/><text x="850" y="968" class="detail">Persistent state</text>
<circle cx="1208" cy="962" r="7" fill="#c56a08"/><text x="1225" y="968" class="detail">AI / embedding provider</text>
</svg>

After

Width:  |  Height:  |  Size: 7.5 KiB

+25
View File
@@ -0,0 +1,25 @@
flowchart TD
A[Admin upload + Idempotency-Key] --> B[Authorization / size / MIME / structural validation]
B --> C[Store immutable original + SHA256]
C --> D[Create new document + frozen profile + queued job]
D --> E[Worker claim + lease token + heartbeat]
E --> F[Read original + verify digest / claim]
F --> G{Format / retained artifact?}
G -->|Valid retained extraction| J[Extraction artifact / faithful blocks]
G -->|DOCX / readable text| H[Direct extraction]
G -->|PDF| P[Direct text; vision for affected pages]
G -->|JPEG / PNG| V[Vision transcription]
H --> Q[Quality / provenance / bounds checks]
P --> Q
V --> Q
Q -->|Strict policy needs review| R[Retain review candidate; failed / review pending]
R -->|Approved + explicit same-job retry| E
Q -->|Accept; partial mode keeps warnings| J
Q -->|Unusable / invalid output| X[Failed; classified reason]
X -->|Eligible explicit same-job retry| E
J --> K[Group-aware chunking + search normalization]
K --> L[Bounded batched embeddings: local bge-m3]
L --> M[Atomic fenced publication: chunks + vectors]
M --> N[Document ready; inactive]
N --> O[Admin activates selected knowledge]
O --> S[Searchable: ready + active + authorized + undeleted]
Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

+85
View File
@@ -0,0 +1,85 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1600" height="1000" viewBox="0 0 1600 1000" role="img">
<title>Document ingestion pipeline</title>
<desc>Independent uploads, bounded extraction and atomic publication</desc>
<defs><marker id="arrow" markerWidth="9" markerHeight="9" refX="8" refY="4.5" orient="auto"><path d="M0,0 L9,4.5 L0,9" fill="#64748b"/></marker></defs>
<rect width="1600" height="1000" fill="#ffffff"/>
<style>text{font-family:Segoe UI,Arial,sans-serif}.title{font-size:38px;font-weight:700;fill:#0f172a}.sub{font-size:21px;fill:#475569}.node{font-size:21px;font-weight:650;fill:#0f172a}.detail{font-size:17px;fill:#475569}.edge{font-size:14px;fill:#475569}</style>
<text x="75" y="75" class="title">Document ingestion pipeline</text>
<text x="75" y="115" class="sub">Independent uploads, bounded extraction and atomic publication</text>
<path d="M395,262.5 L450,262.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M770,262.5 L825,262.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M1145,262.5 L1200,262.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M1360.0,335 L1360.0,435" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M1200,507.5 L1145,507.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M825,507.5 L770,507.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M450,507.5 L395,507.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M235.0,580 L235.0,680" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M395,752.5 L450,752.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M770,752.5 L825,752.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M1145,752.5 L1200,752.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<rect x="75" y="190" width="320" height="145" rx="16" fill="#e8f0fe" stroke="#2563eb" stroke-width="1.8"/>
<rect x="75" y="212" width="5" height="101" rx="2" fill="#2563eb"/>
<text x="95" y="230" class="node">1. Admin upload</text>
<text x="95" y="268" class="detail">Cookie, role, CSRF</text>
<text x="95" y="298" class="detail">Idempotency-Key</text>
<rect x="450" y="190" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="450" y="212" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="470" y="230" class="node">2. Validate intake</text>
<text x="470" y="268" class="detail">Size, MIME, file structure</text>
<text x="470" y="298" class="detail">SHA256 of original</text>
<rect x="825" y="190" width="320" height="145" rx="16" fill="#f2eaff" stroke="#7c3aed" stroke-width="1.8"/>
<rect x="825" y="212" width="5" height="101" rx="2" fill="#7c3aed"/>
<text x="845" y="230" class="node">3. Persist original</text>
<text x="845" y="268" class="detail">Immutable content on disk</text>
<text x="845" y="298" class="detail">New document; frozen profile</text>
<rect x="1200" y="190" width="320" height="145" rx="16" fill="#f2eaff" stroke="#7c3aed" stroke-width="1.8"/>
<rect x="1200" y="212" width="5" height="101" rx="2" fill="#7c3aed"/>
<text x="1220" y="230" class="node">4. Queue job</text>
<text x="1220" y="268" class="detail">Database-backed ingestion job</text>
<text x="1220" y="298" class="detail">No external message broker</text>
<rect x="75" y="435" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="75" y="457" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="95" y="475" class="node">8. Chunk + normalize</text>
<text x="95" y="513" class="detail">Source order / groups / locations</text>
<text x="95" y="543" class="detail">Search text separate from source</text>
<rect x="450" y="435" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="450" y="457" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="470" y="475" class="node">7. Quality admission</text>
<text x="470" y="513" class="detail">Strict review OR opt-in partial</text>
<text x="470" y="543" class="detail">Keep warnings; reject unusable</text>
<rect x="825" y="435" width="320" height="145" rx="16" fill="#fff2dd" stroke="#c56a08" stroke-width="1.8"/>
<rect x="825" y="457" width="5" height="101" rx="2" fill="#c56a08"/>
<text x="845" y="475" class="node">6. Extract text</text>
<text x="845" y="513" class="detail">DOCX/text: direct; PDF: fallback</text>
<text x="845" y="543" class="detail">Images: hosted vision</text>
<rect x="1200" y="435" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="1200" y="457" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="1220" y="475" class="node">5. Worker claim</text>
<text x="1220" y="513" class="detail">Lease + fencing token</text>
<text x="1220" y="543" class="detail">Heartbeat and ownership checks</text>
<rect x="75" y="680" width="320" height="145" rx="16" fill="#fff2dd" stroke="#c56a08" stroke-width="1.8"/>
<rect x="75" y="702" width="5" height="101" rx="2" fill="#c56a08"/>
<text x="95" y="720" class="node">9. Embed bounded batches</text>
<text x="95" y="758" class="detail">Local Ollama / bge-m3</text>
<text x="95" y="788" class="detail">Stage results before publish</text>
<rect x="450" y="680" width="320" height="145" rx="16" fill="#f2eaff" stroke="#7c3aed" stroke-width="1.8"/>
<rect x="450" y="702" width="5" height="101" rx="2" fill="#7c3aed"/>
<text x="470" y="720" class="node">10. Atomic publication</text>
<text x="470" y="758" class="detail">Commit chunks + vectors together</text>
<text x="470" y="788" class="detail">Fenced by current claim</text>
<rect x="825" y="680" width="320" height="145" rx="16" fill="#f2eaff" stroke="#7c3aed" stroke-width="1.8"/>
<rect x="825" y="702" width="5" height="101" rx="2" fill="#7c3aed"/>
<text x="845" y="720" class="node">11. Ready / inactive</text>
<text x="845" y="758" class="detail">No partial searchable document</text>
<text x="845" y="788" class="detail">Same-job retry on eligible failure</text>
<rect x="1200" y="680" width="320" height="145" rx="16" fill="#e8f0fe" stroke="#2563eb" stroke-width="1.8"/>
<rect x="1200" y="702" width="5" height="101" rx="2" fill="#2563eb"/>
<text x="1220" y="720" class="node">12. Activate knowledge</text>
<text x="1220" y="758" class="detail">Admin selects ready document</text>
<text x="1220" y="788" class="detail">Revision / access invalidation</text>
<text x="75" y="890" class="detail">Review is conditional. Local partial-admission mode bypasses manual approval; malformed data, identity and bounds still fail.</text>
<circle cx="83" cy="962" r="7" fill="#2563eb"/><text x="100" y="968" class="detail">Frontend / admin</text>
<circle cx="458" cy="962" r="7" fill="#0f766e"/><text x="475" y="968" class="detail">Backend logic</text>
<circle cx="833" cy="962" r="7" fill="#7c3aed"/><text x="850" y="968" class="detail">Persistent state</text>
<circle cx="1208" cy="962" r="7" fill="#c56a08"/><text x="1225" y="968" class="detail">AI / embedding provider</text>
</svg>

After

Width:  |  Height:  |  Size: 7.1 KiB

+46
View File
@@ -0,0 +1,46 @@
sequenceDiagram
autonumber
participant U as Browser / AudioWorklet
participant A as FastAPI / Live lifecycle
participant R as VoiceRuntime
participant P as OpenAI Realtime
participant S as Backend search
U->>A: Create conversation + reserve voice session
A->>A: Auth / ownership / request dedup / freeze profile
A-->>U: Session ID + stream_path
U->>A: Open authenticated WebSocket
A->>A: Origin + cookie + pinned profile checks
A->>R: Start runtime + server-side adapter
R->>P: session.update
P-->>R: session.updated / acknowledged setup
R-->>U: session_ready
loop Each user turn
U->>R: PCM16LE mono 24kHz
R->>P: input_audio_buffer.append
P-->>R: VAD + input commit + transcription events
R->>P: response.create after authority / cleanup gates
opt Document question
P-->>R: Tool call
R->>S: Validate args + trusted scope + durable dedup
S-->>R: Revalidated evidence or normalized error
R->>P: Private tool result
P-->>R: report_used_sources
R-->>U: Validated used-source subset
end
P-->>R: Streaming audio / transcript / response.done
R-->>U: Bounded audio + application JSON events
U->>R: Playback progress / actual played position
opt User interrupts
P-->>R: speech_started
R-->>U: turn_interrupted; discard unheard audio
R->>P: response.cancel if generation is active
P-->>R: Terminal confirmation; correlated race allowed
U->>R: Final playback position
R->>P: conversation.item.truncate
P-->>R: Exact truncation acknowledgement
R->>R: Release next response only after cleanup
Note over R,S: Same-topic pending search survives speech interruption
end
end
U->>A: Explicit close
A->>R: Cancel tasks / release provider / persist outcome
Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

+87
View File
@@ -0,0 +1,87 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1600" height="1000" viewBox="0 0 1600 1000" role="img">
<title>Live voice session and streaming</title>
<desc>Control lifecycle plus continuous bidirectional media</desc>
<defs><marker id="arrow" markerWidth="9" markerHeight="9" refX="8" refY="4.5" orient="auto"><path d="M0,0 L9,4.5 L0,9" fill="#64748b"/></marker></defs>
<rect width="1600" height="1000" fill="#ffffff"/>
<style>text{font-family:Segoe UI,Arial,sans-serif}.title{font-size:38px;font-weight:700;fill:#0f172a}.sub{font-size:21px;fill:#475569}.node{font-size:21px;font-weight:650;fill:#0f172a}.detail{font-size:17px;fill:#475569}.edge{font-size:14px;fill:#475569}</style>
<text x="75" y="75" class="title">Live voice session and streaming</text>
<text x="75" y="115" class="sub">Control lifecycle plus continuous bidirectional media</text>
<path d="M395,262.5 L450,262.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M770,262.5 L825,262.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M1145,262.5 L1200,262.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M1360.0,335 L1360.0,435" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M1200,507.5 L1145,507.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M825,507.5 L770,507.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M450,507.5 L395,507.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M235.0,580 L235.0,680" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M395,752.5 L450,752.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M770,752.5 L825,752.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M1145,752.5 L1200,752.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<rect x="75" y="190" width="320" height="145" rx="16" fill="#e8f0fe" stroke="#2563eb" stroke-width="1.8"/>
<rect x="75" y="212" width="5" height="101" rx="2" fill="#2563eb"/>
<text x="95" y="230" class="node">1. Reserve session</text>
<text x="95" y="268" class="detail">Create conversation + voice ID</text>
<text x="95" y="298" class="detail">Auth / ownership / request dedup</text>
<rect x="450" y="190" width="320" height="145" rx="16" fill="#f2eaff" stroke="#7c3aed" stroke-width="1.8"/>
<rect x="450" y="212" width="5" height="101" rx="2" fill="#7c3aed"/>
<text x="470" y="230" class="node">2. Freeze execution profile</text>
<text x="470" y="268" class="detail">Model, voice, ASR, limits</text>
<text x="470" y="298" class="detail">Knowledge / access revisions</text>
<rect x="825" y="190" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="825" y="212" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="845" y="230" class="node">3. Admit browser WebSocket</text>
<text x="845" y="268" class="detail">Origin + cookie + profile check</text>
<text x="845" y="298" class="detail">Browser PCM: mono 24 kHz</text>
<rect x="1200" y="190" width="320" height="145" rx="16" fill="#fff2dd" stroke="#c56a08" stroke-width="1.8"/>
<rect x="1200" y="212" width="5" height="101" rx="2" fill="#c56a08"/>
<text x="1220" y="230" class="node">4. Provider setup</text>
<text x="1220" y="268" class="detail">Server-side connection + secrets</text>
<text x="1220" y="298" class="detail">Wait for setup acknowledgement</text>
<rect x="75" y="435" width="320" height="145" rx="16" fill="#e8f0fe" stroke="#2563eb" stroke-width="1.8"/>
<rect x="75" y="457" width="5" height="101" rx="2" fill="#2563eb"/>
<text x="95" y="475" class="node">8. Interrupted playback</text>
<text x="95" y="513" class="detail">Stop old output; report played ms</text>
<text x="95" y="543" class="detail">Discard buffered unheard audio</text>
<rect x="450" y="435" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="450" y="457" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="470" y="475" class="node">7. Bounded delivery</text>
<text x="470" y="513" class="detail">Audio + transcript + sources</text>
<text x="470" y="543" class="detail">Playback credit / progress</text>
<rect x="825" y="435" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="825" y="457" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="845" y="475" class="node">6. Turn orchestration</text>
<text x="845" y="513" class="detail">Authority + terminal gates</text>
<text x="845" y="543" class="detail">Trusted evidence tools as needed</text>
<rect x="1200" y="435" width="320" height="145" rx="16" fill="#fff2dd" stroke="#c56a08" stroke-width="1.8"/>
<rect x="1200" y="457" width="5" height="101" rx="2" fill="#c56a08"/>
<text x="1220" y="475" class="node">5. Incoming speech</text>
<text x="1220" y="513" class="detail">PCM relay; provider VAD + ASR</text>
<text x="1220" y="543" class="detail">Runtime controls response.create</text>
<rect x="75" y="680" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="75" y="702" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="95" y="720" class="node">9. Cancel generation</text>
<text x="95" y="758" class="detail">Correlate cancellation intent</text>
<text x="95" y="788" class="detail">Require terminal confirmation</text>
<rect x="450" y="680" width="320" height="145" rx="16" fill="#fff2dd" stroke="#c56a08" stroke-width="1.8"/>
<rect x="450" y="702" width="5" height="101" rx="2" fill="#c56a08"/>
<text x="470" y="720" class="node">10. Synchronize context</text>
<text x="470" y="758" class="detail">Truncate at actual played position</text>
<text x="470" y="788" class="detail">Require exact acknowledgement</text>
<rect x="825" y="680" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="825" y="702" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="845" y="720" class="node">11. Release next response</text>
<text x="845" y="758" class="detail">After all cleanup gates</text>
<text x="845" y="788" class="detail">Same-topic search may survive</text>
<rect x="1200" y="680" width="320" height="145" rx="16" fill="#f2eaff" stroke="#7c3aed" stroke-width="1.8"/>
<rect x="1200" y="702" width="5" height="101" rx="2" fill="#7c3aed"/>
<text x="1220" y="720" class="node">12. Close / fail safely</text>
<text x="1220" y="758" class="detail">Cancel tasks + release provider</text>
<text x="1220" y="788" class="detail">Persist outcome; fresh session</text>
<text x="75" y="890" class="detail">This is a lifecycle summary, not serial audio processing. See the sequence diagram for asynchronous events and acknowledgements.</text>
<circle cx="83" cy="962" r="7" fill="#2563eb"/><text x="100" y="968" class="detail">Frontend / admin</text>
<circle cx="458" cy="962" r="7" fill="#0f766e"/><text x="475" y="968" class="detail">Backend logic</text>
<circle cx="833" cy="962" r="7" fill="#7c3aed"/><text x="850" y="968" class="detail">Persistent state</text>
<circle cx="1208" cy="962" r="7" fill="#c56a08"/><text x="1225" y="968" class="detail">AI / embedding provider</text>
</svg>

After

Width:  |  Height:  |  Size: 7.2 KiB

+24
View File
@@ -0,0 +1,24 @@
flowchart TD
A[Committed user speech + provider context] --> B[Realtime model + grounding / Persian delivery policy]
B --> C{Need document evidence?}
C -->|Greeting / focused clarification| Z[Short answer without retrieval]
C -->|New topic| D[search_knowledge]
C -->|Same-topic continuation| E[reuse_last_evidence]
E -->|Retained search / current eligibility| J
E -->|Fresh search required| D
D --> F[Validate tool args / backend identity / deadline / durable dedup]
F --> G[Normalize query + local bge-m3 embedding]
G --> H[PostgreSQL: semantic + exact-pattern branches]
H --> I[Merge / deduplicate / measured cutoff / bounded evidence]
I --> J[Recheck authority / revisions / document eligibility]
J --> K{Backend result}
K -->|ok| L[Private evidence to model: document_id + chunk_id + labels]
K -->|no_evidence| N[Say evidence is insufficient; invent no facts]
K -->|error| X[Say technical check failed; invent no fallback]
L --> M[report_used_sources: only supporting current-turn labels]
M --> V[Backend validates reported labels and delivery eligibility]
V -->|Invalid report| M
V -->|Valid subset| O[Sources event to browser]
V --> P[Model generates grounded spoken answer]
P --> Q[VoiceRuntime: audio / transcript / playback / interruption gates]
Q --> U[Browser playback + rendered used sources]
Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

+87
View File
@@ -0,0 +1,87 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1600" height="1000" viewBox="0 0 1600 1000" role="img">
<title>AI and grounded retrieval pipeline</title>
<desc>The model chooses tools; the backend owns identity and evidence</desc>
<defs><marker id="arrow" markerWidth="9" markerHeight="9" refX="8" refY="4.5" orient="auto"><path d="M0,0 L9,4.5 L0,9" fill="#64748b"/></marker></defs>
<rect width="1600" height="1000" fill="#ffffff"/>
<style>text{font-family:Segoe UI,Arial,sans-serif}.title{font-size:38px;font-weight:700;fill:#0f172a}.sub{font-size:21px;fill:#475569}.node{font-size:21px;font-weight:650;fill:#0f172a}.detail{font-size:17px;fill:#475569}.edge{font-size:14px;fill:#475569}</style>
<text x="75" y="75" class="title">AI and grounded retrieval pipeline</text>
<text x="75" y="115" class="sub">The model chooses tools; the backend owns identity and evidence</text>
<path d="M395,262.5 L450,262.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M770,262.5 L825,262.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M1145,262.5 L1200,262.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M1360.0,335 L1360.0,435" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M1200,507.5 L1145,507.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M825,507.5 L770,507.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M450,507.5 L395,507.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M235.0,580 L235.0,680" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M395,752.5 L450,752.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M770,752.5 L825,752.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<path d="M1145,752.5 L1200,752.5" fill="none" stroke="#94a3b8" stroke-width="2.2" marker-end="url(#arrow)"/>
<rect x="75" y="190" width="320" height="145" rx="16" fill="#fff2dd" stroke="#c56a08" stroke-width="1.8"/>
<rect x="75" y="212" width="5" height="101" rx="2" fill="#c56a08"/>
<text x="95" y="230" class="node">1. Committed user speech</text>
<text x="95" y="268" class="detail">Audio + current conversation</text>
<text x="95" y="298" class="detail">Grounding and delivery policy</text>
<rect x="450" y="190" width="320" height="145" rx="16" fill="#fff2dd" stroke="#c56a08" stroke-width="1.8"/>
<rect x="450" y="212" width="5" height="101" rx="2" fill="#c56a08"/>
<text x="470" y="230" class="node">2. Decide evidence need</text>
<text x="470" y="268" class="detail">New topic: search_knowledge</text>
<text x="470" y="298" class="detail">Same topic: reuse_last_evidence</text>
<rect x="825" y="190" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="825" y="212" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="845" y="230" class="node">3. Trusted tool dispatch</text>
<text x="845" y="268" class="detail">Validate schema / deadline</text>
<text x="845" y="298" class="detail">Backend identity; durable dedup</text>
<rect x="1200" y="190" width="320" height="145" rx="16" fill="#fff2dd" stroke="#c56a08" stroke-width="1.8"/>
<rect x="1200" y="212" width="5" height="101" rx="2" fill="#c56a08"/>
<text x="1220" y="230" class="node">4. Query embedding</text>
<text x="1220" y="268" class="detail">Normalize query</text>
<text x="1220" y="298" class="detail">Local bge-m3 vector</text>
<rect x="75" y="435" width="320" height="145" rx="16" fill="#fff2dd" stroke="#c56a08" stroke-width="1.8"/>
<rect x="75" y="457" width="5" height="101" rx="2" fill="#c56a08"/>
<text x="95" y="475" class="node">8. Prepare supported answer</text>
<text x="95" y="513" class="detail">Preserve names / dates / limits</text>
<text x="95" y="543" class="detail">No invented missing facts</text>
<rect x="450" y="435" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="450" y="457" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="470" y="475" class="node">7. Private evidence result</text>
<text x="470" y="513" class="detail">ok / no_evidence / error</text>
<text x="470" y="543" class="detail">Document + chunk identities</text>
<rect x="825" y="435" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="825" y="457" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="845" y="475" class="node">6. Admit evidence</text>
<text x="845" y="513" class="detail">Measured cutoff; max 5 chunks</text>
<text x="845" y="543" class="detail">Max 12,000 chars per retrieval</text>
<rect x="1200" y="435" width="320" height="145" rx="16" fill="#f2eaff" stroke="#7c3aed" stroke-width="1.8"/>
<rect x="1200" y="457" width="5" height="101" rx="2" fill="#7c3aed"/>
<text x="1220" y="475" class="node">5. Hybrid retrieval</text>
<text x="1220" y="513" class="detail">Semantic + exact-pattern search</text>
<text x="1220" y="543" class="detail">Ready, active, authorized only</text>
<rect x="75" y="680" width="320" height="145" rx="16" fill="#fff2dd" stroke="#c56a08" stroke-width="1.8"/>
<rect x="75" y="702" width="5" height="101" rx="2" fill="#c56a08"/>
<text x="95" y="720" class="node">9. Declare used sources</text>
<text x="95" y="758" class="detail">report_used_sources</text>
<text x="95" y="788" class="detail">Only supporting current-turn labels</text>
<rect x="450" y="680" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="450" y="702" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="470" y="720" class="node">10. Validate and deliver</text>
<text x="470" y="758" class="detail">Recheck scope / label / eligibility</text>
<text x="470" y="788" class="detail">Invalid reports corrected privately</text>
<rect x="825" y="680" width="320" height="145" rx="16" fill="#e6f7f2" stroke="#0f766e" stroke-width="1.8"/>
<rect x="825" y="702" width="5" height="101" rx="2" fill="#0f766e"/>
<text x="845" y="720" class="node">11. Stream answer</text>
<text x="845" y="758" class="detail">Audio + transcript</text>
<text x="845" y="788" class="detail">Runtime playback / interruption</text>
<rect x="1200" y="680" width="320" height="145" rx="16" fill="#e8f0fe" stroke="#2563eb" stroke-width="1.8"/>
<rect x="1200" y="702" width="5" height="101" rx="2" fill="#2563eb"/>
<text x="1220" y="720" class="node">12. Browser presentation</text>
<text x="1220" y="758" class="detail">Play audio; show used subset</text>
<text x="1220" y="788" class="detail">Retrieval candidates stay private</text>
<text x="75" y="890" class="detail">Retrieval branches: 50 semantic + up to 50 exact-pattern candidates, deduplicated. Greetings need no retrieval; failures never authorize</text>
<text x="75" y="915" class="detail">fallback facts.</text>
<circle cx="83" cy="962" r="7" fill="#2563eb"/><text x="100" y="968" class="detail">Frontend / admin</text>
<circle cx="458" cy="962" r="7" fill="#0f766e"/><text x="475" y="968" class="detail">Backend logic</text>
<circle cx="833" cy="962" r="7" fill="#7c3aed"/><text x="850" y="968" class="detail">Persistent state</text>
<circle cx="1208" cy="962" r="7" fill="#c56a08"/><text x="1225" y="968" class="detail">AI / embedding provider</text>
</svg>

After

Width:  |  Height:  |  Size: 7.2 KiB

+199
View File
@@ -0,0 +1,199 @@
# دیاگرام‌های ارائهٔ فنی پروژه
مجموعه بر اساس کد فعلی پروژه، ۱۴ اکتبر ۲۰۲۶ تهیه شده است. SVGها مستقل‌اند و برای ورود مستقیم به PowerPoint مناسب‌اند. متن داخل دیاگرام‌ها انگلیسی است و نسخهٔ Mermaid برای ویرایش مسیرها کنار هر تصویر قرار دارد.
[نمایش همهٔ دیاگرام‌ها در مرورگر](index.html)
[PDF چهارصفحه‌ای](technical-pipelines.pdf)
## ۱. معماری کلی برنامه
[SVG](01-system.svg) · [PNG](01-system.png) · [Mermaid](01-system.mmd)
Angular با REST و WebSocket به FastAPI متصل می‌شود. API احراز هویت، مجوزها، انتخاب دانش و سشن صوتی را کنترل می‌کند. worker مستقل اسناد را پردازش می‌کند؛ صف jobها داخل PostgreSQL است و broker جدا ندارد. فایل‌های اصلی و آرتیفکت‌های استخراج روی دیسک هستند؛ اسناد، jobها، چانک‌ها، بردارها، سشن‌ها و نتایج ابزار در PostgreSQL/pgvector نگهداری می‌شوند. OpenAI از طریق اداپتور سرور به مسیر صوت متصل است و کلید آن به مرورگر ارسال نمی‌شود.
## ۲. پایپلاین اینجست
[SVG](02-ingestion.svg) · [PNG](02-ingestion.png) · [Mermaid](02-ingestion.mmd)
آپلود با مجوز ادمین و Idempotency-Key آغاز می‌شود. نوع، حجم و ساختار فایل بررسی می‌شود؛ اصل فایل، SHA256 و پروفایل پردازش ثابت نگه داشته می‌شوند. هر آپلود سند مستقلی می‌سازد. worker با claim، lease، heartbeat و fencing کار را می‌گیرد.
DOCX و متن خوانا مستقیم استخراج می‌شوند؛ PDF فقط در صفحات نیازمند fallback و عکس‌ها از vision استفاده می‌کنند. پس از بررسی استخراج، چانک‌سازی، نرمال‌سازی متن جستجو و امبدینگ دسته‌ای انجام می‌شود. انتشار چانک‌ها و بردارها اتمیک است؛ سند ناقص وارد جستجو نمی‌شود.
سند ready ابتدا inactive است؛ ادمین باید آن را برای جستجو فعال کند. تأیید انسانی به سیاست پردازش وابسته است؛ تنظیم فعلی allow_partial_extraction فعال است و هشدارهای قابل‌استفاده را می‌پذیرد. این حالت تضمین صحت کامل OCR نیست. retry روی همان سند و job ناموفق واجد شرایط اجرا می‌شود و محتوای اصلی را بازنویسی نمی‌کند.
## ۳. سشن صوتی و استریم
[SVG](03-live-session.svg) · [PNG](03-live-session.png) · [Mermaid sequence](03-live-session.mmd)
conversation و voice session رزرو می‌شوند و مدل، صدا، تنظیمات و پروفایل اجرا ثابت می‌شوند. WebSocket مرورگر با cookie، Origin، مالکیت و پروفایل بررسی می‌شود. پس از تأیید تنظیمات provider، session_ready ارسال می‌شود. صوت مرورگر PCM16LE تک‌کاناله با نرخ ۲۴ کیلوهرتز است. OpenAI تشخیص گفتار/VAD و transcription را ارائه می‌دهد، اما runtime ایجاد پاسخ را کنترل می‌کند.
صدا و رویدادهای transcript و sources با بافر محدود و اعتبار پخش تحویل می‌شوند. هنگام وقفه، صدای شنیده‌نشده کنار گذاشته می‌شود؛ پایان پاسخ و حذف صوت در موقعیت واقعی پخش باید تأیید شوند تا پاسخ نوبت بعد آزاد شود. جستجوی همان موضوع می‌تواند با وجود قطع صدا حفظ شود. شکست همگام‌سازی، timeout یا خطای فنی ممکن است جلسه را ببندد؛ resume بی‌وقفه بعد از restart هنوز قابلیت کامل این مسیر نیست.
## ۴. AI و RAG
[SVG](04-ai-rag.svg) · [PNG](04-ai-rag.png) · [Mermaid](04-ai-rag.mmd)
مدل برای موضوع جدید search_knowledge و برای ادامهٔ همان موضوع reuse_last_evidence را انتخاب می‌کند. backend پارامترها، deadline، هویت، دسترسی و dedup ابزار را کنترل می‌کند. query با bge-m3 امبد می‌شود؛ شاخه‌های semantic و exact-pattern روی اسناد مجاز، ready، active و حذف‌نشده اجرا می‌شوند. exact-pattern را به‌عنوان BM25 یا reranker معرفی نکنید؛ چنین مرحله‌ای در این مسیر وجود ندارد.
هر شاخه حداکثر ۵۰ candidate می‌آورد. پس از ادغام، حذف تکرار و cutoff کالیبره‌شده، هر retrieval حداکثر ۵ چانک و ۱۲٬۰۰۰ کاراکتر شاهد تحویل می‌دهد؛ این سقف مجموع همهٔ ابزارهای یک نوبت نیست. دسترسی و revisionها در handoff و delivery دوباره بررسی می‌شوند. پاسخ backend سه حالت ok، no_evidence و error دارد.
مدل با report_used_sources فقط منابع استفاده‌شده در پاسخ را اعلام می‌کند. backend اعتبار برچسب‌ها و وضعیت اسناد را بررسی می‌کند و همان زیرمجموعه در UI نمایش داده می‌شود. اعتبارسنجی تعلق منبع، تضمین صحت کامل همهٔ ادعاهای مدل نیست. سلام و سؤال روشن‌کننده به retrieval نیاز ندارند.
## وضعیت فعلی و مرزهای ارائه
- Voice: OpenAI gpt-realtime-2.1، صدای Marin، دستور گفتار فارسی v7.
- Embeddings: Ollama / bge-m3 محلی؛ vision: OpenRouter / Gemini 2.5 Flash.
- سرعت ۱٫۳۰ و سقف پاسخ ۲۰۴۸ وضعیت فعلی‌اند، نه پیش‌فرض ثابت معماری.
- نمودارها مسیر MVP صوتی پیاده‌شده را نشان می‌دهند. چت متنی کامل، تاریخچهٔ کامل صوتی ذخیره‌شده، بازیابی seamless سشن پس از restart و اجرای چند API هم‌زمان را تکمیل‌شده معرفی نکنید.
- کانتینر اصلی API برای rollback محفوظ است. دو API روی همین دیتابیس نباید هم‌زمان اجرا شوند، چون reconciliation راه‌اندازی مشترک دارند.
## نقشهٔ کد برای سؤال‌های فنی
| بخش | مسیر |
| --- | --- |
| Upload / retry | app/api/v1/documents.py، app/modules/documents/intake.py |
| Worker / claim / publish | app/modules/documents/worker.py، app/infrastructure/worker_repository.py |
| Extraction / chunking | app/modules/documents/extraction.py، app/modules/documents/chunking.py |
| OCR adapter | app/infrastructure/openrouter_vision.py |
| Auth / session admission | app/modules/auth/service.py، app/api/v1/live.py |
| Runtime / playback / interruption | app/modules/voice/runtime.py |
| Provider protocol | app/infrastructure/realtime.py |
| Tool / search | app/modules/knowledge/langchain_tool.py، app/modules/knowledge/service.py |
| Evidence / source delivery | app/modules/knowledge/evidence.py، app/modules/voice/durable_tools.py |
## نسخه‌های Mermaid
### 01-system
```mermaid
flowchart LR
U[User / Admin] --> UI[Angular frontend]
UI -->|REST + session cookie + CSRF| API[FastAPI API]
UI <-->|WebSocket: PCM + JSON events| API
API --> AUTH[Authentication / role / organization]
API -->|Upload: independent document + job| DB[(PostgreSQL + pgvector)]
API --> FS[(Immutable originals / extraction artifacts)]
W[Separate ingestion worker] -->|Claim job + lease + heartbeat| DB
W -->|Read original / retain extraction| FS
W --> OCR[OpenRouter vision / Gemini Flash]
W --> EMB[Local Ollama / bge-m3]
W -->|Atomic chunks + vectors publication| DB
API --> RT[OpenAI Realtime adapter]
RT <-->|Provider WebSocket| OAI[OpenAI gpt-realtime-2.1 / Marin]
RT -->|Validated tools| SEARCH[Shared backend SearchService]
SEARCH --> EMB
SEARCH -->|Eligible document chunks| DB
API -->|Selection / revision invalidation| DB
```
### 02-ingestion
```mermaid
flowchart TD
A[Admin upload + Idempotency-Key] --> B[Authorization / size / MIME / structural validation]
B --> C[Store immutable original + SHA256]
C --> D[Create new document + frozen profile + queued job]
D --> E[Worker claim + lease token + heartbeat]
E --> F[Read original + verify digest / claim]
F --> G{Format / retained artifact?}
G -->|Valid retained extraction| J[Extraction artifact / faithful blocks]
G -->|DOCX / readable text| H[Direct extraction]
G -->|PDF| P[Direct text; vision for affected pages]
G -->|JPEG / PNG| V[Vision transcription]
H --> Q[Quality / provenance / bounds checks]
P --> Q
V --> Q
Q -->|Strict policy needs review| R[Retain review candidate; failed / review pending]
R -->|Approved + explicit same-job retry| E
Q -->|Accept; partial mode keeps warnings| J
Q -->|Unusable / invalid output| X[Failed; classified reason]
X -->|Eligible explicit same-job retry| E
J --> K[Group-aware chunking + search normalization]
K --> L[Bounded batched embeddings: local bge-m3]
L --> M[Atomic fenced publication: chunks + vectors]
M --> N[Document ready; inactive]
N --> O[Admin activates selected knowledge]
O --> S[Searchable: ready + active + authorized + undeleted]
```
### 03-live-session
```mermaid
sequenceDiagram
autonumber
participant U as Browser / AudioWorklet
participant A as FastAPI / Live lifecycle
participant R as VoiceRuntime
participant P as OpenAI Realtime
participant S as Backend search
U->>A: Create conversation + reserve voice session
A->>A: Auth / ownership / request dedup / freeze profile
A-->>U: Session ID + stream_path
U->>A: Open authenticated WebSocket
A->>A: Origin + cookie + pinned profile checks
A->>R: Start runtime + server-side adapter
R->>P: session.update
P-->>R: session.updated / acknowledged setup
R-->>U: session_ready
loop Each user turn
U->>R: PCM16LE mono 24kHz
R->>P: input_audio_buffer.append
P-->>R: VAD + input commit + transcription events
R->>P: response.create after authority / cleanup gates
opt Document question
P-->>R: Tool call
R->>S: Validate args + trusted scope + durable dedup
S-->>R: Revalidated evidence or normalized error
R->>P: Private tool result
P-->>R: report_used_sources
R-->>U: Validated used-source subset
end
P-->>R: Streaming audio / transcript / response.done
R-->>U: Bounded audio + application JSON events
U->>R: Playback progress / actual played position
opt User interrupts
P-->>R: speech_started
R-->>U: turn_interrupted; discard unheard audio
R->>P: response.cancel if generation is active
P-->>R: Terminal confirmation; correlated race allowed
U->>R: Final playback position
R->>P: conversation.item.truncate
P-->>R: Exact truncation acknowledgement
R->>R: Release next response only after cleanup
Note over R,S: Same-topic pending search survives speech interruption
end
end
U->>A: Explicit close
A->>R: Cancel tasks / release provider / persist outcome
```
### 04-ai-rag
```mermaid
flowchart TD
A[Committed user speech + provider context] --> B[Realtime model + grounding / Persian delivery policy]
B --> C{Need document evidence?}
C -->|Greeting / focused clarification| Z[Short answer without retrieval]
C -->|New topic| D[search_knowledge]
C -->|Same-topic continuation| E[reuse_last_evidence]
E -->|Retained search / current eligibility| J
E -->|Fresh search required| D
D --> F[Validate tool args / backend identity / deadline / durable dedup]
F --> G[Normalize query + local bge-m3 embedding]
G --> H[PostgreSQL: semantic + exact-pattern branches]
H --> I[Merge / deduplicate / measured cutoff / bounded evidence]
I --> J[Recheck authority / revisions / document eligibility]
J --> K{Backend result}
K -->|ok| L[Private evidence to model: document_id + chunk_id + labels]
K -->|no_evidence| N[Say evidence is insufficient; invent no facts]
K -->|error| X[Say technical check failed; invent no fallback]
L --> M[report_used_sources: only supporting current-turn labels]
M --> V[Backend validates reported labels and delivery eligibility]
V -->|Invalid report| M
V -->|Valid subset| O[Sources event to browser]
V --> P[Model generates grounded spoken answer]
P --> Q[VoiceRuntime: audio / transcript / playback / interruption gates]
Q --> U[Browser playback + rendered used sources]
```
+1
View File
@@ -0,0 +1 @@
<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Technical pipeline diagrams</title><style>body{margin:0;background:#f1f5f9;color:#0f172a;font-family:Segoe UI,Arial,sans-serif}header,main{max-width:1440px;margin:auto;padding:28px}header p{color:#475569}section{background:white;border-radius:16px;margin-bottom:32px;padding:24px;box-shadow:0 3px 18px #0f172a0d}h1{font-size:32px}h2{margin:0 0 8px}section>h2,section>p:not(.links){display:none}p{color:#475569}img{display:block;width:100%;height:auto}a{color:#2563eb}@media print{body{background:white}header{display:none}main{padding:0;max-width:none}section{box-shadow:none;break-after:page;padding:0}.links{display:none}h2,section>p{display:none}@page{size:landscape;margin:10mm}}</style><header><h1>Technical pipeline diagrams</h1><p>Current voice MVP &middot; 14 October 2026 &middot; standalone SVG exports and editable Mermaid sources</p><a href="README.md">Persian presentation notes and implementation references</a></header><main><section><h2>System architecture</h2><p>Deployed application boundaries and shared storage</p><img src="01-system.svg" alt="System architecture"><p class="links"><a href="01-system.svg">SVG</a> &middot; <a href="01-system.mmd">Mermaid</a></p></section><section><h2>Document ingestion pipeline</h2><p>Independent uploads, bounded extraction and atomic publication</p><img src="02-ingestion.svg" alt="Document ingestion pipeline"><p class="links"><a href="02-ingestion.svg">SVG</a> &middot; <a href="02-ingestion.mmd">Mermaid</a></p></section><section><h2>Live voice session and streaming</h2><p>Control lifecycle plus continuous bidirectional media</p><img src="03-live-session.svg" alt="Live voice session and streaming"><p class="links"><a href="03-live-session.svg">SVG</a> &middot; <a href="03-live-session.mmd">Mermaid</a></p></section><section><h2>AI and grounded retrieval pipeline</h2><p>The model chooses tools; the backend owns identity and evidence</p><img src="04-ai-rag.svg" alt="AI and grounded retrieval pipeline"><p class="links"><a href="04-ai-rag.svg">SVG</a> &middot; <a href="04-ai-rag.mmd">Mermaid</a></p></section></main></html>
Binary file not shown.