Skip to main content

TypeScript SDK: Memories

Create, search, update, and delete memories with the TypeScript SDK.

Overview

The memories resource handles creating, reading, updating, and deleting memory objects. Memories are the core data type in Trix.

Create Memory

create-memory.ts
const memory = await trix.memories.create({
  content: 'TypeScript provides static type checking at compile time',
  type: 'text',
  tags: ['typescript', 'programming'],
  metadata: {
    source: 'documentation',
    author: 'team'
  },
  spaceId: 'space_abc123'
});

console.log(memory.id);
console.log(memory.content);

Create Options

OptionTypeDescription
contentstringMemory content (required)
typestring'text', 'markdown', 'url', 'audio'
tagsstring[]Tags for categorization
metadataobjectCustom key-value metadata
spaceIdstringSpace to store memory in
prioritynumberPriority level (0-100)
saliencenumberImportance score (0-1)

List and Search Memories

list-memories.ts
const { data, pagination } = await trix.memories.list({
  limit: 20, page: 1
});

const results = await trix.memories.list({
  q: 'how does TypeScript handle types?',
  mode: 'semantic',
  limit: 10
});

const tagged = await trix.memories.list({
  tags: ['typescript', 'frontend'],
  sortBy: 'createdAt',
  sortOrder: 'desc'
});

Search Modes

ModeDescriptionBest For
semanticVector similarity searchConceptual queries
keywordTraditional keyword searchExact matches
hybridCombined semantic and keywordGeneral purpose (recommended)

Async Iteration

Stream through all memories without manual pagination:

iterate-memories.ts
for await (const memory of trix.memories.listAll({ limit: 100 })) {
  console.log(memory.content);
}

for await (const memory of trix.memories.listAll({
  tags: ['important'],
  type: 'text'
})) {
  processMemory(memory);
}

Async iteration is the recommended way to process large datasets. It handles pagination automatically and only fetches data as needed.

Get Single Memory

get-memory.ts
const memory = await trix.memories.get('mem_xyz789');
console.log(memory.content);
console.log(memory.tags);
console.log(memory.metadata);

Update Memory

update-memory.ts
const updated = await trix.memories.update('mem_xyz789', {
  content: 'Updated content here',
  tags: ['typescript', 'updated'],
  metadata: {
    lastReviewed: new Date().toISOString()
  }
});

Updating content will trigger re-embedding. If you only want to update metadata or tags, the embedding will be preserved.

Delete Memory

delete-memory.ts
await trix.memories.delete('mem_xyz789');

Bulk Operations

Perform operations on multiple memories at once for better performance:

Bulk Create

bulk-create.ts
const result = await trix.memories.bulkCreate([
  { content: 'First memory', tags: ['batch'] },
  { content: 'Second memory', tags: ['batch'] },
  { content: 'Third memory', tags: ['batch'] }
]);

console.log(`Created: ${result.success}, Failed: ${result.failed}`);

Bulk Update

bulk-update.ts
await trix.memories.bulkUpdate([
  { id: 'mem_1', tags: ['reviewed'] },
  { id: 'mem_2', content: 'Updated content' }
]);

Bulk Delete

bulk-delete.ts
await trix.memories.bulkDelete(['mem_1', 'mem_2', 'mem_3']);

Audio Memories

Store and transcribe audio files:

Create Audio Memory

create-audio.ts
const audioMemory = await trix.memories.create({
  content: 'Meeting recording - Q4 planning',
  type: 'audio',
  audioFile: audioBlob,
  tags: ['meeting', 'q4']
});

Stream Audio

stream-audio.ts
const stream = await trix.memories.streamAudio('mem_audio123');

Transcription

transcription.ts
const job = await trix.memories.transcribe('mem_audio123', {
  language: 'en',
  priority: 'high'
});

const transcript = await trix.memories.getTranscript('mem_audio123');
console.log(transcript.text);
console.log(transcript.segments);

Feedback

Collect user feedback on memories to improve relevance and quality.

feedback.ts
await trix.feedback.submit({
  memoryId: 'mem_xyz',
  type: 'positive',
  comment: 'This was exactly what I needed',
  metadata: {
    context: 'search_result'
  }
});

