Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@ impl Network {
pub fn forward_with_cache(&self, input: &[f32]) -> ForwardCache { ... }
pub fn grow_neuron(&mut self, layer_id: u32, input_size: usize) -> Result<u64, ManasError> { ... }
pub fn grow_layer(&mut self, input_size: usize, neuron_count: usize) -> Result<u32, ManasError> { ... }
pub fn bind_hidden_neuron_to_fact(&mut self, neuron_id: u64, input: &[f32], target: &[f32])
-> Result<usize, ManasError> { ... }
pub fn readout_from_best_hidden(&self, input: &[f32]) -> Option<HiddenReadout> { ... }
pub fn neuron_count(&self) -> u64 { ... }
pub fn layer_count(&self) -> usize { ... }
pub fn open_neuron_count(&self) -> u64 { ... }
Expand Down Expand Up @@ -780,6 +783,12 @@ pub struct QueryResult {
pub freshness_warning: Option<FreshnessWarning>,
}

pub struct HiddenReadout {
pub hidden_index: usize,
pub activation: f32,
pub output: Vec<f32>,
}

pub struct FreshnessWarning {
pub category: FreshnessCategory,
pub age_days: u64,
Expand Down Expand Up @@ -1008,16 +1017,12 @@ manas teach "A cat is a small domesticated animal with fur and whiskers."
3. manas-ingest: chunk (single chunk, text is short)
4. manas-learn: tokenize chunk → token IDs
5. manas-learn: embed with positional encoding → input_vec (Vec<f32>)
6. manas-learn: build target — encode("cat animal fur whiskers small domesticated") → target_vec
7. manas-core: forward(input_vec) → output_vec
8. manas-learn: compute MSE loss(output_vec, target_vec)
9. manas-learn: loss > GROWTH_THRESHOLD?
→ yes: try updating Open neurons (up to MAX_ATTEMPTS)
→ still high: grow new neuron in appropriate layer
10. manas-core: apply_gradients() — respects ProtectionLevel on every neuron
11. manas-learn: update importance scores, promote protection levels
12. manas-store: append new neurons to .manas; update existing neuron records
13. manas-cli: print LearnReport
6. manas-learn: build decode-friendly answer vector from meaningful target words
7. manas-core: grow or reuse an Open keyed hidden neuron
8. manas-core: bind the hidden neuron to input_vec and write target_vec into its output column
9. manas-learn: update importance, source, freshness, and protection metadata
10. manas-store: persist network weights, vocab, and neuron metadata in .manas
11. manas-cli: print LearnReport
```

### Asking a Question
Expand All @@ -1026,15 +1031,16 @@ manas teach "A cat is a small domesticated animal with fur and whiskers."
manas ask "What is a cat?"

1. manas-cli: parse command
2. manas-learn: encode("What is a cat") → question_vec (Vec<f32>)
3. manas-core: forward(question_vec) → output_vec
4. manas-learn: confidence = cosine_similarity(output_vec, nearest known vector)
5. confidence > MIN_CONFIDENCE?
2. manas-learn: build query variants such as "cat" from "What is a cat?"
3. manas-learn: encode each query variant → question_vec (Vec<f32>)
4. manas-core: select best activated hidden neuron and read only its output column
5. manas-learn: confidence = decoded answer score × hidden activation
6. confidence > MIN_CONFIDENCE?
→ yes: decode(output_vec) → "small domesticated animal with fur and whiskers"
answered_from = AnswerSource::NeuralWeights
→ no: "Not enough knowledge yet."
answered_from = AnswerSource::NotEnough
6. manas-cli: print QueryResult
7. manas-cli: print QueryResult
```

No text file. No sidecar. No internet. The network answers from its own weights.
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Manas uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Stage 10 — File and folder ingestion.
- Stage 11 — Importance scoring and promotion.
- Stage 12 — Freshness system.
- Stage 13 — The real demo.

### Added

Expand Down Expand Up @@ -74,10 +75,17 @@ Manas uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
stale.
- Added freshness tests for detection, staleness, trainer query warnings, CLI
rendering, CLI teach metadata, and `.manas` persistence.
- Added bound hidden-neuron readout so sequentially learned facts retrieve from
their own neural output columns instead of drifting toward the latest fact.
- Added decode-friendly answer vectors for learned targets and query variants
for natural questions like "Where is the Eiffel Tower?"
- Added `demo.sh` plus the Stage 13 CLI integration test that teaches 22 facts,
deletes all historical sidecars, verifies five neural-weight answers, and
enforces the sub-500KB brain size gate.

### Next

- Stage 13The real demo.
- Stage 14Inspect, neurons, and debug commands.

---

Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ Manas v2 is in active development. The roadmap follows a strict rule:
| Stage 10 | File and folder ingestion | Complete |
| Stage 11 | Importance scoring and promotion | Complete |
| Stage 12 | Freshness system | Complete |
| Stage 13 | The real demo | Next |
| Stage 14+ | Inspect, benchmarks, layer growth | Planned |
| Stage 13 | The real demo | Complete |
| Stage 14 | Inspect, neurons, and debug commands | Next |
| Stage 15+ | Compression, benchmarks, layer growth | Planned |

Stages 1 and 2 are preserved as a standalone proof in
`manas-core/src/experiment.rs`. Stage 3 promotes the proven engine into
Expand All @@ -154,7 +155,9 @@ inside the learned neurons. Stage 11 replaces activation-count-only promotion
with weighted importance scoring based on frequency, recency, weight magnitude,
and smooth age grace. Stage 12 classifies learned knowledge as Timeless, Slow,
Fast, or Realtime and warns during `manas ask` when the answer comes from stale
neuron metadata.
neuron metadata. Stage 13 adds the full 22-fact proof: the demo teaches facts,
deletes historical sidecars, and verifies that five questions answer from neural
weights only.

Run the proof:

Expand All @@ -176,6 +179,12 @@ Run the maintained crate proof:
cargo test -p manas-learn anti_forgetting
```

Run the v0.1.0 real demo:

```bash
bash demo.sh
```

Run the persistence proof:

```bash
Expand Down
28 changes: 21 additions & 7 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ from Stage 2 onward.**
| Stage 10 | File and folder ingestion | Complete |
| Stage 11 | Importance scoring and promotion | Complete |
| Stage 12 | Freshness system | Complete |
| Stage 13 | The real demo | Next |
| Stage 14 | Inspect, neurons, and debug commands | Planned |
| Stage 13 | The real demo | Complete |
| Stage 14 | Inspect, neurons, and debug commands | Next |
| Stage 15 | Compression and forget command | Planned |
| Stage 16 | Benchmarks and test suite | Planned |
| Stage 17 | Layer growth | Planned |
Expand Down Expand Up @@ -1663,6 +1663,10 @@ fn fast_fact_stale_after_30_days() {
**Goal:** Run the definitive test that v1 failed. This is the milestone that proves
the whole project works.

**Status:** Complete. `bash demo.sh` builds the release binary, teaches all 22
facts, deletes all historical sidecars, verifies five neural-weight answers, and
checks that `brain.manas` stays under 500KB.

### The Demo Script

```bash
Expand Down Expand Up @@ -1741,11 +1745,21 @@ Search results from DuckDuckGo...

### Done When

- [ ] All 5 `ask` calls return answers
- [ ] All 5 show `Answered from: neural weights`
- [ ] No sidecar files exist when the test runs
- [ ] Brain file is under 500KB for 22 facts
- [ ] `manas inspect` shows correct neuron and protection stats
- [x] All 5 `ask` calls return answers
- [x] All 5 show `Answered from: neural weights`
- [x] No sidecar files exist when the test runs
- [x] Brain file is under 500KB for 22 facts
- [x] `manas inspect` shows correct neuron and protection stats

### Stage 13 Implementation Notes

- Added bound hidden-neuron readout in `manas-core` so each learned fact keeps
its own neural output column
- Added decode-friendly answer vectors and question variants in `manas-learn`
so natural questions retrieve the intended keyed fact
- Added `demo.sh` and `manas-cli/tests/stage13_demo.rs` as the permanent
22-fact proof
- Current proof result: `bash demo.sh` passes with `brain.manas` at about 83KB

**This is v0.1.0. The first real version of Manas.**

Expand Down
164 changes: 164 additions & 0 deletions demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BIN="$ROOT_DIR/target/release/manas"
MAX_BRAIN_BYTES=$((500 * 1024))

if [[ -n "${MANAS_DEMO_DIR:-}" ]]; then
DEMO_DIR="$MANAS_DEMO_DIR"
mkdir -p "$DEMO_DIR"
else
DEMO_DIR="$(mktemp -d /tmp/manas-stage13-demo-XXXXXX)"
fi

facts=(
"A cat is a small domesticated animal with fur and whiskers."
"The Eiffel Tower is located in Paris France and was built in 1889."
"The Amazon River is the largest river by discharge in the world."
"Photosynthesis is the process by which plants convert sunlight into energy."
"Hydrogen is the lightest and most abundant element in the universe."
"The human brain contains approximately 86 billion neurons."
"Mount Everest is the highest mountain on Earth at 8849 meters."
"Shakespeare wrote 37 plays and 154 sonnets during his lifetime."
"The speed of light in vacuum is approximately 299792458 meters per second."
"DNA is a double helix structure that carries genetic information."
"The Roman Empire fell in 476 AD when Romulus Augustulus was deposed."
"Water boils at 100 degrees Celsius at standard atmospheric pressure."
"The Python programming language was created by Guido van Rossum in 1991."
"Jupiter is the largest planet in our solar system with 95 known moons."
"The Mona Lisa was painted by Leonardo da Vinci in the early 16th century."
"Rust programming language was first released by Mozilla Research in 2010."
"The mitochondria is the powerhouse of the cell in biology."
"Albert Einstein developed the theory of relativity in the early 20th century."
"The Pacific Ocean is the largest and deepest ocean on Earth."
"Bitcoin was created by Satoshi Nakamoto and launched in January 2009."
"The nitrogen cycle describes how nitrogen moves through ecosystems."
"Gravity pulls objects toward each other with a force proportional to mass."
)

sidecars=(
"brain.manas.sources"
"brain.manas.sourceindex"
"brain.manas.seq"
"brain.manas.transformer"
"brain.manas.langmeta"
)

echo "=== Building release binary ==="
cargo build --workspace --release

cd "$DEMO_DIR"
echo "=== Demo directory ==="
echo "$DEMO_DIR"

echo ""
echo "=== Starting fresh ==="
rm -f brain.manas "${sidecars[@]}"
"$BIN" reset

echo ""
echo "=== Teaching 22 facts ==="
for fact in "${facts[@]}"; do
"$BIN" teach "$fact" >/dev/null
done

echo ""
echo "=== Deleting all sidecars: neural weights only ==="
rm -f "${sidecars[@]}"
for sidecar in "${sidecars[@]}"; do
if [[ -e "$sidecar" ]]; then
echo "sidecar still exists: $sidecar" >&2
exit 1
fi
done

require_neural_answer() {
local output="$1"
if ! grep -q $'Answered from\n neural weights' <<<"$output"; then
echo "answer did not come from neural weights:" >&2
echo "$output" >&2
exit 1
fi
if grep -q "Not enough knowledge yet." <<<"$output"; then
echo "answer reported not enough knowledge:" >&2
echo "$output" >&2
exit 1
fi
}

require_all_words() {
local output
output="$(tr '[:upper:]' '[:lower:]' <<<"$1")"
shift
for word in "$@"; do
if ! grep -q "$word" <<<"$output"; then
echo "answer missed required word '$word':" >&2
echo "$output" >&2
exit 1
fi
done
}

require_two_words() {
local output
output="$(tr '[:upper:]' '[:lower:]' <<<"$1")"
shift
local count=0
for word in "$@"; do
if grep -q "$word" <<<"$output"; then
count=$((count + 1))
fi
done
if (( count < 2 )); then
echo "answer matched only $count keywords from: $*" >&2
echo "$output" >&2
exit 1
fi
}

ask_and_print() {
local question="$1"
echo ""
echo "QUESTION: $question"
"$BIN" ask "$question"
}

echo ""
echo "=== Asking: must answer from neural weights ==="
cat_answer="$(ask_and_print "What is a cat?")"
echo "$cat_answer"
require_neural_answer "$cat_answer"
require_two_words "$cat_answer" small domesticated animal fur whiskers

eiffel_answer="$(ask_and_print "Where is the Eiffel Tower?")"
echo "$eiffel_answer"
require_neural_answer "$eiffel_answer"
require_two_words "$eiffel_answer" paris france 1889

einstein_answer="$(ask_and_print "What did Einstein develop?")"
echo "$einstein_answer"
require_neural_answer "$einstein_answer"
require_all_words "$einstein_answer" theory relativity

mitochondria_answer="$(ask_and_print "What is the mitochondria?")"
echo "$mitochondria_answer"
require_neural_answer "$mitochondria_answer"
require_all_words "$mitochondria_answer" powerhouse cell

bitcoin_answer="$(ask_and_print "When was Bitcoin created?")"
echo "$bitcoin_answer"
require_neural_answer "$bitcoin_answer"
require_two_words "$bitcoin_answer" satoshi nakamoto 2009

brain_size="$(wc -c < brain.manas)"
if (( brain_size >= MAX_BRAIN_BYTES )); then
echo "brain.manas is too large: $brain_size bytes" >&2
exit 1
fi

echo ""
echo "=== Brain state ==="
"$BIN" inspect
echo ""
echo "Stage 13 demo passed: brain.manas is $brain_size bytes."
Loading
Loading