memo-grafter 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +4 -3
- package/README.md +24 -111
- package/USER_GUIDE.md +715 -702
- package/dist/adapters/AnthropicAdapter.d.ts +9 -0
- package/dist/adapters/AnthropicAdapter.d.ts.map +1 -0
- package/dist/adapters/AnthropicAdapter.js +27 -0
- package/dist/adapters/AnthropicAdapter.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/pipeline/GrafterPipeline.d.ts +0 -1
- package/dist/pipeline/GrafterPipeline.d.ts.map +1 -1
- package/dist/pipeline/GrafterPipeline.js +3 -14
- package/dist/pipeline/GrafterPipeline.js.map +1 -1
- package/dist/pipeline/SegmentProcessor.d.ts.map +1 -1
- package/dist/pipeline/SegmentProcessor.js +2 -22
- package/dist/pipeline/SegmentProcessor.js.map +1 -1
- package/dist/prompts/memoryInjectionPrompt.d.ts +4 -0
- package/dist/prompts/memoryInjectionPrompt.d.ts.map +1 -0
- package/dist/prompts/memoryInjectionPrompt.js +16 -0
- package/dist/prompts/memoryInjectionPrompt.js.map +1 -0
- package/dist/prompts/segmentExtractionPrompt.d.ts +3 -0
- package/dist/prompts/segmentExtractionPrompt.d.ts.map +1 -0
- package/dist/prompts/segmentExtractionPrompt.js +25 -0
- package/dist/prompts/segmentExtractionPrompt.js.map +1 -0
- package/package.json +76 -55
package/.env.example
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
DATABASE_URL=postgres://postgres:postgres@localhost:5432/memograffer
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
DATABASE_URL=postgres://postgres:postgres@localhost:5432/memograffer
|
|
2
|
+
ANTHROPIC_API_KEY=
|
|
3
|
+
OPENAI_API_KEY=
|
|
4
|
+
REDIS_URL=redis://localhost:6379
|
package/README.md
CHANGED
|
@@ -1,73 +1,49 @@
|
|
|
1
1
|
# MemoGrafter
|
|
2
|
+
[](https://www.npmjs.com/package/memo-grafter)
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
Structured memory for TypeScript chatbots.
|
|
4
5
|
|
|
5
|
-
MemoGrafter
|
|
6
|
+
MemoGrafter helps chatbot applications remember conversations without stuffing every old message back into the prompt. It turns conversations into topic-based memory, retrieves the relevant parts later, and can copy useful memory from one chatbot or session into another.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
It is a memory framework, not an autonomous agent runtime. It does not run tools, schedule tasks, or decide goals for an agent.
|
|
8
9
|
|
|
9
|
-
##
|
|
10
|
+
## What You Can Build
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
- connect related nodes in a graph
|
|
17
|
-
- inject only relevant memory into later calls
|
|
18
|
-
- graft selected memory into another chatbot/session
|
|
19
|
-
|
|
20
|
-
The project is early-stage and experimental, but it is useful for demos, prototypes, and exploring memory workflows beyond plain chat history.
|
|
12
|
+
- Chatbots that remember user preferences across long conversations.
|
|
13
|
+
- Support or tutoring assistants that recall prior topics without replaying full history.
|
|
14
|
+
- Multi-chatbot demos where one bot can absorb selected memory from another.
|
|
15
|
+
- Prototypes for graph-based conversational memory, retrieval, and memory transfer.
|
|
16
|
+
- Server-side TypeScript apps that need reusable LLM memory primitives.
|
|
21
17
|
|
|
22
18
|
## How It Works
|
|
23
19
|
|
|
20
|
+
At a high level:
|
|
21
|
+
|
|
24
22
|
```text
|
|
25
23
|
chat messages
|
|
26
24
|
-> topic segments
|
|
27
|
-
->
|
|
28
|
-
-> graph
|
|
29
|
-
-> memory injection
|
|
30
|
-
->
|
|
25
|
+
-> memory nodes
|
|
26
|
+
-> graph links
|
|
27
|
+
-> relevant memory injection
|
|
28
|
+
-> optional memory grafting
|
|
31
29
|
```
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
MemoGrafter stores conversation turns, detects topic shifts, summarizes segments into memory nodes, links related nodes, and injects relevant memory into future LLM calls. Memory grafting lets one chatbot or session copy selected memory from another.
|
|
34
32
|
|
|
35
|
-
##
|
|
33
|
+
## Install
|
|
36
34
|
|
|
37
35
|
```bash
|
|
38
36
|
npm install memo-grafter
|
|
39
37
|
```
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
git clone <repo-url> project-memoGrafter
|
|
45
|
-
cd project-memoGrafter
|
|
46
|
-
npm install
|
|
47
|
-
npm run build
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
Then install it from a local app:
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
npm install D:/cohort/projects/project-memoGrafter
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## Environment
|
|
39
|
+
MemoGrafter runs server-side on Node.js and requires PostgreSQL with `pgvector`. The included OpenAI adapters also require `OPENAI_API_KEY`.
|
|
57
40
|
|
|
58
41
|
```bash
|
|
59
42
|
DATABASE_URL=postgres://postgres:postgres@localhost:5432/memo_grafter
|
|
60
43
|
OPENAI_API_KEY=sk-...
|
|
61
|
-
REDIS_URL=redis://localhost:6379
|
|
62
44
|
```
|
|
63
45
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
`OPENAI_API_KEY` is only needed when using the included OpenAI adapters.
|
|
67
|
-
|
|
68
|
-
`REDIS_URL` is optional and only needed for queue mode.
|
|
69
|
-
|
|
70
|
-
## Minimal Usage
|
|
46
|
+
## Minimal Example
|
|
71
47
|
|
|
72
48
|
```ts
|
|
73
49
|
import "dotenv/config";
|
|
@@ -79,9 +55,7 @@ import {
|
|
|
79
55
|
} from "memo-grafter";
|
|
80
56
|
|
|
81
57
|
const agent = new MemoGrafterAgent({
|
|
82
|
-
db: {
|
|
83
|
-
connectionString: process.env.DATABASE_URL!,
|
|
84
|
-
},
|
|
58
|
+
db: { connectionString: process.env.DATABASE_URL! },
|
|
85
59
|
llm: new OpenAILLMAdapter("gpt-4o"),
|
|
86
60
|
embedder: new OpenAIEmbedAdapter("text-embedding-3-small"),
|
|
87
61
|
});
|
|
@@ -90,86 +64,25 @@ await agent.initialize();
|
|
|
90
64
|
|
|
91
65
|
console.log(await agent.invoke("I am planning a Japan trip."));
|
|
92
66
|
console.log(await agent.invoke("I like quiet towns, bookstores, and local cafes."));
|
|
93
|
-
|
|
94
|
-
const nodes = await agent.getActiveNodes();
|
|
95
|
-
console.log(nodes.map((node) => ({ label: node.label, summary: node.summary })));
|
|
67
|
+
console.log(await agent.invoke("What do you remember about my travel preferences?"));
|
|
96
68
|
|
|
97
69
|
await agent.close();
|
|
98
70
|
```
|
|
99
71
|
|
|
100
|
-
Run with:
|
|
101
|
-
|
|
102
|
-
```bash
|
|
103
|
-
npx tsx --env-file=.env src/index.ts
|
|
104
|
-
```
|
|
105
|
-
|
|
106
72
|
## Memory Grafting
|
|
107
73
|
|
|
108
|
-
Memory grafting
|
|
74
|
+
Memory grafting is the core idea behind the name: one chatbot can build memory, and another chatbot can absorb only the useful parts.
|
|
109
75
|
|
|
110
76
|
```ts
|
|
111
|
-
const travelBot = new MemoGrafterAgent(config);
|
|
112
|
-
const writingBot = new MemoGrafterAgent(config);
|
|
113
|
-
|
|
114
|
-
await travelBot.initialize();
|
|
115
|
-
await writingBot.initialize();
|
|
116
|
-
|
|
117
|
-
await travelBot.invoke("I am planning a Japan trip.");
|
|
118
|
-
await travelBot.invoke("I like quiet towns, bookstores, and local cafes.");
|
|
119
|
-
await travelBot.invoke("My budget is around 2500 dollars.");
|
|
120
|
-
|
|
121
77
|
await writingBot.absorbFromAgent(travelBot, {
|
|
122
78
|
prompt: "Japan travel preferences",
|
|
123
|
-
minSimilarity: 0.6,
|
|
124
79
|
limit: 3,
|
|
125
80
|
});
|
|
126
|
-
|
|
127
|
-
const intro = await writingBot.invoke(
|
|
128
|
-
"Suggest a reflective blog intro for my Japan trip."
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
console.log(intro);
|
|
132
|
-
|
|
133
|
-
await travelBot.close();
|
|
134
|
-
await writingBot.close();
|
|
135
81
|
```
|
|
136
82
|
|
|
137
|
-
You can also preview a graft before copying it:
|
|
138
|
-
|
|
139
|
-
```ts
|
|
140
|
-
const graft = await travelBot.graft();
|
|
141
|
-
|
|
142
|
-
console.log(graft.systemPrompt);
|
|
143
|
-
console.log(graft.nodes);
|
|
144
|
-
console.log(graft.tokenCount);
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
## Key Features
|
|
148
|
-
|
|
149
|
-
- Structured chatbot memory over PostgreSQL and pgvector.
|
|
150
|
-
- Topic drift detection for splitting conversations into segments.
|
|
151
|
-
- Topic nodes with summaries, embeddings, message ranges, and graph edges.
|
|
152
|
-
- Automatic memory injection during chatbot calls.
|
|
153
|
-
- Selective memory grafting by topic ID or semantic prompt.
|
|
154
|
-
- Optional BullMQ/Redis queue mode for background ingestion.
|
|
155
|
-
- OpenAI adapters included.
|
|
156
|
-
- Custom LLM and embedding adapters supported.
|
|
157
|
-
- Minimal fleet API for color-scoped worker chatbots and conductor grafting.
|
|
158
|
-
|
|
159
|
-
## Requirements
|
|
160
|
-
|
|
161
|
-
- Node.js 18 or newer.
|
|
162
|
-
- Server-side Node.js runtime.
|
|
163
|
-
- PostgreSQL with `pgvector`.
|
|
164
|
-
- An LLM adapter and embedding adapter.
|
|
165
|
-
- OpenAI API key if using `OpenAILLMAdapter` or `OpenAIEmbedAdapter`.
|
|
166
|
-
- Redis only if using queue mode.
|
|
167
|
-
|
|
168
|
-
MemoGrafter does not run in browser code.
|
|
169
|
-
|
|
170
83
|
## Learn More
|
|
171
84
|
|
|
172
|
-
Read
|
|
85
|
+
Read [USER_GUIDE.md](https://github.com/mayhemking007/memo-grafter/blob/main/USER_GUIDE.md) for setup, configuration, queue mode, custom adapters, fleet APIs, examples, and troubleshooting.
|
|
173
86
|
|
|
174
87
|
This repository also includes a runnable demo:
|
|
175
88
|
|