contextRagTopK reads the rag flag, which the model may send as a bool (true → default top-K, encoded here as -1 meaning "mode default on") or an int (explicit K). 0 / absent / false means "no override".
(raw map[string]json.RawMessage)
| 386 | // (true → default top-K, encoded here as -1 meaning "mode default on") or an |
| 387 | // int (explicit K). 0 / absent / false means "no override". |
| 388 | func contextRagTopK(raw map[string]json.RawMessage) int { |
| 389 | v, ok := raw["rag"] |
| 390 | if !ok { |
| 391 | v, ok = raw["retrieve"] |
| 392 | } |
| 393 | if !ok || len(v) == 0 { |
| 394 | return 0 |
| 395 | } |
| 396 | var b bool |
| 397 | if err := json.Unmarshal(v, &b); err == nil { |
| 398 | if b { |
| 399 | return contextDefaultRagTopK |
| 400 | } |
| 401 | return 0 |
| 402 | } |
| 403 | if n := jsonInt(raw, "rag", "retrieve"); n > 0 { |
| 404 | return n |
| 405 | } |
| 406 | return 0 |
| 407 | } |
| 408 | |
| 409 | // contextDefaultRagTopK is the top-K applied when rag is requested as a bare |
| 410 | // boolean. Mirrors ctxmgr.DefaultRetrievalTopK without importing it here. |