-
Notifications
You must be signed in to change notification settings - Fork 0
Learning Guide
How to teach your project to improve retrieval relevance through query patterns
NeuralMind's learning system automatically improves as you use it. The more you query, the smarter it gets.
┌──────────────────────────────────────────────────────────┐
│ 1. Query Your Code │
│ neuralmind query . "How does auth work?" │
│ ↓ Events logged to .neuralmind/memory/ │
├──────────────────────────────────────────────────────────┤
│ 2. Collect Patterns │
│ After 5-10 queries, run: │
│ neuralmind learn . │
│ ↓ Analyzes which modules appear together │
├──────────────────────────────────────────────────────────┤
│ 3. Automatic Improvement │
│ Next queries automatically boost related modules │
│ ↓ Better results in fewer tokens │
├──────────────────────────────────────────────────────────┤
│ 4. Continuous Learning │
│ Each new query adds to the pattern │
│ Run neuralmind learn . weekly for updates │
└──────────────────────────────────────────────────────────┘
First-time only. When you run your first query, you'll be prompted:
$ neuralmind query . "How does authentication work?"
Enable local NeuralMind memory logging to improve retrieval over time? [y/N]: y✅ Consent saved to ~/.neuralmind/memory_consent.json
To disable: Set NEURALMIND_MEMORY=0 or NEURALMIND_LEARNING=0
Just query as usual. Events are logged automatically.
# Daily usage - these all get logged
neuralmind query . "How does authentication work?"
neuralmind query . "What are the API endpoints?"
neuralmind query . "How is data validated?"
neuralmind query . "Where's the database logic?"
neuralmind query . "What's the error handling?"Each query logs:
- The question you asked
- Which modules were retrieved
- How many tokens used
- Which communities matched
After collecting 5-10 queries, analyze the patterns:
$ neuralmind learn .
Analyzing 8 query events...
✓ Learned 12 cooccurrence patterns
✓ Patterns saved to .neuralmind/learned_patterns.json
✓ Next query will apply learned patterns for improved retrieval
Top cooccurrence patterns:
community_0|community_1: 5 times (100% - auth + validation)
community_1|community_2: 4 times (validation + middleware)
community_0|community_2: 3 times (auth + middleware)On your next query, learned patterns are applied automatically:
$ neuralmind query . "How does auth work?"
## Search Results
1. **validate_user** (score: 0.85 +0.25 boost) ← Boosted due to cooccurrence!
Type: function
File: auth.py
2. **authenticate** (score: 0.91)
Type: function
File: auth.py
3. **check_permissions** (score: 0.78 +0.18 boost) ← Also boosted!
Type: function
File: middleware.pyWhat happened:
- System recognized "auth" question
- Looked for modules that frequently appear with auth
- Boosted validation and middleware in results
- Same token budget, better relevance ✅
Run neuralmind learn . weekly or after major development:
# Weekly learning update
0 9 * * 1 neuralmind learn /path/to/projectEach run:
- Reads new query events
- Updates pattern weights
- Saves improved patterns
The system tracks module cooccurrence — which code parts appear together in successful queries.
{
"cooccurrence": {
"community_0|community_1": 5,
"community_0|community_2": 3,
"community_1|community_2": 4
},
"module_frequency": {
"community_0": 8,
"community_1": 12,
"community_2": 7
}
}Example: If users ask about authentication, validation modules usually appear in L2 context (frequency: 5). The system learns this relationship.
When you query:
- L2 identifies context modules — which communities match your question
- L3 searches normally — semantic search finds candidates
- Reranker boosts results — modules cooccurring with L2 context get +0.3 multiplier
- Final ranking — better matches rise to top
Boost formula:
combined_score = semantic_score × (1.0 + 0.3 × cooccurrence_strength)
Where cooccurrence_strength is 0-1 (normalized to max pattern).
Queries ask about: auth, validation, permissions
System learns: These modules appear together
Effect: "How does auth work?" automatically includes validation
Token savings: -20% (fewer irrelevant results)
Queries ask about: API endpoints, routes, handlers
System learns: These modules always appear together
Effect: "What are the endpoints?" automatically includes handler details
Token savings: -15% (more complete context)
Queries ask about: database, models, migrations
System learns: These concepts are linked
Effect: "How's the data stored?" includes migration history
Token savings: -25% (better context relevance)
✅ 100% Local — All learning happens on your machine
✅ No Telemetry — Nothing sent to servers
✅ User Control — One-time consent, can disable anytime
✅ Persistent — Patterns stay in your .neuralmind/ directory
~/.neuralmind/
├── memory_consent.json # Consent flag (once per user)
└── memory/
└── query_events.jsonl # Global event log
project/.neuralmind/
├── memory/
│ └── query_events.jsonl # Project-specific events
└── learned_patterns.json # Learned patterns (created by neuralmind learn)
# Disable memory logging
export NEURALMIND_MEMORY=0
# Disable learning
export NEURALMIND_LEARNING=0
# Use both to disable completely
export NEURALMIND_MEMORY=0 NEURALMIND_LEARNING=0Problem: You run neuralmind learn . but see "No query events found"
Solution:
- Have you run at least 1 query?
neuralmind query . "test" - Did you consent to memory logging? You should see prompt on first query
- Check memory file exists:
ls -la project/.neuralmind/memory/query_events.jsonl - Check NEURALMIND_MEMORY not set to 0
Problem: You see "Learned 0 cooccurrence patterns"
Solution:
- You may need 5+ queries for meaningful patterns
- Your queries might be too different (no overlapping modules)
- Try a few more queries, then run learn again
Problem: You see no boost scores in search results
Solution:
- Run
neuralmind query . "test"again (must be AFTER learning) - Check file exists:
ls -la project/.neuralmind/learned_patterns.json - Check logs aren't disabled:
echo $NEURALMIND_LEARNING - Try with a fresh query (not the exact same as before)
✅ DO: Ask questions naturally as they come up
neuralmind query . "How does user login work?"
❌ DON'T: Artificially create queries just for learning✅ DO: Run learn after several days/weeks of usage
neuralmind learn . # Weekly is ideal
❌ DON'T: Rely on very fresh patterns (need 5+ queries)✅ DO: Ask varied questions about your codebase
- "How does auth work?"
- "What are the API routes?"
- "How is data validated?"
❌ DON'T: Ask the exact same question repeatedly✅ DO: Check top patterns to understand your code structure
neuralmind learn . | grep "cooccurrence"
❌ DON'T: Manually edit learned_patterns.json (it's auto-generated)Learning has zero overhead:
- Pattern loading: ~1ms (lazy loaded, happens once)
- Reranking: ~5ms (only sort, no compute)
- Memory: ~10KB for patterns file
- Storage: ~50KB for event logs (100 queries)
Total cost: Negligible compared to network latency of semantic search.
v0.4.0 adds a second learning system that runs in parallel with the v0.3.2 cooccurrence reranker described above. They are complementary — read this section as "what v0.4 adds on top".
| Aspect | v0.3.2 reranker | v0.4 synapse layer |
|---|---|---|
| Data structure | Cooccurrence counts in JSON (.neuralmind/learned_patterns.json) |
Weighted graph in SQLite (.neuralmind/synapses.db) |
| Update timing | Batch — runs neuralmind learn . after collecting events |
Continuous — updates on every query, tool call, file edit |
| What it influences | Re-orders L3 search hits | Adds a new retrieval path (spreading activation) and surfaces associations to Claude Code's auto-memory |
| Memory model | Logged event history | Hebbian + decay + LTP (long-term potentiation) |
| Forgets stale patterns? | No (only what you analyze) | Yes (multiplicative decay; LTP floor protects frequent associations) |
In short: the reranker improves the ordering of vector-search hits based on cooccurrence patterns from the past. The synapse layer is an independent associative memory that can recall related code even when vector search wouldn't have found it — because the relationship isn't textual or graph-structural, it's behavioral, learned from co-activation.
Five activation paths, all of which strengthen pairwise edges between co-active nodes (Hebbian: "nodes that fire together wire together"):
-
Every
mind.query()— top search hits + loaded communities reinforce. -
PostToolUsehook — when the agent reads/runs/searches code together. -
UserPromptSubmithook — current prompt's neighbors get an activation pulse. -
SessionStarthook — runs decay so weights age between sessions, then exports memory. -
neuralmind watchdaemon — debounces file edits into co-activation batches; co-edited files wire together.
# One-time: install the lifecycle hooks (idempotent — safe to re-run)
neuralmind install-hooks .
# Optional: always-on learning from file edits
neuralmind watch &
# That's it — the synapse store grows continuously.
# Inspect what was learned
cat .neuralmind/SYNAPSE_MEMORY.mdEach SessionStart re-exports the synapse memory as markdown to:
-
<project>/.neuralmind/SYNAPSE_MEMORY.md— import inCLAUDE.mdvia@.neuralmind/SYNAPSE_MEMORY.mdso it's part of every session. -
~/.claude/projects/<slug>/memory/synapse-activations.md— Claude Code's auto-memory directory (when present); the model picks it up natively without anyone calling an MCP tool.
Local-only, project-scoped, same as the v0.3.x memory layer. No external services. Disable with:
-
NEURALMIND_SYNAPSE_INJECT=0— skip prompt-time recall injection -
NEURALMIND_SYNAPSE_EXPORT=0— skip the auto-memory export -
NeuralMind(..., enable_synapses=False)— disable the layer entirely -
mind.synapses.reset()— wipe the learned graph any time
- v0.4.0 Release Notes — full feature walkthrough
- Architecture: Synapse Layer (v0.4) — design and activation channels
- Synapse import/export — let teams share a learned brain.
- Quality benchmark — measure retrieval gain with vs without synapses.
-
Auto-watcher launch from
SessionStart— no manualwatchinvocation needed. - Feedback signals — explicit ratings improve pattern accuracy.
- CLI Reference — All commands
- Brain-Like Learning — v0.3.x design rationale
- Architecture — v0.4 synapse layer architecture
- Troubleshooting — Common issues