Overview
The memories resource handles creating, reading, updating, and deleting memory objects. Memories are the core data type in Trix.
Create Memory
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
| Option | Type | Description |
|---|---|---|
content | string | Memory content (required) |
type | string | 'text', 'markdown', 'url', 'audio' |
tags | string[] | Tags for categorization |
metadata | object | Custom key-value metadata |
spaceId | string | Space to store memory in |
priority | number | Priority level (0-100) |
salience | number | Importance score (0-1) |
List and Search Memories
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
| Mode | Description | Best For |
|---|---|---|
semantic | Vector similarity search | Conceptual queries |
keyword | Traditional keyword search | Exact matches |
hybrid | Combined semantic and keyword | General purpose (recommended) |
Async Iteration
Stream through all memories without manual pagination:
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
const memory = await trix.memories.get('mem_xyz789');
console.log(memory.content);
console.log(memory.tags);
console.log(memory.metadata);Update Memory
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
await trix.memories.delete('mem_xyz789');Bulk Operations
Perform operations on multiple memories at once for better performance:
Bulk Create
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
await trix.memories.bulkUpdate([
{ id: 'mem_1', tags: ['reviewed'] },
{ id: 'mem_2', content: 'Updated content' }
]);Bulk Delete
await trix.memories.bulkDelete(['mem_1', 'mem_2', 'mem_3']);Search
The search resource provides semantic search and embedding operations.
Find Similar Memories
const results = await trix.search.similar('mem_xyz', {
limit: 10,
threshold: 0.6,
includeEmbedding: false,
spaceId: 'space_dev'
});
for (const { memory, similarity } of results.results) {
console.log(`${similarity.toFixed(2)}: ${memory.content.slice(0, 50)}...`);
}Generate Embeddings
const embeddings = await trix.search.embed(['mem_1', 'mem_2', 'mem_3']);
for (const { memoryId, embedding } of embeddings.embeddings) {
console.log(`${memoryId}: ${embedding.length} dimensions`);
}
const batch = await trix.search.embedAll(100);
console.log(`Processed ${batch.processed} of ${batch.total}`);Search Configuration
const config = await trix.search.getConfig();
console.log('Embedding model:', config.embeddingModel);
console.log('Dimensions:', config.embeddingDimensions);
console.log('Max batch size:', config.maxBatchSize);Audio Memories
Store and transcribe audio files:
Create Audio Memory
const audioMemory = await trix.memories.create({
content: 'Meeting recording - Q4 planning',
type: 'audio',
audioFile: audioBlob,
tags: ['meeting', 'q4']
});Stream Audio
const stream = await trix.memories.streamAudio('mem_audio123');Transcription
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.
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.
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.
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.
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
| Level | Description | Use Case |
|---|---|---|
'none' | No protection, can be freely modified or deleted | Regular memories |
'soft' | Deletion requires explicit confirmation | Important but occasionally updated data |
'hard' | Cannot be deleted without first removing protection | Critical 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.
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.
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
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
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
| Operation | Description |
|---|---|
'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.
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
| Scale | Description | Typical Use |
|---|---|---|
'fine' | Many small, tightly related clusters | Finding very similar memories |
'medium' | Balanced clustering | General organization (default) |
'coarse' | Few large, broadly related clusters | High-level categorization |
Advanced List & Create Options
The list and create methods support additional parameters for fine-grained control over memory management.
Advanced List Options
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
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);