Skip to content

Commit 7a3fe8b

Browse files
authored
Merge pull request #41 from namel3ss-Ai/feat/core-edition-retrieval-tuning
Feat/core edition retrieval tuning
2 parents 34f093d + b9ec4ba commit 7a3fe8b

145 files changed

Lines changed: 7485 additions & 201 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/composition/includes.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Deterministic Includes
2+
3+
Evolution Edition adds deterministic multi-file composition through top-level include directives.
4+
5+
## Capability Gate
6+
7+
You must enable:
8+
9+
```ai
10+
capabilities:
11+
composition.includes
12+
```
13+
14+
Without it, compile fails with:
15+
16+
`Capability missing: composition.includes is required to use 'include' directives. Add 'capability is composition.includes' to the manifest.`
17+
18+
## Syntax
19+
20+
```ai
21+
include "modules/retrieval.ai"
22+
include 'modules/flows.ai'
23+
```
24+
25+
Rules:
26+
27+
- Include is top-level only.
28+
- Paths are relative, `.ai` only.
29+
- Absolute paths are rejected.
30+
- `..` traversal is rejected.
31+
- Include order is the merge order.
32+
33+
## Merge and Validation
34+
35+
- Root file remains authoritative for `ui` and `pages`.
36+
- Included files may contribute flows, records, and other declarations.
37+
- Duplicate declarations across files are compile errors.
38+
- Include cycles are compile errors with a stable path chain.
39+
- Duplicate include paths are collapsed with a deterministic warning:
40+
- `Warning: Duplicate include ignored: "<path>"`
41+
42+
## Determinism Guarantees
43+
44+
- Paths are normalized to project-relative POSIX format.
45+
- Merge order is include order then in-file appearance order.
46+
- Source-map entries are stable and sorted by `decl_id`.
47+
- No absolute paths are emitted in composition metadata.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Determinism Regression Suite
2+
3+
Evolution Edition makes repeat-run stability a first-class CI signal.
4+
5+
## Core Checks
6+
7+
- Repeated compile of the same app must produce byte-identical manifest JSON.
8+
- Repeated retrieval trace generation must produce byte-identical trace JSON.
9+
- Include warnings and composition source-map output must be stable.
10+
- UI baselines must match checked-in goldens.
11+
12+
## Local Commands
13+
14+
```bash
15+
python tools/determinism_repeat_check.py app.ai
16+
python tools/ui_baseline_refresh.py --check
17+
python -m namel3ss.beta_lock.repo_clean
18+
```
19+
20+
## CI Policy
21+
22+
Determinism failures are blocking:
23+
24+
- No timestamps or random IDs in compiler/runtime artifacts.
25+
- No absolute paths in manifests, diagnostics payloads, or emitted composition metadata.
26+
- Warning and error ordering remains stable across runs.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Retrieval Trace and What-If
2+
3+
Evolution Edition adds a deterministic retrieval trace contract for Studio diagnostics.
4+
5+
## Capability Gate
6+
7+
Enable:
8+
9+
```ai
10+
capabilities:
11+
diagnostics.trace
12+
```
13+
14+
If missing, compiler emits:
15+
16+
`Warning: Retrieval trace diagnostics are disabled (missing capability diagnostics.trace).`
17+
18+
## Trace Contract
19+
20+
Trace payload includes:
21+
22+
- `query`
23+
- `params` (`semantic_weight`, `semantic_k`, `lexical_k`, `final_top_k`)
24+
- `filter_tags` (sorted)
25+
- `semantic`, `lexical`, `final` candidate lists
26+
- `tie_breaker` (static deterministic ordering description)
27+
28+
## Deterministic Ordering
29+
30+
Rows are sorted with:
31+
32+
1. `final_score` descending
33+
2. `semantic_score` descending
34+
3. `lexical_score` descending
35+
4. `doc_id` ascending
36+
37+
## What-If Simulation
38+
39+
Studio computes deterministic what-if ranking from stored trace data only:
40+
41+
- No external calls
42+
- No rerun of retrieval
43+
- Pure function of `(trace, params)`
44+
- Same input produces identical output

docs/manifest/composition_rules.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Composition rules
2+
3+
Namel3ss composition is deterministic and layer-scoped.
4+
5+
1. Theme composition:
6+
- App-level theme defaults are applied first.
7+
- Page-level theme overrides apply next.
8+
- Runtime theme state (when enabled) applies last.
9+
2. Page composition:
10+
- Slot layout pages are evaluated in canonical slot order: `header`, `sidebar`, `main`, `footer`.
11+
- Retrieval explain elements are injected ahead of non-error content in the active slot.
12+
3. Module composition:
13+
- Imported module exports must be explicit.
14+
- Flow and UI names must be unique at composition time.
15+
- Unsupported exported actions are dropped by export guards instead of re-ordered or rewritten.
16+
17+
Composition order is stable across runs, and manifests are serialized canonically.

docs/reports/code_audit.md

Lines changed: 32 additions & 26 deletions
Large diffs are not rendered by default.

