interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tools / gen / retrieval / CONTRACT.md

243 lines · 15408 bytes Raw Blame History Source

genret: file-backed retrieval provider, CLI contract genret-cli-v3

GEN-4 (aien-spark/omega#479, master #475). Owner: Agent E. Consumers: the GEN runner (Agent C, through this CLI only) and the Cortex provider (aien-spark/aien-sovereign-core#556), which must reproduce selected.tsv, excluded.tsv and suffix.txt byte for byte from the same corpus and query. Every rule below is integer arithmetic or byte comparison so a second implementation can match it exactly. Any change to an observable output is a new contract version.

Version history:

Arms C and D call the same command with the same --k, --cap-bytes, mode and rendering. The only difference is --kind raw (C) versus --kind abstraction (D), and therefore which records are indexed.

1. Command

genret query --corpus <records/MANIFEST> --manifest-sha256 <64 lowercase hex>
             --recheck <recheck binary> --recheck-sha256 <64 lowercase hex>
             --kind raw|abstraction --k <1..64> --cap-bytes <1..1048576>
             --requirement <file> --prompt <file> --out <new dir>
             [--exclude-family <family>]...  [--mode normal|irrelevant|empty|length-matched]
             [--target-bytes <1..cap>]         (required with, and only with, --mode length-matched)
genret version                                  prints "genret-cli-v3"

2. Corpus input

3. Query (public requirement + prompt only)

4. Tokenization

Lowercase ASCII A-Z to a-z; a token is a maximal run of bytes in [a-z0-9]; every other byte separates. Record document text = the values of entry, params, ret, desc, then the body (each tokenized separately and the token lists concatenated; field boundaries separate tokens). dl = number of tokens (with repeats).

5. Eligibility and indexing

For every manifest record, in this order, the first failing check is its exclusion reason:

  1. kind:<kind>: kind differs from --kind
  2. split:<split>: split is not corpus (schema v1: probe records are never eligible)
  3. validity:<validity>: validity is not verified (schema v1: unverified)
  4. family_excluded:<family>: one of its families is named by --exclude-family (first such, record order)
  5. poisoned:fence: desc or body contains the three bytes "```" (could escape its code block)

Records that pass all five form the index: N records, T = sum of their dl, df(t) = number of index records containing term t. Excluded records do not affect any score. A record is eligible only through a MANIFEST whose sha256 is the pinned one (RECORD_SCHEMA.md section 5).

Only the fence is screened here. desc is rendered as plain prose outside the code block (section 6), so its wording reaches the model unfenced. Its content is owned by the record producers and by recheck's schema checks (one printable line), not by genret.

6. Scoring, ranking, selection

Integer BM25, k1 = 6/5, b = 3/4, log base 2, scores in units of 2^-16. For index record r and query term t with tf = occurrences of t in r (only terms with tf > 0 and therefore df >= 1 contribute):

idf(t)    = log2q16(2N + 2, 2 df(t) + 1)
part(t,r) = floor( idf(t) * tf * 44 * T / (20 * T * tf + 6 * T + 18 * dl(r) * N) )     (128-bit intermediate)
score(r)  = sum of part(t,r) over the distinct query terms t

log2q16(a, b):   requires a >= b >= 1, a < 2^32; 64-bit unsigned arithmetic
  k = 0; while a >= 2b: b = 2b, k = k + 1
  y = floor(a * 2^30 / b)                      (2^30 <= y < 2^31)
  r = k * 2^16
  for i = 15 down to 0: y = floor(y * y / 2^30); if y >= 2^31: y = floor(y / 2), r = r + 2^i
  return r

(This is BM25 with idf = ln(1 + (N - df + 0.5)/(df + 0.5)), rescaled by 1/ln 2 and multiplied out by 20T.)

Rendering (exact bytes, the same for both kinds: a C suffix and a D suffix with the same number of records differ only in the entry, params, ret, desc and body values):

H        = "\nVerified reference code from earlier tasks, most relevant first.\n"            (66 bytes)
block(i) = "\nRecord " i ".\n\n" "entry " entry "\n" "params" (" " param)* "\n" "ret " ret "\n" "\n" desc "\n\n```\n" body "```\n"
suffix   = "" when nothing is selected, else H block(1) ... block(n)

i is the decimal position in the suffix (1-based). bytes of a record = length of its block.

Order and selection by mode:

7. Fatal (exit 2, one stderr line genret: FATAL <reason> <detail>, no output)

A record is never replaced by another one: integrity failures stop the run.

8. Outputs in --out

filecontent
selected.tsvheader rank\tid\tdigest\tscore\tbytes\trole; one row per selected record in suffix order; role top or pad
excluded.tsvheader id\tdigest\tscore\treason; every manifest record not selected, sorted by id (byte order); score - when not indexed
suffix.txtthe exact bytes the runner appends in the variable suffix (may be empty)
query.txtthe query terms (section 3)
receipt.txtkey=value lines in a fixed order (listed below)
SHA256SUMSsha256sum lines of the five files above, in that file order

receipt.txt keys, in this order:

  1. contract=genret-cli-v3
  2. mode
  3. kind
  4. k
  5. cap_bytes
  6. target_bytes (- if unused)
  7. exclude_family (comma list or -)
  8. manifest_sha256
  9. recheck_sha256
  10. recheck_source_sha256
  11. requirement_sha256
  12. prompt_sha256
  13. query_sha256
  14. records
  15. indexed
  16. total_tokens (T)
  17. selected
  18. pad (- unless length-matched; else none or the count of pad records)
  19. pad_reason (-, c_not_shorter, reached or exhausted)
  20. unpadded_bytes (- unless length-matched)
  21. suffix_bytes
  22. length_gap (- unless length-matched; else signed decimal)
  23. suffix_sha256
  24. selected_sha256
  25. excluded_sha256

Digests are lowercase hex sha256. No timestamps, paths or host data in any output.