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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
openapi: 3.1.0
info:
  # Do not change the title, if the title changes, the import paths will be broken
  title: Api
  version: 0.1.0
  description: Io HST Search Engine API
servers:
  - url: /api
    description: Base API path
tags:
  - name: health
    description: Health operations
  - name: search
    description: Io search synthesis
  - name: model
    description: Io neural model inference
  - name: feedback
    description: User feedback for evolutionary learning
paths:
  /healthz:
    get:
      operationId: healthCheck
      tags: [health]
      summary: Health check
      description: Returns server health status
      responses:
        "200":
          description: Healthy
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/HealthStatus"

  /search:
    post:
      operationId: search
      tags: [search]
      summary: Search and synthesize
      description: Runs the HST search engine across 200+ sources and returns a synthesized answer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/SearchInput"
      responses:
        "200":
          description: Synthesized search result
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SearchResult"
        "400":
          description: Bad request

  /model/generate:
    post:
      operationId: modelGenerate
      tags: [model]
      summary: Generate text from Io neural model
      description: Runs inference on the Io HST checkpoint
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ModelInput"
      responses:
        "200":
          description: Generated text
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ModelResult"
        "503":
          description: Model not available

  /feedback:
    post:
      operationId: submitFeedback
      tags: [feedback]
      summary: Submit thumbs up/down for a search answer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/FeedbackInput"
      responses:
        "200":
          description: Recorded
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/FeedbackResult"
        "400":
          description: Bad request

  /feedback/stats:
    get:
      operationId: feedbackStats
      tags: [feedback]
      summary: Aggregate feedback stats
      responses:
        "200":
          description: Stats
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/FeedbackStats"

  /model/finetune:
    post:
      operationId: modelFineTune
      tags: [model]
      summary: Start light CPU fine-tuning of the Io checkpoint
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/FineTuneInput"
      responses:
        "200":
          description: Started
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/FineTuneState"
        "400":
          description: Bad request

  /model/finetune/status:
    get:
      operationId: modelFineTuneStatus
      tags: [model]
      summary: Fine-tune status
      responses:
        "200":
          description: Status
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/FineTuneState"

  /model/status:
    get:
      operationId: modelStatus
      tags: [model]
      summary: Model status
      responses:
        "200":
          description: Model status
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ModelStatus"

components:
  schemas:
    HealthStatus:
      type: object
      properties:
        status:
          type: string
      required:
        - status

    SearchInput:
      type: object
      required:
        - query
      properties:
        query:
          type: string
          minLength: 1
          maxLength: 500
        target:
          type: integer
          minimum: 1
          maximum: 12
          default: 6

    SearchResult:
      type: object
      required:
        - answer
        - sources
        - query
      properties:
        answer:
          type: string
        sources:
          type: array
          items:
            type: string
        topUrl:
          type: ["string", "null"]
        query:
          type: string
        intent:
          type: string
        selfReferential:
          type: boolean
        sourceCount:
          type: integer
        processingMs:
          type: integer

    ModelInput:
      type: object
      required:
        - prompt
      properties:
        prompt:
          type: string
          minLength: 1
          maxLength: 1500
        maxTokens:
          type: integer
          minimum: 1
          maximum: 1024
          default: 200
        temperature:
          type: number
          minimum: 0.01
          maximum: 2.0
          default: 0.85
        topK:
          type: integer
          minimum: 1
          maximum: 200
          default: 50
        topP:
          type: number
          minimum: 0.01
          maximum: 1.0
          default: 0.95
        repetitionPenalty:
          type: number
          minimum: 1.0
          maximum: 2.0
          default: 1.15
        presencePenalty:
          type: number
          minimum: 0.0
          maximum: 2.0
          default: 0.0
        nSamples:
          type: integer
          minimum: 1
          maximum: 8
          default: 1

    ModelResult:
      type: object
      required:
        - text
        - step
      properties:
        text:
          type: string
        step:
          type: integer
        checkpoint:
          type: string
        coherenceScore:
          type: number
        bestOfN:
          type: integer
        bestScore:
          type: number
        error:
          type: ["string", "null"]

    FeedbackInput:
      type: object
      required:
        - query
        - rating
      properties:
        query:
          type: string
          minLength: 1
          maxLength: 500
        rating:
          type: string
          enum: [up, down]
        sources:
          type: array
          items:
            type: string
        answer:
          type: string
          maxLength: 8000

    FeedbackResult:
      type: object
      required:
        - ok
        - ts
      properties:
        ok:
          type: boolean
        ts:
          type: integer

    FeedbackStats:
      type: object
      required:
        - totalFeedback
        - totalUp
        - totalDown
        - sources
      properties:
        totalFeedback:
          type: integer
        totalUp:
          type: integer
        totalDown:
          type: integer
        sources:
          type: array
          items:
            type: object
            required: [source, up, down, multiplier]
            properties:
              source:
                type: string
              up:
                type: integer
              down:
                type: integer
              multiplier:
                type: number

    FineTuneInput:
      type: object
      properties:
        steps:
          type: integer
          minimum: 1
          maximum: 200
          default: 30
        lr:
          type: number
          minimum: 0.0000001
          maximum: 0.001
          default: 0.00001
        seqLen:
          type: integer
          minimum: 64
          maximum: 1024
          default: 256

    FineTuneState:
      type: object
      required:
        - status
      properties:
        status:
          type: string
          enum: [idle, running, success, failed]
        startedAt:
          type: ["integer", "null"]
        finishedAt:
          type: ["integer", "null"]
        steps:
          type: integer
        currentStep:
          type: integer
        loss:
          type: ["number", "null"]
        avgLoss:
          type: ["number", "null"]
        error:
          type: ["string", "null"]
        checkpointOut:
          type: ["string", "null"]
        activeCheckpoint:
          type: string
        fineTunedExists:
          type: boolean
        guideStats:
          type: object
          additionalProperties: true
        log:
          type: array
          items:
            type: object
            additionalProperties: true
        ok:
          type: boolean

    ModelStatus:
      type: object
      required:
        - available
        - message
      properties:
        available:
          type: boolean
        message:
          type: string
        step:
          type: ["integer", "null"]
        checkpoint:
          type: ["string", "null"]