docs/retrieval/tuning.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Retrieval Tuning
2+
3+
Retrieval tuning controls adjust semantic/lexical blending and candidate limits while preserving deterministic ranking and preview output.
4+
5+
## Tunable fields
6+
7+
- `semantic_weight` (0..1)
8+
- `semantic_k` (int)
9+
- `lexical_k` (int)
10+
- `final_top_k` (int)
11+
12+
Runtime state is stored under `state.retrieval.tuning` with canonical key ordering.
13+
14+
## Deterministic preview ordering
15+
16+
Preview rows are sorted by:
17+
1. `final_score` (desc)
18+
2. `semantic_score` (desc)
19+
3. `lexical_score` (desc)
20+
4. `doc_id` (asc)
21+
5. `chunk_id` (asc internal tie-break)
22+
23+
## Tag filtering
24+
25+
`filter_tags` can be provided explicitly or resolved from UI state scopes. Matching is deterministic:
26+
27+
- normalized tags (trimmed, deduped, sorted)
28+
- per-result `matched_tags` sorted ascending
29+
- empty matches return deterministic empty `results` and `retrieval_preview`
30+
31+
## Flows
32+
33+
The platform wires retrieval tuning controls to flow actions when available:
34+
35+
- `set_semantic_weight`
36+
- `set_semantic_k`
37+
- `set_lexical_k`
38+
- `set_final_top_k`
39+

docs/runtime/retrieval_flows.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Retrieval tuning flows
2+
3+
Namel3ss supports four built-in retrieval tuning flows:
4+
5+
- `set_semantic_k(k: int)`
6+
- `set_lexical_k(k: int)`
7+
- `set_final_top_k(k: int)`
8+
- `set_semantic_weight(weight: float)`
9+
10+
## Behavior
11+
12+
- Calls are applied in declaration order within a flow.
13+
- `set_semantic_k` and `set_lexical_k` define candidate pool limits.
14+
- `set_final_top_k` limits final output size after semantic/lexical merge.
15+
- `set_semantic_weight` sets blend weight in `[0, 1]` and defaults to `0.5` when omitted.
16+
17+
## Validation
18+
19+
- Compile-time validation checks ordering and literal argument ranges when literals are provided.
20+
- Runtime raises `ValueError` for out-of-range dynamic values.
21+
- Unsupported tuning-like names raise `UnknownFlowError` at compile time.
22+
23+
## State contract
24+
25+
Runtime stores tuning state under:
26+
27+
`state.retrieval.tuning`
28+
29+
Canonical field order:
30+
31+
1. `semantic_k`
32+
2. `lexical_k`
33+
3. `final_top_k`
34+
4. `semantic_weight`

docs/ui-dsl.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,17 @@ page "home":
643643
- `upload.missing_control` when uploads capability is enabled but no upload control is declared
644644
- `upload.unused_declaration` when an upload declaration is never referenced from `state.uploads.<name>`
645645

646+
## 4.4) Retrieval tuning controls (Studio)
647+
- Retrieval tuning uses normal flow calls and does not add new UI DSL syntax.
648+
- Supported runtime tuning flows are:
649+
- `set_semantic_k(<int>)`
650+
- `set_lexical_k(<int>)`
651+
- `set_final_top_k(<int>)`
652+
- `set_semantic_weight(<number in [0, 1]>)`
653+
- Studio may render interim controls (dropdowns/radios) when these flows exist with valid one-field numeric contracts.
654+
- Production behavior is unchanged: if these flows are not defined, retrieval keeps legacy defaults.
655+
- Control metadata and any disabled reasons are deterministic and emitted in canonical manifest order.
656+
646657
## 5) Core UI primitives
647658
- `page "<title>":` container with optional `purpose is "<string>"` metadata (page-only; deterministic id generation). Duplicate page titles are rejected.
648659
- `purpose is "<string>"` may only appear at the page root; it is persisted to manifests and Studio payloads as metadata for runtime decisions.

docs/ui/citations.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Citations
2+
3+
Enhanced citations provide stable inline chips plus deterministic snippet previews and drawer linking.
4+
5+
## Capability
6+
7+
`ui.citations_enhanced` enables enhanced chip/snippet behavior.
8+
9+
If missing, the compiler emits:
10+
11+
`Warning: Enhanced citations are disabled (missing capability ui.citations_enhanced). Falling back to legacy citations UI.`
12+
13+
Fallback behavior is explicit and deterministic.
14+
15+
## Citation contract
16+
17+
Each citation entry includes:
18+
19+
- `citation_id` (stable; generated when missing)
20+
- `index` (1-based, stable order)
21+
- `title`
22+
- `source_id` or `url`
23+
- optional deterministic `snippet` truncation
24+
25+
## Sources drawer mapping
26+
27+
- chips and drawer rows use `data-citation-id`
28+
- answer click focuses the matching drawer entry
29+
- drawer selection can resolve back to the matching citation ID
30+
31+
## Snippet truncation
32+
33+
- whitespace normalized
34+
- deterministic max length
35+
- truncated values end with `...`
36+

docs/ui/diagnostics.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Diagnostics Panel
2+
3+
The diagnostics panel supports deterministic filtering and sorting for retrieval-focused debugging.
4+
5+
## Sort options
6+
7+
- `severity`
8+
- `semantic score`
9+
- `lexical score`
10+
- `final score`
11+
- `doc id`
12+
13+
Score sorts use stable tie-breaking and deterministic ordering.
14+
15+
## Filters
16+
17+
Toggles:
18+
19+
- `semantic`
20+
- `lexical`
21+
- `final`
22+
23+
Rows are shown only when at least one enabled toggle matches the row mode set.
24+
25+
## Per-row metadata
26+
27+
Each rendered row includes stable metadata:
28+
29+
- `doc_id`
30+
- `semantic_score`
31+
- `lexical_score`
32+
- `final_score`
33+
34+
## Determinism
35+
36+
- repeated renders over the same diagnostics payload produce the same row order
37+
- score sorting has fixed numeric comparison and tie-break rules
38+
- empty filter state shows a stable empty-state row
39+

0 commit comments

Comments
 (0)