-
Notifications
You must be signed in to change notification settings - Fork 2
SDK Reference
The Total Recall TypeScript SDK provides full programmatic access to the AI coding assistant memory system. It connects directly to the local SQLite database — no worker required.
npm install totalrecallaiimport { createTotalRecall } from 'totalrecallai';
const ctx = createTotalRecall({ project: 'my-project' });
const context = await ctx.getContext();
ctx.close();The createTotalRecall function accepts a configuration object:
interface TotalRecallConfig {
dataDir?: string; // Default: ~/.totalrecall
project?: string; // Default: auto-detected from git root
skipMigrations?: boolean; // Skip migration check for performance (use in hooks)
}The getContext method retrieves recent observations, summaries, and prompts for the current project.
const context = await ctx.getContext();
// Returns: { project, relevantObservations, relevantSummaries, recentPrompts }The storeObservation method stores a new observation with automatic deduplication (SHA256 content hash) and background embedding generation.
const id = await ctx.storeObservation({
type: 'note', // Required: file-write, command, research, note, etc.
title: 'Auth fix', // Required: max 500 chars
content: 'Fixed OAuth flow with 5-min token buffer', // Required: max 100KB
subtitle: 'OAuth2', // Optional
narrative: 'Detailed narrative...', // Optional
facts: 'key facts...', // Optional
concepts: ['auth', 'oauth'], // Optional: tags
filesRead: ['src/auth.ts'], // Optional
filesModified: ['src/auth.ts'] // Optional
});Returns the observation ID, or -1 if deduplicated.
The storeKnowledge method stores structured knowledge with type-specific metadata.
await ctx.storeKnowledge({
knowledgeType: 'decision', // constraint | decision | heuristic | rejected
title: 'Chose PostgreSQL over MongoDB',
content: 'ACID compliance required for financial transactions',
metadata: {
reason: 'Need strong consistency guarantees',
alternatives: ['MongoDB', 'DynamoDB']
}
});The storeSummary method stores a structured session summary.
const id = await ctx.storeSummary({
content: 'Implemented OAuth2 login with Google provider',
investigated: 'OAuth2 flow, JWT best practices',
completed: 'Google OAuth provider',
learned: 'Use 5-min buffer for token refresh',
nextSteps: 'Add GitHub OAuth provider'
});The search method performs full-text search (FTS5 with BM25 scoring).
const results = await ctx.search('authentication');
// Returns: { observations: Observation[], summaries: Summary[] }The searchAdvanced method performs FTS5 search with project and type filters.
const results = await ctx.searchAdvanced('auth', {
project: 'my-app',
type: 'file-write',
limit: 10
});The hybridSearch method combines vector embeddings and FTS5 keyword search with 4-signal smart ranking.
const results = await ctx.hybridSearch('authentication flow', { limit: 10 });
// Returns: SearchResult[] with score, source, id, type, title, contentThe semanticSearch method performs pure vector similarity search using local embeddings.
const results = await ctx.semanticSearch('OAuth token refresh', {
limit: 5,
threshold: 0.3 // Minimum cosine similarity
});The getOrCreateSession method gets an existing session or creates a new one.
const session = await ctx.getOrCreateSession('session-abc-123');The completeSession method marks a session as completed.
await ctx.completeSession(session.id);The createCheckpoint method saves a session checkpoint for later resume. Automatically includes a context snapshot of the last 10 observations.
await ctx.createCheckpoint(session.id, {
task: 'Implement OAuth2 login',
progress: 'Google provider done, GitHub pending',
nextSteps: 'Add GitHub OAuth provider',
openQuestions: 'Should we support SAML?',
relevantFiles: ['src/auth/oauth.ts', 'src/middleware/auth.ts']
});const checkpoint = await ctx.getCheckpoint(session.id);
const latest = await ctx.getLatestProjectCheckpoint();await ctx.storePrompt('session-abc', 1, 'Fix the authentication bug');await ctx.storeConversationMessage({
contentSessionId: 'session-abc',
role: 'user',
content: 'Fix the authentication bug',
messageIndex: 0
});const messages = await ctx.getConversationMessages('session-abc');const count = await ctx.importConversationTranscript('session-abc', '/path/to/transcript.jsonl');The getSmartContext method retrieves context ranked by the 4-signal scoring system (recency, frequency, semantic similarity, decay).
const smartCtx = await ctx.getSmartContext({
limit: 20,
query: 'authentication', // Optional: boosts semantically similar results
includeKnowledge: true
});const obs = await ctx.getRecentObservations(10);
const sums = await ctx.getRecentSummaries(5);const obs = await ctx.getObservationsByIds([1, 2, 3]);The getTimeline method returns chronological context around a specific observation.
const timeline = await ctx.getTimeline(42, 5, 5);const available = await ctx.initializeEmbeddings();const processed = await ctx.backfillEmbeddings(50);const stats = ctx.getEmbeddingStats();
// Returns: { total, embedded, percentage }const staleCount = await ctx.detectStaleObservations();const result = await ctx.consolidateObservations({ dryRun: true });
// Returns: { merged, removed }const stats = await ctx.getDecayStats();
// Returns: { total, stale, neverAccessed, recentlyAccessed }const report = await ctx.generateReport({
period: 'weekly', // or 'monthly'
startDate: new Date('2026-04-01'),
endDate: new Date('2026-04-07')
});Both methods support keyset pagination for efficient traversal of large datasets.
const page1 = await ctx.listObservations({ limit: 50 });
const page2 = await ctx.listObservations({ cursor: page1.next_cursor });
// Returns: { data, next_cursor, has_more }const project = ctx.getProject();The close method closes the database connection. Always call when done.
ctx.close();| Method | Returns | Description |
|---|---|---|
getContext() |
ContextContext |
Recent observations, summaries, and prompts |
storeObservation(data) |
number |
Store observation (returns ID, -1 if deduped) |
storeKnowledge(data) |
number |
Store structured knowledge |
storeSummary(data) |
number |
Store session summary |
search(query) |
{ observations, summaries } |
FTS5 full-text search |
searchAdvanced(query, filters) |
{ observations, summaries } |
FTS5 with filters |
hybridSearch(query, opts) |
SearchResult[] |
Vector + FTS5 hybrid search |
semanticSearch(query, opts) |
SearchResult[] |
Pure vector similarity search |
getRecentObservations(limit) |
Observation[] |
Recent observations |
getRecentSummaries(limit) |
Summary[] |
Recent summaries |
getObservationsByIds(ids) |
Observation[] |
Observations by ID |
getTimeline(anchor, before, after) |
TimelineEntry[] |
Chronological context |
getOrCreateSession(id) |
DBSession |
Get or create session |
completeSession(sessionId) |
void |
Mark session completed |
storePrompt(sessionId, num, text) |
number |
Store user prompt |
storeConversationMessage(data) |
number |
Store conversation message |
getConversationMessages(sessionId) |
ConversationMessage[] |
Get conversation messages |
importConversationTranscript(id, path) |
number |
Import transcript |
createCheckpoint(sessionId, data) |
number |
Save session checkpoint |
getCheckpoint(sessionId) |
DBCheckpoint | null |
Get session checkpoint |
getLatestProjectCheckpoint() |
DBCheckpoint | null |
Get latest project checkpoint |
generateReport(opts) |
ReportData |
Generate activity report |
getSmartContext(opts) |
SmartContext |
Context with 4-signal ranking |
initializeEmbeddings() |
boolean |
Initialize embedding service |
backfillEmbeddings(batchSize) |
number |
Generate missing embeddings |
getEmbeddingStats() |
{ total, embedded, percentage } |
Embedding coverage stats |
detectStaleObservations() |
number |
Detect and mark stale observations |
consolidateObservations(opts) |
{ merged, removed } |
Consolidate duplicates |
getDecayStats() |
DecayStats |
Memory decay statistics |
listObservations(opts) |
KeysetPageResult<Observation> |
Paginated observations |
listSummaries(opts) |
KeysetPageResult<Summary> |
Paginated summaries |
getProject() |
string |
Current project name |
close() |
void |
Close database connection |
Total Recall Wiki
- Home
- Installation
- Configuration
- CLI Reference
- SDK Reference
- MCP Tools
- Architecture
- Troubleshooting
- FAQ