fix(openai): prompt engineering and transcript model
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# RAG Assistant — Phase 1 API Catalog
|
||||
# RAG Assistant — Phase 1 API Catalog
|
||||
|
||||
Current voice configuration (2026-10-09): **VOICE_PROVIDER=gemini|openai selects
|
||||
one backend adapter. Gemini remains the temporary default because an OpenAI
|
||||
@@ -14,7 +14,7 @@ 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.
|
||||
Version 1.3 آ· 2026-10-07 آ· Current Live document MVP contract; planned endpoints are not claimed operational.
|
||||
|
||||
Companions: `RAG-Phase1-Implementation-Guide.md`, `RAG-Phase1-Database-Design.md`, `RAG-Phase1-MVP-Scenarios.md`. Scope follows `RAG-AI-Phase1-Delivery-Plan.md`. No document versioning is implemented: every upload is a new document; there is no version-upload route, model selector, mixed conversation or SSE in Phase 1.
|
||||
|
||||
@@ -70,7 +70,7 @@ Health paths are outside `/api/v1`. Register `/voice/sessions/by-request/...` be
|
||||
|
||||
## 3. Authentication
|
||||
|
||||
### A01 — Login
|
||||
### A01 — Login
|
||||
|
||||
```json
|
||||
{"username":"demo.admin","password":"<password>"}
|
||||
@@ -82,17 +82,17 @@ Health paths are outside `/api/v1`. Register `/voice/sessions/by-request/...` be
|
||||
|
||||
Credentials invalid: 401 `INVALID_CREDENTIALS`; throttled: 429. Do not distinguish missing username from wrong password. Expiry above is illustrative. Set Secure/HttpOnly/SameSite=Lax cookie; rotate tokens after successful login.
|
||||
|
||||
### A02 — Logout
|
||||
### A02 — Logout
|
||||
|
||||
No body. Revoke current session, clear cookie and close owned live sessions linked to it. Repeated logout returns 204. For a valid session require CSRF; missing/expired session may simply clear cookie after Origin validation.
|
||||
|
||||
### A03 — Current identity
|
||||
### A03 — Current identity
|
||||
|
||||
No body. Same identity/CSRF/expiry shape as login. Missing/expired session returns 401 `AUTH_REQUIRED`.
|
||||
|
||||
## 4. Documents and selected knowledge
|
||||
|
||||
### D01 — Upload
|
||||
### D01 — Upload
|
||||
|
||||
`multipart/form-data`: required `file`; optional `title`. Required `Idempotency-Key`. The server creates one independent document and ingestion job. New document is inactive.
|
||||
|
||||
@@ -104,11 +104,11 @@ Current local intake validates configured PDF, UTF-8 Markdown, DOCX, JPEG and PN
|
||||
|
||||
202 acknowledges durable metadata/job creation, not completed processing. Replay same upload returns these stable identities with current processing state and header `Idempotency-Replayed: true`. Scope key to organization; hash bytes and normalized title. 413 `FILE_TOO_LARGE`, 415 `UNSUPPORTED_FILE_TYPE`, 422 `INVALID_FILE`, 409 `IDEMPOTENCY_CONFLICT`. A parser failure after acceptance is represented by document status, not a later HTTP response to upload.
|
||||
|
||||
### D02 — List
|
||||
### D02 — List
|
||||
|
||||
Query: common pagination; optional `status=queued|processing|ready|failed`, `is_active=true|false`. Exclude deleted documents. Items use the D03 shape, except potentially omit verbose error detail. Return current `knowledge_revision` alongside the list.
|
||||
|
||||
### D03 — Detail / processing polling
|
||||
### D03 — Detail / processing polling
|
||||
|
||||
```json
|
||||
{"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}}
|
||||
@@ -116,7 +116,7 @@ Query: common pagination; optional `status=queued|processing|ready|failed`, `is_
|
||||
|
||||
`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
|
||||
### D04 — Retry failed processing
|
||||
|
||||
No body; required `Idempotency-Key`. Eligible only for failed undeleted document and retained original. Requeue same job, reset attempt count, increment retry generation and audit. Same key replays without incrementing twice.
|
||||
|
||||
@@ -183,7 +183,7 @@ paths, models or reviewer fields. Rejecting keeps zero publication and a safe
|
||||
failure reason. Lost worker ownership cannot attach candidates; an admin cannot
|
||||
approve a fresh OCR response using an old digest.
|
||||
|
||||
### D05 — Delete (deferred HTTP/UI)
|
||||
### D05 — Delete (deferred HTTP/UI)
|
||||
|
||||
Required `expected_revision` is the current knowledge revision; required idempotency key. Transaction locks selection and document. Mark deleted and inactive; if formerly active, increment knowledge revision and access epoch and invalidate sessions. Physical cleanup is not promised by this response.
|
||||
|
||||
@@ -193,13 +193,13 @@ Required `expected_revision` is the current knowledge revision; required idempot
|
||||
|
||||
202; 409 `REVISION_CONFLICT` on stale initial request. Replay same delete/key returns recorded result before revision validation. A new delete request for an already-deleted owned document can return its tombstone result without changing revisions. No read or search route restores eligibility.
|
||||
|
||||
### K01 — Get selection
|
||||
### K01 — Get selection
|
||||
|
||||
```json
|
||||
{"revision":1,"access_epoch":1,"document_ids":[]}
|
||||
```
|
||||
|
||||
### K02 — Replace selected set
|
||||
### K02 — Replace selected set
|
||||
|
||||
This replaces the entire set, not a delta. UI reads current selection before toggling a document.
|
||||
|
||||
@@ -215,7 +215,7 @@ Duplicate IDs: 422. Any unready item: 409 `DOCUMENT_NOT_READY`, with rejected ID
|
||||
|
||||
## 5. Configuration (read-only in MVP)
|
||||
|
||||
### F01 — Read
|
||||
### 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":20971520,"ocr_review_required":true}}
|
||||
@@ -223,7 +223,7 @@ Duplicate IDs: 422. Any unready item: 409 `DOCUMENT_NOT_READY`, with rejected ID
|
||||
|
||||
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.
|
||||
|
||||
### F02 — Update (deferred)
|
||||
### F02 — Update (deferred)
|
||||
|
||||
```json
|
||||
{"expected_revision":1,"assistant_name":"HR Assistant","instruction":"Use formal Persian and state when supporting evidence is missing."}
|
||||
@@ -233,7 +233,7 @@ Runtime must replace illustrative capability placeholders with actual configurat
|
||||
|
||||
## 6. Conversations and deferred text
|
||||
|
||||
### C01 — Create
|
||||
### C01 — Create
|
||||
|
||||
```json
|
||||
{"client_request_id":"50000000-0000-4000-8000-000000000001","mode":"voice","title":"Working hours"}
|
||||
@@ -245,11 +245,11 @@ Runtime must replace illustrative capability placeholders with actual configurat
|
||||
|
||||
The current MVP accepts `mode=voice` only; text/mixed requests return 409 `MODE_MISMATCH`. Follow-up text support uses a separate mode and must not silently alter the voice contract. Title optional. Idempotency scope `(owner,client_request_id)`; same payload replays original 201. Different payload 409. New conversation snapshots current epoch. Voice history cannot be continued as text in Phase 1.
|
||||
|
||||
### C02 — List own conversations (deferred history UI)
|
||||
### C02 — List own conversations (deferred history UI)
|
||||
|
||||
Common pagination, optional `mode`. Items use C01 response plus `updated_at`; derive `status=stale` when epoch differs. Status values: active, stale, closed. List excludes other users regardless of role.
|
||||
|
||||
### C03 — Read messages (deferred)
|
||||
### C03 — Read messages (deferred)
|
||||
|
||||
Common pagination, ascending sequence. Voice can return no durable messages: current-session answer transcripts are delivered through Live events when available; durable full voice history is deferred. Old text history remains viewable even when stale.
|
||||
|
||||
@@ -259,7 +259,7 @@ Common pagination, ascending sequence. Voice can return no durable messages: cur
|
||||
|
||||
Assistant items also expose `turn_status` and source objects. Failed turns remain visible as state, not fabricated assistant answers. A user message may exist without an assistant reply; UI follows turn status.
|
||||
|
||||
### T01 — Submit text turn (deferred)
|
||||
### T01 — Submit text turn (deferred)
|
||||
|
||||
```json
|
||||
{"conversation_id":"60000000-0000-4000-8000-000000000001","client_request_id":"90000000-0000-4000-8000-000000000001","message":"What are the Thursday opening hours?"}
|
||||
@@ -275,11 +275,11 @@ Assistant items also expose `turn_status` and source objects. Failed turns remai
|
||||
|
||||
Scope key `(conversation_id,client_request_id)`. Changed message under same key: 409. Another different request while one runs: 409 `CONVERSATION_BUSY`. Wrong mode: 409 `MODE_MISMATCH`. Stale epoch: 409 `CONVERSATION_STALE`. Admission failures use the common HTTP error envelope; failures after a turn is persisted use its failed terminal result. Retry completed failures only with a new request ID.
|
||||
|
||||
### T02 — Recover/poll turn (deferred)
|
||||
### T02 — Recover/poll turn (deferred)
|
||||
|
||||
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 — backend-selected provider; frozen application audio/events
|
||||
## 7. Voice contract — backend-selected provider; frozen application audio/events
|
||||
|
||||
The selected provider is backend-managed Gemini Live or OpenAI Realtime. The
|
||||
OpenAI-specific mechanisms below describe the preserved Realtime adapter; the Gemini
|
||||
@@ -289,7 +289,36 @@ 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. 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)
|
||||
OpenAI Phase 1 speech configuration is server-only. New reservations freeze
|
||||
the exact requested transcription/language mode/prompt/vocabulary, server VAD
|
||||
parameters and optional noise reduction under execution_profile.audio_input.
|
||||
The same values must be acknowledged before readiness. Existing defaults remain;
|
||||
both automatic response/interrupt flags stay false. A missing or mismatched
|
||||
OpenAI audio snapshot is unusable at stream admission before provider opening.
|
||||
Replay retains the original identity and snapshot; never backfill it. Gemini
|
||||
profiles and all public fields/events remain unchanged. See the
|
||||
[Phase 1 handoff](../guides/openai-persian-speech-phase1.md) for settings and
|
||||
unrun real-speech/browser gates.
|
||||
|
||||
OpenAI Phase 2 additionally freezes `style_revision` and
|
||||
`effective_instructions_digest` (SHA-256 of exact UTF-8 composed instructions).
|
||||
Missing/mismatched style fields reject stream admission before provider opening;
|
||||
replay never rewrites snapshots. Effective instructions require provider
|
||||
acknowledgment. Gemini instructions remain unchanged. Voice changes require fresh
|
||||
sessions; candidate voices remain unverified until listening/interruption acceptance.
|
||||
See [Phase 2 handoff](../guides/openai-persian-delivery-phase2.md).
|
||||
|
||||
OpenAI Phase 3 freezes optional `execution_profile.reasoning`: null when omitted,
|
||||
or `{"effort":"low"}` / `{"effort":"medium"}` for the explicitly supported
|
||||
`gpt-realtime-2.1` and `gpt-realtime-2.1-mini` candidates. Unsupported explicit
|
||||
combinations reject configuration before connection. Enabled reasoning is sent as
|
||||
private session reasoning and must be acknowledged before readiness. Disabled
|
||||
reasoning is omitted on the wire; provider-enabled reasoning is rejected when
|
||||
unrequested. Missing enabled snapshots and changed effort/model reject admission;
|
||||
replay retains identity and never rewrites snapshots. Gemini/public contracts are
|
||||
unchanged. See [Phase 3 report](../guides/openai-persian-understanding-phase3.md).
|
||||
|
||||
### V01 — Create session (HTTP)
|
||||
|
||||
```json
|
||||
{"conversation_id":"61000000-0000-4000-8000-000000000001","client_request_id":"91000000-0000-4000-8000-000000000001"}
|
||||
@@ -303,7 +332,7 @@ Voice conversation must be owned and current-epoch. Reserve session before provi
|
||||
|
||||
No persistent provider secret or provider credential is returned. Backend adapter installs tools/Persian policy and enables available transcription before marking usable. Provider timeout leaves failed/uncertain reservation: inspect with V03, never blind recreation. 503 can represent a capability failure before reservation. `connecting` is not proof of working audio.
|
||||
|
||||
### V02 — Poll state, diagnostics and recent retrieved sources (HTTP)
|
||||
### V02 — Poll state, diagnostics and recent retrieved sources (HTTP)
|
||||
|
||||
```json
|
||||
{"session_id":"a0000000-0000-4000-8000-000000000001","status":"connected","close_reason":null,"expires_at":"2026-10-06T09:30:00Z","recent_tool_results":[{"tool_call_id":"b0000000-0000-4000-8000-000000000001","status":"succeeded","created_at":"2026-10-06T09:08:00Z","sources":[{"source_ref":"S1","document_id":"10000000-0000-4000-8000-000000000001","chunk_id":"30000000-0000-4000-8000-000000000001","title":"Illustrative circular","excerpt":"<verified source passage>","location":{"page":1,"section":"<verified clause>"},"available":true}]}]}
|
||||
@@ -311,11 +340,11 @@ No persistent provider secret or provider credential is returned. Backend adapte
|
||||
|
||||
Illustrative payload; not an extracted source quotation. At most 20 recent results, chronological, deduplicate by tool_call_id. Sources are retrieved evidence unless exact answer attribution is verified. Redact revoked excerpts and mark unavailable. States: creating, connecting, connected, closed, failed. Poll approximately every 2 seconds while active; stop at terminal state. Polling is not durable transcript recovery. A client cannot claim connected state or inject a trusted tool result.
|
||||
|
||||
### V03 — Recover creation by request ID (HTTP)
|
||||
### V03 — Recover creation by request ID (HTTP)
|
||||
|
||||
200 returns V01's session/path shape if reservation remains eligible, otherwise terminal state and `stream_path:null`. Owner-only, 404 if no reservation, never creates a session. Before starting a fresh request after media loss, reconcile/close the old session. The old path does not restore provider context.
|
||||
|
||||
### V04 — Close (HTTP)
|
||||
### V04 — Close (HTTP)
|
||||
|
||||
No body. 200 `{session_id,status:"closed",close_reason:"user_requested"}`. Already terminal returns its existing state. Close application stream/microphone/playback and attempt provider cleanup. Unresolved cleanup is logged and bounded by expiry; logout, auth expiry, epoch revocation and provider loss also close the session.
|
||||
|
||||
@@ -478,7 +507,7 @@ Transcript status is partial, completed or interrupted. The backend assigns turn
|
||||
|
||||
Interruption, final progress, acknowledged context cleanup and late-output suppression follow 7.1.2; generation completion is not playback completion. On disconnection/restart, mark old session unusable and start a new one after reconciliation; seamless reconnect/context restoration is deferred. Do not replay audio/tool events as fresh turns. Use bounded buffers, idle/creation/tool deadlines and existing session TTL; values require deployment validation.
|
||||
|
||||
### 7.2 Internal model tool — `search_knowledge`
|
||||
### 7.2 Internal model tool — `search_knowledge`
|
||||
|
||||
Model arguments, identical for the internal text-query harness, later text chat and Live. The LangChain tool uses this schema while trusted dispatcher context supplies authority:
|
||||
|
||||
@@ -486,7 +515,7 @@ Model arguments, identical for the internal text-query harness, later text chat
|
||||
{"query":"What are the conditions and exceptions of the circular?","context":"The circular identified as source S1 in the preceding exchange."}
|
||||
```
|
||||
|
||||
`query` required, 1–2000 characters; optional `context` proposed maximum 2000 characters, a conversation-resolved textual reference. Reject unknown fields. Context does not grant permission or turn previous model prose into evidence. No model-supplied organization/user IDs or paths; supported document filters remain deferred. Backend derives identity, current selected ready/active/undeleted scope, profile, bounded top_k/evidence size and execution IDs.
|
||||
`query` required, 1–2000 characters; optional `context` proposed maximum 2000 characters, a conversation-resolved textual reference. Reject unknown fields. Context does not grant permission or turn previous model prose into evidence. No model-supplied organization/user IDs or paths; supported document filters remain deferred. Backend derives identity, current selected ready/active/undeleted scope, profile, bounded top_k/evidence size and execution IDs.
|
||||
|
||||
Illustrative successful result; text/location must be populated from actual retained chunks, never from these placeholders:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user