|
| 1 | +# `sections` |
| 2 | + |
| 3 | +Typed surfaces over the `<section>:<scope>` namespace convention |
| 4 | +(`crates/tinymemory-bus/src/namespace.rs`): `Sections`, `SectionView`, and |
| 5 | +`SectionRecall`. Nothing here is a new capability — every call composes |
| 6 | +`MemoryCore` and `MemoryRecall`, which every driver implements as supertraits — |
| 7 | +this module only stops a caller from hand-concatenating the `conversation:` / |
| 8 | +`learning:` / `document:` prefix, where a typo silently produces a different, |
| 9 | +valid namespace instead of an error. |
| 10 | + |
| 11 | +## Design |
| 12 | + |
| 13 | +```text |
| 14 | +Sections::new(provider) |
| 15 | + ├── conversations() ─┐ |
| 16 | + ├── learnings() ├─ SectionView put / get / forget / list |
| 17 | + ├── documents() │ scopes / list_section |
| 18 | + ├── section(custom) ─┘ |
| 19 | + └── recall() ── SectionRecall in_scope / across_section |
| 20 | +``` |
| 21 | + |
| 22 | +- `Sections` is the entry point: one named accessor per routine section |
| 23 | + (`conversations`, `learnings`, `documents`) plus `section(&MemorySection)` for |
| 24 | + the rest of the vocabulary (`entity:`, `profile:`, `tool:`, `source:`, and |
| 25 | + `Custom`) and `recall()` for the cross-cutting query surface. |
| 26 | +- `SectionView` addresses one section by scope — `put` / `get` / `forget` / |
| 27 | + `list` take the bare scope (`"thread-8f21"`), never the prefixed namespace — |
| 28 | + and enumerates it with `scopes()` / `list_section()`. |
| 29 | +- `SectionRecall` answers two different questions, deliberately kept apart |
| 30 | + because they cost different amounts: `in_scope` is one provider call; |
| 31 | + `across_section` fans out to one call per namespace in the section. |
| 32 | + |
| 33 | +Every handle borrows `&dyn MemoryProvider` (see `view.rs`, `recall.rs`): cheap |
| 34 | +to construct, holds no state between calls, and cannot outlive the provider — |
| 35 | +so a caller builds one where it is needed instead of threading it through a |
| 36 | +struct. |
| 37 | + |
| 38 | +`MemorySection` is normalised through `MemorySection::from_prefix` in |
| 39 | +`SectionView::new`, so `Custom("conversation")` and `MemorySection::Conversation` |
| 40 | +are the same view rather than two. Storing the caller's spelling verbatim would |
| 41 | +let a write land under `conversation:` while a `scopes()` call — which compares |
| 42 | +against this normalised field — reported the section as empty. |
| 43 | + |
| 44 | +## Public surface |
| 45 | + |
| 46 | +- `Sections::{new, conversations, learnings, documents, section, recall}` |
| 47 | +- `SectionView::{put, get, forget, list, scopes, list_section}` |
| 48 | +- `SectionRecall::{in_scope, across_section}` |
| 49 | +- `SectionScope`, `SectionHits` — the value types `scopes()` / recall return |
| 50 | +- `MAX_SECTION_NAMESPACES` — the fan-out cap `across_section` enforces |
| 51 | +- `NAMESPACE_FILTER_CONFLICT`, `CROSS_SESSION_SECTION_CONFLICT`, |
| 52 | + `CROSS_SESSION_FAN_OUT_CONFLICT` — the exact `MemoryError::Invalid` messages |
| 53 | + the recall refusals carry, exposed so a caller's test can assert against the |
| 54 | + same string it sees |
| 55 | + |
| 56 | +## Operational constraints |
| 57 | + |
| 58 | +**`across_section` is a fan-out, not a filtered call.** `OwnedRecallOpts::namespace` |
| 59 | +is exact-match, and `namespace: None` means the literal `global` namespace on |
| 60 | +the embedded engine but *every* namespace on the reference driver |
| 61 | +(`crates/tinymemory-conformance/src/reference/mod.rs`). A single unfiltered call |
| 62 | +plus post-filtering would return nothing in production, so `across_section` |
| 63 | +enumerates `scopes()` and issues one exact-namespace recall per scope instead, |
| 64 | +capped at `MAX_SECTION_NAMESPACES` and reported through `SectionHits::truncated` |
| 65 | +when the cap bites. Each namespace is asked for the full `limit`, never a |
| 66 | +share of it — a share would let one scope's best hit lose to another's worst. |
| 67 | + |
| 68 | +**`cross_session` and `session_id` are refused outside the conversation |
| 69 | +section, and refused on `across_section` unconditionally.** The bundled |
| 70 | +`UnifiedMemory` driver's `cross_session` recall option surfaces episodic |
| 71 | +*conversational* rows from other sessions; its `session_id` option |
| 72 | +independently appends that session's episodic rows. Both relabel every such |
| 73 | +row with whichever namespace the call was pinned to, regardless of the |
| 74 | +option's own defaults. Honouring either on a `learning:` or `document:` |
| 75 | +section would therefore return conversational content mislabeled as that |
| 76 | +section's own hits, so `in_scope` rejects both with |
| 77 | +`CROSS_SESSION_SECTION_CONFLICT` — checked against the section's *normalised* |
| 78 | +form, so `Custom("conversation")` counts as `MemorySection::Conversation` — |
| 79 | +unless `section == MemorySection::Conversation`. |
| 80 | + |
| 81 | +`across_section` rejects both unconditionally, with |
| 82 | +`CROSS_SESSION_FAN_OUT_CONFLICT`, including on the conversation section. This |
| 83 | +is not merely the same hazard: the driver's episodic augmentation runs once, |
| 84 | +independent of the pinned namespace, so the fan-out would repeat the exact |
| 85 | +same rows once per scope in the merged result, crowding genuine hits out of |
| 86 | +`limit` — and it is also redundant even where it would not repeat, since |
| 87 | +`across_section` already visits every conversation scope on its own. A caller |
| 88 | +who wants cross-session or session-scoped recall uses `in_scope` instead, |
| 89 | +which issues exactly one call. |
| 90 | + |
| 91 | +**Visit order is by entry count descending, not recency.** `SectionScope::last_updated` |
| 92 | +is optional and no bundled driver currently populates it, so `scopes()` cannot |
| 93 | +order by recency today. This is deliberate and raised as an open question in |
| 94 | +`docs/specs/memory-section-api.md`, not an oversight. |
| 95 | + |
| 96 | +**This is not the document intake path.** `Sections::documents` writes through |
| 97 | +`MemoryCore`, for text a caller already holds. Handing the memory layer a |
| 98 | +*file* — sniffing its format, converting it to markdown, then choosing between |
| 99 | +`MemoryIngest`, `MemoryDocuments`, and `MemoryCore` — is `DocumentIntake`'s job |
| 100 | +in the `documents` module, which is the right entry point for an upload. |
| 101 | + |
| 102 | +**The `namespace: None` divergence between drivers is out of scope here.** The |
| 103 | +embedded engine and the reference driver disagree on what an unfiltered recall |
| 104 | +means, as noted above; fixing that divergence needs its own spec and is |
| 105 | +deliberately not attempted by this module. |
0 commit comments