await trix.feedback.quick({
  memoryId: 'mem_xyz',
  type: 'thumbs_up'
});

await trix.feedback.batch({
  feedback: [
    { memoryId: 'mem_1', type: 'positive' },
    { memoryId: 'mem_2', type: 'negative', comment: 'Outdated' },
    { memoryId: 'mem_3', type: 'neutral' }
  ]
});

Highlights

Create and manage text highlights within memories.

highlights.ts
const highlight = await trix.highlights.create('mem_xyz', {
  text: 'important concept',
  startOffset: 42,
  endOffset: 60,
  color: 'yellow',
  note: 'Key takeaway from this section'
});

for await (const h of trix.highlights.listAll('mem_xyz')) {
  console.log(`"${h.text}" - ${h.note}`);
}

const extracted = await trix.highlights.extract('mem_xyz', {
  method: 'ai',
  limit: 5
});

for (const { text, score } of extracted.highlights) {
  console.log(`${score.toFixed(2)}: ${text}`);
}

await trix.highlights.update('hlt_abc', {
  color: 'green',
  note: 'Updated note'
});

await trix.highlights.delete('hlt_abc');

Memory Pinning

Pin important memories to prevent them from being affected by decay or automatic cleanup. Pinned memories are always prioritized in search results.

pinning.ts
await trix.memories.pin('mem_xyz789');
await trix.memories.unpin('mem_xyz789');

const memory = await trix.memories.get('mem_xyz789');
console.log('Pinned:', memory.isPinned);

const pinned = await trix.memories.create({
  content: 'Critical business rule: always validate input',
  isPinned: true,
  tags: ['rules', 'validation']
});

const { data } = await trix.memories.list({ pinned: true });
for (const m of data) {
  console.log(`Pinned: ${m.content.slice(0, 50)}...`);
}

Use pinning for critical information that should never be forgotten, such as core business rules, important contacts, or key procedures.

Protection Levels

Set protection levels on memories to control how they can be modified or deleted. This provides an extra layer of safety for important data.

protection.ts
await trix.memories.setProtectionLevel('mem_xyz789', 'hard');

const protectedMemory = await trix.memories.create({
  content: 'Legal compliance requirement: retain for 7 years',
  protectionLevel: 'hard',
  tags: ['legal', 'compliance']
});

const memory = await trix.memories.get('mem_xyz789');
console.log('Protection:', memory.protectionLevel);

await trix.memories.setProtectionLevel('mem_xyz789', 'none');
await trix.memories.delete('mem_xyz789');

Protection Level Reference

LevelDescriptionUse Case
'none'No protection, can be freely modified or deletedRegular memories
'soft'Deletion requires explicit confirmationImportant but occasionally updated data
'hard'Cannot be deleted without first removing protectionCritical data, compliance requirements

Soft Delete & Restore

Soft delete moves memories to a recoverable state instead of permanently deleting them. This allows you to restore accidentally deleted memories.

soft-delete.ts
await trix.memories.softDelete('mem_xyz789');

const deleted = await trix.memories.get('mem_xyz789', { includeDeleted: true });
console.log('Deleted at:', deleted.deletedAt);

await trix.memories.restore('mem_xyz789');

const restored = await trix.memories.get('mem_xyz789');
console.log('Status: active');

const { data } = await trix.memories.list({
  includeDeleted: true,
  onlyDeleted: true
});
for (const m of data) {
  console.log(`Deleted: ${m.content.slice(0, 50)}... at ${m.deletedAt}`);
}

await trix.memories.delete('mem_xyz789', { permanent: true });

Soft-deleted memories are automatically purged after 30 days by default. Configure the retention period in your space settings.

Topic Extraction

Extract and search by topics to organize and discover related memories. Topics are automatically extracted or can be manually assigned.

topics.ts
const topics = await trix.memories.getTopics('mem_xyz789');
for (const topic of topics) {
  console.log(`Topic: ${topic.name} (confidence: ${topic.confidence.toFixed(2)})`);
}

const results = await trix.memories.searchByTopic('machine learning');
for (const result of results.data) {
  console.log(`${result.score.toFixed(2)}: ${result.memory.content.slice(0, 50)}...`);
}

const multiTopic = await trix.memories.searchByTopic('typescript', {
  limit: 20
});

