feat(backend): deliver Phase 3 document and voice integration
Add authenticated upload, review, retry and knowledge-selection HTTP flows with bounded JSON processing and frozen OCR policy. Preserve Gemini/OpenAI provider selection and fenced lifecycle semantics; retain FAQ preambles and uncertain vision candidates, and expose opt-in uncalibrated voice transport diagnostics. Include frontend integration examples, aligned contracts and deterministic regressions. Validation: 1767 provider-free tests passed; all 404 PostgreSQL scenarios have passing evidence across the documented runs.
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
# RAG Assistant — Phase 1 API Catalog
|
||||
|
||||
Current voice decision (2026-10-09): **Gemini Live is temporarily the sole voice
|
||||
provider because an OpenAI Realtime voice key is unavailable.** The validated
|
||||
backend Gemini model/voice configuration is shared by reservation, stream and
|
||||
operator smoke. No OpenAI voice key is required. Extraction/embedding providers,
|
||||
frozen profiles, measured calibration and canonical search are unchanged.
|
||||
The provider-independent browser audio/events, direct document/chunk identities
|
||||
and durable owner/replay/revocation rules remain authoritative. Historical
|
||||
OpenAI checkpoints below remain historical. Gemini interruption closes safely
|
||||
where native sample-level context truncation cannot be verified; seamless
|
||||
barge-in is not certified. See [Phase 2 repair report](../guides/realtime-agent-phase2-repair.md).
|
||||
Current voice configuration (2026-10-09): **VOICE_PROVIDER=gemini|openai selects
|
||||
one backend adapter. Gemini remains the temporary default because an OpenAI
|
||||
Realtime voice key is unavailable.** Reservation, authenticated stream and
|
||||
operator smoke share the selected model/voice/profile. Only the selected voice
|
||||
key is required; there is no fallback or frontend provider selector. Legacy
|
||||
PROVIDER and existing GEMINI_* settings remain supported; conflicting provider
|
||||
aliases fail configuration. Dedicated OPENAI_REALTIME_* settings do not change
|
||||
embedding credentials. Browser PCM16LE remains mono 24 kHz in both directions.
|
||||
Pinned reservations cannot switch providers on connection or replay. Gemini
|
||||
interruption requiring unverified context truncation closes safely; OpenAI keeps
|
||||
its existing native cancellation/truncation contract. Canonical search, original
|
||||
documents, frozen profiles and owner/replay/revocation rules remain unchanged.
|
||||
See [Phase 2 repair report](../guides/realtime-agent-phase2-repair.md).
|
||||
|
||||
Version 1.3 · 2026-10-07 · Current Live document MVP contract; planned endpoints are not claimed operational.
|
||||
|
||||
@@ -93,7 +96,7 @@ No body. Same identity/CSRF/expiry shape as login. Missing/expired session retur
|
||||
|
||||
`multipart/form-data`: required `file`; optional `title`. Required `Idempotency-Key`. The server creates one independent document and ingestion job. New document is inactive.
|
||||
|
||||
Current local intake validates configured PDF, UTF-8 Markdown, DOCX, JPEG and PNG with byte/signature/package/image bounds and correct MIME. D01 accepts new files without a repository filename/hash allowlist. The four examples are acceptance fixtures, not upload eligibility. Stream/spool within configured limits; do not buffer an unbounded request. These engineering defaults do not imply every layout is extractable or total corpus capacity is unlimited. D01 HTTP transport remains planned.
|
||||
Current local intake validates configured PDF, UTF-8 Markdown, DOCX, JPEG and PNG with byte/signature/package/image bounds and correct MIME. D01 accepts new files without a repository filename/hash allowlist. The four examples are acceptance fixtures, not upload eligibility. Stream/spool within configured limits; do not buffer an unbounded request. These engineering defaults do not imply every layout is extractable or total corpus capacity is unlimited. D01 HTTP transport is implemented; see the Phase 3 handoff.
|
||||
|
||||
```json
|
||||
{"document_id":"10000000-0000-4000-8000-000000000001","job_id":"40000000-0000-4000-8000-000000000001","status":"queued","is_active":false,"searchable":false}
|
||||
@@ -111,7 +114,7 @@ Query: common pagination; optional `status=queued|processing|ready|failed`, `is_
|
||||
{"id":"10000000-0000-4000-8000-000000000001","title":"Working Hours","filename":"working-hours.pdf","status":"ready","is_active":false,"searchable":false,"created_at":"2026-10-05T09:00:00Z","chunk_count":8,"job":{"id":"40000000-0000-4000-8000-000000000001","status":"succeeded","stage":"publish","attempt_count":1,"retry_generation":0,"can_retry":false,"error":null}}
|
||||
```
|
||||
|
||||
`searchable = ready AND active AND not deleted AND not content-purged`. A review-required failure is failed with a safe reason and `review_required:true`; it is not a new lifecycle state. Detail may include `review_required:false` for other outcomes. D06 supplies retained review evidence only to admins. Poll while queued/processing; proposed interval 2 seconds, slow down when tab is hidden. Failed job exposes `{code,message,retryable}` without internal stack traces. `can_retry` means server allows retry of the unchanged original; corrupt input generally requires new upload. Return 404 for deleted/hidden ID.
|
||||
`searchable = ready AND active AND not deleted AND not content-purged`. A review-required failure is failed with a safe reason and `review_required:true`; it is not a new lifecycle state. Detail includes `review_required`, `review_state`, frozen `ocr_review_required` and `extraction_quality_decision` (null before complete extraction). D06 supplies retained review evidence only to admins. Poll while queued/processing; proposed interval 2 seconds, slow down when tab is hidden. Failed job exposes `{code,message,retryable}` without internal stack traces. `can_retry` means server allows retry of the unchanged original; corrupt input generally requires new upload. Return 404 for deleted/hidden ID.
|
||||
|
||||
### D04 — Retry failed processing
|
||||
|
||||
@@ -215,7 +218,7 @@ Duplicate IDs: 422. Any unready item: 409 `DOCUMENT_NOT_READY`, with rejected ID
|
||||
### F01 — Read
|
||||
|
||||
```json
|
||||
{"revision":1,"assistant_name":"Organization Assistant","instruction":"Reply concisely in Persian using authorized document evidence.","capabilities":{"text":false,"voice":true,"captions":true,"supported_upload_types":["<confirmed-MIME-type>"],"max_upload_bytes":null}}
|
||||
{"revision":1,"assistant_name":"Organization Assistant","instruction":"Reply concisely in Persian using authorized document evidence.","capabilities":{"text":false,"voice":true,"captions":true,"supported_upload_types":["<confirmed-MIME-type>"],"max_upload_bytes":20971520,"ocr_review_required":true}}
|
||||
```
|
||||
|
||||
Runtime must replace illustrative capability placeholders with actual configuration; `max_upload_bytes` is a positive integer in deployed responses. Add configured `max_pdf_pages` and a bounded `supported_structure_notes` description. Voice/captions capabilities reflect validated provider support, not assumed availability; captions=true above is the intended release outcome. The browser must not advertise full text chat. No settings mutation UI is required. No model secrets or selectable model list. Non-admin may read presentation settings/capabilities.
|
||||
@@ -276,15 +279,15 @@ Scope key `(conversation_id,client_request_id)`. Changed message under same key:
|
||||
|
||||
Path uses the original client request UUID, allowing recovery even if the POST response was lost. 200 returns T01 shape, including running/failed. 404 if no committed turn exists. If 404 after an ambiguous client timeout, retry the SAME POST/key; uniqueness handles races. Never generate a new key merely because a response was lost.
|
||||
|
||||
## 7. Voice contract — Gemini Live temporarily; frozen application audio/events
|
||||
## 7. Voice contract — backend-selected provider; frozen application audio/events
|
||||
|
||||
The current provider is Gemini Live managed by the backend. Earlier OpenAI-specific
|
||||
provider mechanisms below describe the retained Realtime adapter; the Gemini
|
||||
The selected provider is backend-managed Gemini Live or OpenAI Realtime. The
|
||||
OpenAI-specific mechanisms below describe the preserved Realtime adapter; the Gemini
|
||||
adapter uses native setupComplete, voiceActivity, toolCall/toolResponse and
|
||||
transcription. Missing verified input boundaries fail safely. Interruption
|
||||
requiring unheard-audio context repair closes the session rather than inventing
|
||||
a cancellation/truncation acknowledgement. The browser still uses 24 kHz mono
|
||||
PCM16LE; Gemini input conversion to 16 kHz occurs inside the adapter. This replaces revision 1.1's provisional SDP contract before frontend implementation. HTTP creation/poll/close, application WSS audio/events and internal model tools are separate contracts. None is verified as implemented. Phase 0 freezes the application audio/event fields below; implementation remains pending. These are application names, not provider-native event names. Provider events, response/item/call IDs, session objects and credentials remain private to the adapter; tool_call_id is an application correlation ID.
|
||||
PCM16LE; Gemini input conversion to 16 kHz occurs inside the adapter. This replaces revision 1.1's provisional SDP contract before frontend implementation. HTTP creation/poll/close, application WSS audio/events and internal model tools are separate contracts. Phase 0 freezes the application audio/event fields below. Technical implementation evidence and remaining live acceptance prerequisites are recorded in the Phase 2 repair report. These are application names, not provider-native event names. Provider events, response/item/call IDs, session objects and credentials remain private to the adapter; tool_call_id is an application correlation ID.
|
||||
|
||||
### V01 — Create session (HTTP)
|
||||
|
||||
@@ -557,3 +560,43 @@ safe codes never return keys or native provider errors. HTTP authentication
|
||||
failures normalize to `AUTH_REQUIRED`, CSRF to `CSRF_INVALID`, hidden resources
|
||||
to `NOT_FOUND`, admission throttling to `RATE_LIMITED` with Retry-After, and
|
||||
unexpected dependency failures to `DEPENDENCY_UNAVAILABLE`.
|
||||
|
||||
### OCR supervisor deployment policy (2026-10-09)
|
||||
|
||||
`INGEST_OCR_REVIEW_REQUIRED` defaults to true and is backend-only. New ingestion
|
||||
jobs freeze the boolean in `processing_profile.extraction.ocr_review_required`
|
||||
(the existing immutable document-owned snapshot for its one job). Workers and
|
||||
retries use that snapshot; absent fields in legacy profiles mean true. Preserve
|
||||
existing profile bytes/digests; do not backfill applied records. False permits
|
||||
clean OCR/vision output that passes existing automatic validation without a human
|
||||
extraction decision. It never waives non-OCR review, warning/integrity/coverage
|
||||
checks, independent factual-corpus approval, or explicit knowledge selection.
|
||||
Automatic extraction remains quality_decision=passed; mixed inspected/automatic
|
||||
PDFs use partially_reviewed with annotations only for inspected locators. Neither
|
||||
automatic OCR nor its portions in mixed PDFs creates a human review
|
||||
annotation/audit record. Ready publication remains inactive. Retained pending or
|
||||
rejected candidates still block retry; deployment changes cannot waive them.
|
||||
F01 capabilities.ocr_review_required is current deployment policy; D03 reports
|
||||
frozen ocr_review_required, review_state and extraction_quality_decision.
|
||||
See [Phase 3 handoff](../guides/realtime-agent-phase3-handoff.md).
|
||||
|
||||
|
||||
### Phase 3/4 additive admission diagnostics (2026-10-09)
|
||||
|
||||
V01, by-request recovery and V03 polling expose calibration_status with values
|
||||
calibrated, uncalibrated or unknown (legacy reservations without search metadata).
|
||||
It is derived from the frozen server execution profile, never supplied by clients.
|
||||
F01 capabilities additionally expose calibration_status and voice_transport_testing.
|
||||
With explicit server VOICE_TRANSPORT_TESTING=true, missing/pending calibration
|
||||
permits voice connectivity using configured embedding transport. This does not
|
||||
change Section 7.2 evidence admission: search returns error/CALIBRATION_REQUIRED
|
||||
without sources until measured calibration exists. Default false retains strict
|
||||
admission. Origin/CSRF, ownership, epochs, deduplication and provider pinning remain.
|
||||
|
||||
Leading unstyled FAQ introductions appear in factual review and in each included
|
||||
pair's source context. Recognition warnings or complete=false with legible blocks
|
||||
produce extraction review candidates, including when frozen ocr_review_required is
|
||||
false. D06/D07 and same-job D04 approval/retry semantics remain unchanged; no chunks
|
||||
are published while review is pending. Approval attests to exact output, including
|
||||
completeness; reject missing/inaccurate content rather than approve guesses. Fatal
|
||||
format/provenance/readability failures still map to EXTRACTION_QUALITY_FAILED.
|
||||
|
||||
Reference in New Issue
Block a user