-
Notifications
You must be signed in to change notification settings - Fork 59
Cortex Predictive Retrieval
geoffrey fernald edited this page Feb 1, 2026
·
1 revision
Predictive retrieval anticipates what memories you'll need before you ask, reducing latency and improving relevance.
Instead of waiting for queries, Cortex V2 predicts what you'll need based on:
- Current file context
- Recent activity patterns
- Temporal signals (time of day, day of week)
- Git activity
interface FileSignals {
activeFile: string; // Currently open file
recentFiles: string[]; // Recently edited files
fileType: string; // .ts, .tsx, .py, etc.
directory: string; // Current directory
imports: string[]; // Imported modules
}interface TemporalSignals {
hourOfDay: number; // 0-23
dayOfWeek: number; // 0-6
sessionDuration: number; // Minutes in session
timeSinceLastQuery: number; // Seconds
}interface BehavioralSignals {
recentIntents: Intent[]; // Recent query intents
recentTopics: string[]; // Recent focus areas
queryFrequency: number; // Queries per hour
correctionRate: number; // Corrections per query
}interface GitSignals {
currentBranch: string; // Feature branch name
recentCommits: string[]; // Recent commit messages
stagedFiles: string[]; // Files staged for commit
modifiedFiles: string[]; // Uncommitted changes
}The engine combines signals to predict relevant memories:
βββββββββββββββββββ
β Signal Gatherer β
β - File signals β
β - Temporal β
β - Behavioral β
β - Git β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Predictors β
β - File-based β
β - Pattern-basedβ
β - Temporal β
β - Behavioral β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Prediction β
β Cache β
β (preloaded) β
βββββββββββββββββββ
Predicts memories based on current file:
// If editing src/auth/login.ts
// Predict: auth patterns, security constraints, login-related tribal knowledgePredicts based on detected patterns in code:
// If file contains Express route handlers
// Predict: API patterns, error handling, validation patternsPredicts based on time patterns:
// If it's Monday morning
// Predict: memories frequently accessed on Monday morningsPredicts based on recent activity:
// If recent queries were about "authentication"
// Predict: more auth-related memoriesPredicted memories are preloaded into a fast cache:
interface PredictionCache {
memories: Map<string, Memory>; // Preloaded memories
predictions: PredictedMemory[]; // Ranked predictions
lastUpdated: Date;
hitRate: number; // Cache effectiveness
}// On file open
await predictionCache.warmForFile('src/auth/login.ts');
// On session start
await predictionCache.warmForSession(sessionContext);const predictions = await cortex.getPredictions({
activeFile: 'src/auth/login.ts',
limit: 10
});
// Returns:
// [
// { memory: {...}, confidence: 0.92, reason: 'file_match' },
// { memory: {...}, confidence: 0.85, reason: 'pattern_match' },
// ...
// ]// Preload into cache for instant retrieval
await cortex.preloadPredictions({
activeFile: 'src/auth/login.ts',
maxMemories: 20
});{
"activeFile": "src/auth/login.ts",
"recentFiles": ["src/auth/logout.ts", "src/middleware/auth.ts"],
"intent": "add_feature",
"limit": 10
}Response:
{
"predictions": [
{
"memoryId": "mem_abc123",
"summary": "JWT tokens must be validated on every request",
"confidence": 0.92,
"reason": "file_match",
"signals": ["activeFile contains 'auth'", "recent intent was 'add_feature'"]
}
],
"cacheStatus": {
"preloaded": 15,
"hitRate": 0.78
}
}| Metric | Without Prediction | With Prediction |
|---|---|---|
| First query latency | 150ms | 20ms (cache hit) |
| Relevance score | 0.75 | 0.88 |
| Token efficiency | 1x | 1.3x (better targeting) |
const predictionConfig = {
enabled: true,
maxCacheSize: 100, // Max memories in cache
cacheWarmingThreshold: 0.6, // Min confidence to cache
signalWeights: {
file: 0.4,
pattern: 0.3,
temporal: 0.15,
behavioral: 0.15
}
};- Enable prediction β Significant latency improvement
- Monitor hit rate β Should be > 60%
- Tune weights β Adjust based on your workflow
- Warm on file open β Preload when opening files
- Cortex V2 Overview
- Memory Setup Wizard
- Memory CLI
- Universal Memory Types
- Learning System
- Token Efficiency
- Causal Graphs
- Code Generation
- Predictive Retrieval
- Architecture
- Call Graph Analysis
- Impact Analysis
- Security Analysis
- Data Boundaries
- Test Topology
- Coupling Analysis
- Error Handling Analysis
- Wrappers Detection
- Environment Variables
- Constants Analysis
- Styling DNA
- Constraints
- Contracts
- Decision Mining
- Speculative Execution
- Watch Mode
- Trends Analysis
- Projects Management
- Package Context
- Monorepo Support
- Reports & Export
- Dashboard
- 10 Languages
- 21 Frameworks
- 16 ORMs
- 400+ Detectors
- 50+ MCP Tools
- 60+ CLI Commands
- 23 Memory Types