const combined = await trix.memories.list({
  q: 'state management',
  topics: ['frontend'],
  mode: 'hybrid'
});

await trix.memories.update('mem_xyz789', {
  topics: ['web development', 'best practices']
});

Quality Scores & Enrichment

Assess memory quality and enrich memories with additional metadata, summaries, and extracted information.

Quality Scores

quality.ts
const score = await trix.memories.getQualityScore('mem_xyz789');
console.log('Quality score:', score.toFixed(2));

const highQuality = await trix.memories.list({
  minQuality: 0.7,
  limit: 50
});

const lowQuality = await trix.memories.list({
  maxQuality: 0.4,
  limit: 20
});
for (const m of lowQuality.data) {
  console.log(`Needs review: ${m.content.slice(0, 50)}...`);
}

Memory Enrichment

enrichment.ts
const result = await trix.memories.enrich('mem_xyz789', {
  operations: ['topics', 'summary', 'entities']
});

console.log('Summary:', result.summary);
console.log('Topics:', result.topics);
console.log('Entities:', result.entities);

const enriched = await trix.memories.create({
  content: 'Long document content here...',
  autoEnrich: true,
  enrichmentOperations: ['summary', 'topics', 'entities']
});

Enrichment Operations

OperationDescription
'topics'Extract topic labels from content
'summary'Generate a concise summary
'entities'Extract named entities (people, places, organizations)
'keyPoints'Extract key points and takeaways
'sentiment'Analyze sentiment and tone
'keywords'Extract important keywords

Multi-scale Clusters

Access memory clusters at different granularity levels to understand how memories are organized and find related content.

clusters.ts
const fineClusters = await trix.clusters.list({ scale: 'fine' });
const mediumClusters = await trix.clusters.list({ scale: 'medium' });
const coarseClusters = await trix.clusters.list({ scale: 'coarse' });

console.log('Fine clusters:', fineClusters.data.length);

for (const cluster of fineClusters.data.slice(0, 5)) {
  console.log(`Cluster: ${cluster.label}`);
  console.log(`  Memories: ${cluster.memoryCount}`);
  console.log(`  Topics: ${cluster.topics.join(', ')}`);
}

const results = await trix.search.query('artificial intelligence', {
  clusterScale: 'coarse'
});

const clusterMemories = await trix.clusters.getMemories('cluster_abc123', {
  limit: 50
});

const allClusters = await trix.clusters.list();
console.log('Total clusters:', allClusters.length);

Cluster Scales

ScaleDescriptionTypical Use
'fine'Many small, tightly related clustersFinding very similar memories
'medium'Balanced clusteringGeneral organization (default)
'coarse'Few large, broadly related clustersHigh-level categorization

Advanced List & Create Options

The list and create methods support additional parameters for fine-grained control over memory management.

Advanced List Options

advanced-list.ts
const memories = await trix.memories.list({
  q: 'search query',
  mode: 'hybrid',
  tags: ['important'],
  spaceId: 'space_abc123',
  pinned: true,
  minQuality: 0.7,
  maxQuality: 1.0,
  protectionLevel: 'soft',
  includeDeleted: false,
  topics: ['machine learning'],
  createdAfter: '2024-01-01',
  createdBefore: '2024-12-31',
  sortBy: 'quality',
  sortOrder: 'desc',
  limit: 50,
  page: 1
});

for await (const memory of trix.memories.listAll({
  pinned: true,
  minQuality: 0.8
})) {
  console.log(`High-quality pinned: ${memory.content.slice(0, 50)}...`);
}

Advanced Create Options

advanced-create.ts
const memory = await trix.memories.create({
  content: 'Important business rule documentation',
  type: 'markdown',
  tags: ['rules', 'documentation'],
  metadata: {
    author: 'admin',
    department: 'engineering'
  },
  spaceId: 'space_abc123',
  priority: 9,
  isPinned: true,
  protectionLevel: 'soft',
  autoEnrich: true,
  enrichmentOperations: ['topics', 'summary'],
  topics: ['business rules'],
  expiresAt: '2025-12-31T23:59:59Z'
});

console.log('Created:', memory.id);
console.log('Pinned:', memory.isPinned);
console.log('Protection:', memory.protectionLevel);