-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmemory.text.add.ts
More file actions
74 lines (64 loc) · 2.44 KB
/
memory.text.add.ts
File metadata and controls
74 lines (64 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import {Langbase} from 'langbase';
/**
* 1. Run memory.create.ts file to create a memory first.
* 2. Add your API key to the environment variables or replace it in the code.
*/
const langbase = new Langbase({
apiKey: process.env.LANGBASE_API_KEY!,
});
async function main() {
// Basic text addition
const basicResult = await langbase.memories.add({
memoryName: 'my-knowledge-base',
text: 'This is important information about machine learning fundamentals. It covers supervised learning, unsupervised learning, and reinforcement learning concepts.',
});
console.log('✅ Basic text added:', basicResult);
// Text addition with custom name and metadata
const detailedResult = await langbase.memories.add({
memoryName: 'my-knowledge-base',
text: 'Deep learning is a subset of machine learning that uses artificial neural networks with multiple layers to model and understand complex patterns in data. It has revolutionized fields like computer vision, natural language processing, and speech recognition.',
documentName: 'deep-learning-intro',
metadata: {
category: 'machine-learning',
topic: 'deep-learning',
difficulty: 'intermediate',
source: 'manual-entry',
},
});
console.log('✅ Detailed text added:', detailedResult);
// Multiple text entries
const texts = [
{
text: 'Supervised learning uses labeled training data to learn a mapping from inputs to outputs.',
documentName: 'supervised-learning',
metadata: { type: 'definition', category: 'ml-concepts' },
},
{
text: 'Unsupervised learning finds hidden patterns in data without using labeled examples.',
documentName: 'unsupervised-learning',
metadata: { type: 'definition', category: 'ml-concepts' },
},
{
text: 'Reinforcement learning learns optimal actions through trial and error interactions with an environment.',
documentName: 'reinforcement-learning',
metadata: { type: 'definition', category: 'ml-concepts' },
},
];
console.log('\n📝 Adding multiple texts...');
for (const item of texts) {
const result = await langbase.memories.add({
memoryName: 'my-knowledge-base',
...item,
});
console.log(`✅ Added: ${result.documentName}`);
}
console.log('\n🎉 All texts have been added to the memory!');
console.log('You can now query this memory to retrieve relevant information.');
}
main()
.then(() => {
console.log('\n✨ Text addition completed successfully');
})
.catch(error => {
console.error('❌ Error:', error);
});