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:
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.py
What happened:
Run neuralmind learn . weekly or after major development:
# Weekly learning update
0 9 * * 1 neuralmind learn /path/to/project
Each run:
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:
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=0
Problem: You run neuralmind learn . but see βNo query events foundβ
Solution:
neuralmind query . "test"ls -la project/.neuralmind/memory/query_events.jsonlProblem: You see βLearned 0 cooccurrence patternsβ
Solution:
Problem: You see no boost scores in search results
Solution:
neuralmind query . "test" again (must be AFTER learning)ls -la project/.neuralmind/learned_patterns.jsonecho $NEURALMIND_LEARNINGβ
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:
Total cost: Negligible compared to network latency of semantic search.
π Feedback Signals β Explicit ratings improve pattern accuracy π Conversation Memory β Context awareness across multiple queries π Predictive Loading β Anticipate needs based on current file π Team Learning β Share patterns across team members