@pyxmate/memory 0.0.5-beta → 0.1.1-beta
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/README.md +10 -0
- package/bin/init.mjs +63 -0
- package/dist/{chunk-Q4QIILKH.mjs → chunk-JMXAZPDT.mjs} +39 -11
- package/dist/{chunk-EDIYGMT2.mjs → chunk-XNKO7F3P.mjs} +1 -1
- package/dist/dashboard.mjs +2 -2
- package/dist/index.d.ts +85 -40
- package/dist/index.mjs +10 -4
- package/dist/react.mjs +2 -2
- package/package.json +9 -3
- package/skills/pyx-memory-integration/SKILL.md +266 -0
- package/skills/pyx-memory-integration/examples/disabled-memory.ts +53 -0
- package/skills/pyx-memory-integration/examples/minimal-embedded.ts +25 -0
- package/skills/pyx-memory-integration/examples/minimal-sidecar.ts +14 -0
- package/skills/pyx-memory-integration/patterns/consumer.md +103 -0
- package/skills/pyx-memory-integration/patterns/embedded.md +223 -0
- package/skills/pyx-memory-integration/reference/advanced.md +139 -0
- package/skills/pyx-memory-integration/reference/http-api.md +82 -0
- package/skills/pyx-memory-integration/reference/parity.md +63 -0
- package/skills/pyx-memory-integration/reference/types.md +203 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pyx-memory-integration
|
|
3
|
+
description: >
|
|
4
|
+
Integration guide for the pyx-memory universal memory system (TypeScript/Bun).
|
|
5
|
+
Use when integrating pyx-memory into a project, migrating to pyx-memory,
|
|
6
|
+
setting up embedded or sidecar memory, asking about pyx-memory API or types,
|
|
7
|
+
configuring RAG strategies, file ingestion, or lifecycle management.
|
|
8
|
+
Triggers on: 'integrate pyx-memory', 'add memory system', 'setup pyx-memory',
|
|
9
|
+
'memory store search', 'MemoryInterface', 'EmbeddingProvider', 'createMemory',
|
|
10
|
+
'pyx-memory configuration', 'memory consolidation', 'graph RAG'.
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# pyx-memory — AI Agent Integration Guide
|
|
14
|
+
|
|
15
|
+
Reference for AI agents integrating pyx-memory into TypeScript/Bun projects.
|
|
16
|
+
Runtime requirement: **Bun v1.2+** (not Node.js). Uses `bun:sqlite` natively.
|
|
17
|
+
|
|
18
|
+
> After integration work, run the diagnostic tool to verify correctness:
|
|
19
|
+
> ```bash
|
|
20
|
+
> bun .claude/skills/pyx-memory-integration/scripts/diagnose-integration.ts --json
|
|
21
|
+
> ```
|
|
22
|
+
> Parse the `verdict` field: `"healthy"` = done, otherwise fix each `criticalIssues` entry and re-run.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## What are you trying to do?
|
|
27
|
+
|
|
28
|
+
**Integrate pyx-memory into a consumer project?**
|
|
29
|
+
→ See [patterns/consumer.md](patterns/consumer.md)
|
|
30
|
+
|
|
31
|
+
**Set up embedded memory with full features?**
|
|
32
|
+
→ See [patterns/embedded.md](patterns/embedded.md)
|
|
33
|
+
|
|
34
|
+
**Understand type signatures and interfaces?**
|
|
35
|
+
→ See [reference/types.md](reference/types.md)
|
|
36
|
+
|
|
37
|
+
**Check sidecar limitations before choosing a mode?**
|
|
38
|
+
→ See [reference/parity.md](reference/parity.md)
|
|
39
|
+
|
|
40
|
+
**Use the HTTP API directly?**
|
|
41
|
+
→ See [reference/http-api.md](reference/http-api.md)
|
|
42
|
+
|
|
43
|
+
**Configure RAG, bi-temporal queries, or consolidation?**
|
|
44
|
+
→ See [reference/advanced.md](reference/advanced.md)
|
|
45
|
+
|
|
46
|
+
**Validate your integration setup?**
|
|
47
|
+
→ Run: `bun .claude/skills/pyx-memory-integration/scripts/diagnose-integration.ts`
|
|
48
|
+
|
|
49
|
+
**Check server connectivity?**
|
|
50
|
+
→ Run: `bun .claude/skills/pyx-memory-integration/scripts/diagnose-integration.ts --phase=runtime`
|
|
51
|
+
|
|
52
|
+
**Get machine-readable diagnostic report?**
|
|
53
|
+
→ Run: `bun .claude/skills/pyx-memory-integration/scripts/diagnose-integration.ts --json`
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Quick Decision Tree
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
Building pyx-memory itself or its server?
|
|
61
|
+
→ Embedded mode: import { Memory } from '@pyx-memory/core'
|
|
62
|
+
|
|
63
|
+
Consuming pyx-memory from another project (e.g., agent-forge)?
|
|
64
|
+
→ Sidecar mode: import { MemoryClient } from '@pyx-memory/client'
|
|
65
|
+
→ ONLY depend on @pyx-memory/client + @pyx-memory/shared
|
|
66
|
+
→ Do NOT import @pyx-memory/core — that's pyx-memory's internal implementation
|
|
67
|
+
→ See patterns/consumer.md
|
|
68
|
+
|
|
69
|
+
Need memory in your process (best perf, full feature set)?
|
|
70
|
+
→ Embedded mode: import { Memory } from '@pyx-memory/core'
|
|
71
|
+
|
|
72
|
+
Need memory as a separate service (HTTP)?
|
|
73
|
+
→ Sidecar mode: import { MemoryClient } from '@pyx-memory/client'
|
|
74
|
+
|
|
75
|
+
Need to switch modes via config?
|
|
76
|
+
→ Factory: import { createMemory } from '@pyx-memory/core'
|
|
77
|
+
- Returns MemoryInterface (base interface — no lifecycle methods)
|
|
78
|
+
- If you need consolidate/decay/summarize, use `new Memory()` directly
|
|
79
|
+
|
|
80
|
+
Need lifecycle methods (consolidate, decay, summarize)?
|
|
81
|
+
→ Use `new Memory(opts)` — returns ExtendedMemoryInterface
|
|
82
|
+
→ Or `new MemoryClient(url)` — also implements ExtendedMemoryInterface
|
|
83
|
+
→ NOT createMemory() — it returns MemoryInterface (missing lifecycle methods)
|
|
84
|
+
|
|
85
|
+
Need dashboard features (consolidation log, graph visualization)?
|
|
86
|
+
→ Use `DashboardClient` from '@pyx-memory/dashboard'
|
|
87
|
+
→ Extends MemoryClient with additional methods
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Minimal Working Example (Embedded)
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { Memory } from '@pyx-memory/core';
|
|
96
|
+
|
|
97
|
+
// Embedding is internal — pyx-memory uses BGE-M3 (1024d) automatically
|
|
98
|
+
const memory = new Memory({ dataDir: './data' });
|
|
99
|
+
await memory.initialize(); // REQUIRED — throws if you skip this
|
|
100
|
+
|
|
101
|
+
// Store (default targets: sqlite + vector)
|
|
102
|
+
await memory.store({
|
|
103
|
+
content: 'User prefers dark mode',
|
|
104
|
+
type: 'long-term',
|
|
105
|
+
metadata: { source: 'settings' },
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Store with graph routing (agent provides entities)
|
|
109
|
+
await memory.store({
|
|
110
|
+
content: 'Alice works at Acme Corp',
|
|
111
|
+
type: 'long-term',
|
|
112
|
+
metadata: {},
|
|
113
|
+
targets: ['sqlite', 'vector', 'graph'],
|
|
114
|
+
entities: [
|
|
115
|
+
{ name: 'Alice', type: 'PERSON' },
|
|
116
|
+
{ name: 'Acme Corp', type: 'ORGANIZATION' },
|
|
117
|
+
],
|
|
118
|
+
relationships: [{ source: 'Alice', target: 'Acme Corp', type: 'WORKS_AT' }],
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Search
|
|
122
|
+
const results = await memory.search({ query: 'user preferences', limit: 5 });
|
|
123
|
+
|
|
124
|
+
// Cleanup
|
|
125
|
+
await memory.shutdown(); // REQUIRED — releases SQLite + LanceDB resources
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Minimal Working Example (Sidecar / HTTP)
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
import { MemoryClient } from '@pyx-memory/client';
|
|
132
|
+
|
|
133
|
+
// Without auth (local dev)
|
|
134
|
+
const memory = new MemoryClient('http://localhost:7822');
|
|
135
|
+
|
|
136
|
+
// With auth (production — pass API key as second argument)
|
|
137
|
+
const authedMemory = new MemoryClient('http://localhost:7822', process.env.MEMORY_API_KEY);
|
|
138
|
+
|
|
139
|
+
await memory.initialize(); // verifies server connectivity via /health
|
|
140
|
+
|
|
141
|
+
await memory.store({ content: 'Important fact', type: 'long-term', metadata: {} });
|
|
142
|
+
const results = await memory.search({ query: 'fact', limit: 5 });
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Start the server: `bun packages/server/src/index.ts`
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Package Map
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
@pyx-memory/shared → Types + constants only (zero runtime code)
|
|
153
|
+
↑ ↑
|
|
154
|
+
| |
|
|
155
|
+
@pyx-memory/client → MemoryInterface, ExtendedMemoryInterface, MemoryClient
|
|
156
|
+
↑
|
|
157
|
+
|
|
|
158
|
+
@pyx-memory/core → Memory class, embeddings, graph, RAG, ingestion, lifecycle
|
|
159
|
+
↑ (re-exports everything from client and shared)
|
|
160
|
+
|
|
|
161
|
+
@pyx-memory/server → HTTP sidecar server (23 endpoints)
|
|
162
|
+
|
|
163
|
+
@pyx-memory/dashboard → DashboardClient (extends MemoryClient), React hooks,
|
|
164
|
+
Poller, aggregations, graph transforms (D3/Graphology)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**Import rules:**
|
|
168
|
+
- **Embedded mode**: Import everything from `@pyx-memory/core` (it re-exports client + shared)
|
|
169
|
+
- **Sidecar mode (client only)**: Import from `@pyx-memory/client` (+ types from `@pyx-memory/shared`)
|
|
170
|
+
- **Dashboard features**: Import from `@pyx-memory/dashboard` (extends client with extra methods)
|
|
171
|
+
- **Types only**: Import from `@pyx-memory/shared`
|
|
172
|
+
- **Consumer projects**: ONLY use `@pyx-memory/client` + `@pyx-memory/shared` — never `@pyx-memory/core`
|
|
173
|
+
|
|
174
|
+
For full type definitions and interfaces, see [reference/types.md](reference/types.md).
|
|
175
|
+
|
|
176
|
+
For HTTP API endpoint reference, see [reference/http-api.md](reference/http-api.md).
|
|
177
|
+
|
|
178
|
+
For feature parity between embedded and sidecar modes, see [reference/parity.md](reference/parity.md).
|
|
179
|
+
|
|
180
|
+
For RAG strategies, bi-temporal model, consolidation, and community detection, see [reference/advanced.md](reference/advanced.md).
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## DO / DON'T
|
|
185
|
+
|
|
186
|
+
### DO
|
|
187
|
+
|
|
188
|
+
- **DO** call `await memory.initialize()` before any operation
|
|
189
|
+
- **DO** call `await memory.shutdown()` when done (releases SQLite + LanceDB)
|
|
190
|
+
- **DO** provide `entities` when using `targets: ['graph']` — graph storage requires agent-provided entities
|
|
191
|
+
- **DO** initialize GraphStore BEFORE constructing Memory
|
|
192
|
+
- **DO** use `new Memory()` when you need lifecycle methods (ExtendedMemoryInterface)
|
|
193
|
+
- **DO** use `':memory:'` dataDir for tests
|
|
194
|
+
- **DO** handle `MemoryServerError` in sidecar mode (has `.status` and `.isNotFound`)
|
|
195
|
+
- **DO** use `MemoryClient` (not `MemoryInterface`) when you need graph or file ingestion — these are concrete methods
|
|
196
|
+
- **DO** use `DashboardClient` when you need consolidation logs, graph relationships, or enriched health data
|
|
197
|
+
- **DO** implement `DisabledMemory` (no-op) in consumer projects for graceful degradation when memory is unavailable
|
|
198
|
+
|
|
199
|
+
### DON'T
|
|
200
|
+
|
|
201
|
+
- **DON'T** assume `createMemory()` returns `ExtendedMemoryInterface` — it returns `MemoryInterface`
|
|
202
|
+
- **DON'T** use `targets: ['graph']` without entities — throws MemoryError
|
|
203
|
+
- **DON'T** use `targets: ['graph']` without a configured `graphStore` — throws MemoryError
|
|
204
|
+
- **DON'T** use `strategy: 'graph'` without passing `graphStore` — throws "RAG strategy not registered"
|
|
205
|
+
- **DON'T** use `strategy: 'agentic'` without passing `reasoningProvider`
|
|
206
|
+
- **DON'T** construct multiple Memory instances with the same `dataDir` — LanceDB singleton causes conflicts
|
|
207
|
+
- **DON'T** use `':memory:'` in production — LanceDB still writes to `/tmp/autonomy-vectors`
|
|
208
|
+
- **DON'T** expose the server without configuring `API_KEY` for network deployments — use an API gateway for internet-facing deployments
|
|
209
|
+
- **DON'T** import `@pyx-memory/core` in consumer projects — use `@pyx-memory/client` for clean separation
|
|
210
|
+
- **DON'T** expect `filters`, `enableHyDE`, or `enableRerank` to work in sidecar mode — the HTTP API doesn't forward them
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## AI Agent Post-Integration Checklist
|
|
215
|
+
|
|
216
|
+
After integrating pyx-memory, run the diagnostic tool to verify everything is wired correctly:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
bun .claude/skills/pyx-memory-integration/scripts/diagnose-integration.ts --json
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Interpret the result:**
|
|
223
|
+
1. Parse the JSON `verdict` field:
|
|
224
|
+
- `"healthy"` → Integration is complete and working
|
|
225
|
+
- `"misconfigured"` → Environment or config issues — fix each item in `criticalIssues`
|
|
226
|
+
- `"broken"` → Server is down or unreachable — start the server first
|
|
227
|
+
- `"degraded"` → Working but with warnings (e.g., stub embeddings)
|
|
228
|
+
2. For each entry in `criticalIssues`, apply the `fix` instruction
|
|
229
|
+
3. Re-run until `verdict === "healthy"`
|
|
230
|
+
|
|
231
|
+
**Common failure: DisabledMemory (no-op)**
|
|
232
|
+
If `MEMORY_URL` is not set, the client will silently fall back to a DisabledMemory no-op implementation. Everything appears to work (store returns success, health reports "ok") but nothing is actually persisted. The diagnostic tool detects this via checks S5 (missing URL) and I1 (empty store ID).
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## Error Types
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
MemoryError (base)
|
|
240
|
+
├── MemoryStoreError — SQLite store failures
|
|
241
|
+
├── MemoryNotFoundError — entry not found
|
|
242
|
+
├── MemorySearchError — search failures
|
|
243
|
+
├── VectorProviderError — LanceDB/vector issues
|
|
244
|
+
├── EmbeddingError — embedding generation failures
|
|
245
|
+
├── MigrationError — schema migration issues
|
|
246
|
+
├── IngestionError — file parsing / ingestion failures
|
|
247
|
+
├── LifecycleError — consolidation / decay failures
|
|
248
|
+
└── GraphError — graph store operations
|
|
249
|
+
|
|
250
|
+
MemoryServerError — HTTP client errors (has .status, .isNotFound)
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
All from `@pyx-memory/core` except `MemoryServerError` from `@pyx-memory/client`.
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Copy-Paste Examples
|
|
258
|
+
|
|
259
|
+
- [examples/minimal-embedded.ts](examples/minimal-embedded.ts) — Embedded setup with store/search/shutdown
|
|
260
|
+
- [examples/minimal-sidecar.ts](examples/minimal-sidecar.ts) — Sidecar HTTP client setup
|
|
261
|
+
- [examples/disabled-memory.ts](examples/disabled-memory.ts) — No-op DisabledMemory class for graceful degradation
|
|
262
|
+
|
|
263
|
+
## Further Reading
|
|
264
|
+
|
|
265
|
+
- `docs/ARCHITECTURE.md` — Deep architecture reference, research sources, cost analysis, competitive positioning
|
|
266
|
+
- `README.md` — Project overview, HTTP API examples, deployment guides, Docker setup
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { MemoryInterface, MemoryListResult } from '@pyx-memory/client';
|
|
2
|
+
import type { MemoryEntry, MemorySearchResult, MemoryStats } from '@pyx-memory/shared';
|
|
3
|
+
|
|
4
|
+
export class DisabledMemory implements MemoryInterface {
|
|
5
|
+
async initialize(): Promise<void> {
|
|
6
|
+
console.warn('Memory service not configured — running without memory');
|
|
7
|
+
}
|
|
8
|
+
async store(
|
|
9
|
+
entry: Omit<MemoryEntry, 'id' | 'createdAt'> & { id?: string; createdAt?: string },
|
|
10
|
+
): Promise<MemoryEntry> {
|
|
11
|
+
return {
|
|
12
|
+
id: '',
|
|
13
|
+
content: entry.content,
|
|
14
|
+
type: entry.type,
|
|
15
|
+
metadata: {},
|
|
16
|
+
createdAt: new Date().toISOString(),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
async search(): Promise<MemorySearchResult> {
|
|
20
|
+
return { entries: [], totalCount: 0, strategy: 'naive' };
|
|
21
|
+
}
|
|
22
|
+
async list(): Promise<MemoryListResult> {
|
|
23
|
+
return { entries: [], totalCount: 0, page: 1, limit: 20 };
|
|
24
|
+
}
|
|
25
|
+
async get(): Promise<MemoryEntry | null> {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
async delete(): Promise<boolean> {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
async clearSession(): Promise<number> {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
async stats(): Promise<MemoryStats> {
|
|
35
|
+
return {
|
|
36
|
+
totalEntries: 0,
|
|
37
|
+
storageUsedBytes: 0,
|
|
38
|
+
vectorCount: 0,
|
|
39
|
+
recentAccessCount: 0,
|
|
40
|
+
connected: false,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async shutdown(): Promise<void> {}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Usage: pick the right implementation based on config
|
|
47
|
+
import { MemoryClient } from '@pyx-memory/client';
|
|
48
|
+
|
|
49
|
+
const memory: MemoryInterface = process.env.MEMORY_URL
|
|
50
|
+
? new MemoryClient(process.env.MEMORY_URL, process.env.MEMORY_API_KEY)
|
|
51
|
+
: new DisabledMemory();
|
|
52
|
+
|
|
53
|
+
await memory.initialize();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Memory } from '@pyx-memory/core';
|
|
2
|
+
|
|
3
|
+
const memory = new Memory({ dataDir: './data' });
|
|
4
|
+
await memory.initialize(); // REQUIRED — throws if you skip this
|
|
5
|
+
|
|
6
|
+
// Store (default targets: sqlite + vector)
|
|
7
|
+
await memory.store({
|
|
8
|
+
content: 'User prefers dark mode',
|
|
9
|
+
type: 'long-term',
|
|
10
|
+
metadata: { source: 'settings' },
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// Store with explicit targets (e.g., sqlite only)
|
|
14
|
+
await memory.store({
|
|
15
|
+
content: 'Temporary working note',
|
|
16
|
+
type: 'working',
|
|
17
|
+
metadata: {},
|
|
18
|
+
targets: ['sqlite'],
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Search
|
|
22
|
+
const _results = await memory.search({ query: 'user preferences', limit: 5 });
|
|
23
|
+
|
|
24
|
+
// Cleanup
|
|
25
|
+
await memory.shutdown(); // REQUIRED — releases SQLite + LanceDB resources
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MemoryClient } from '@pyx-memory/client';
|
|
2
|
+
|
|
3
|
+
// Without auth (local dev)
|
|
4
|
+
const memory = new MemoryClient('http://localhost:7822');
|
|
5
|
+
|
|
6
|
+
// With auth (production — pass API key as second argument)
|
|
7
|
+
// const memory = new MemoryClient('http://localhost:7822', process.env.MEMORY_API_KEY);
|
|
8
|
+
|
|
9
|
+
await memory.initialize(); // verifies server connectivity via /health
|
|
10
|
+
|
|
11
|
+
await memory.store({ content: 'Important fact', type: 'long-term', metadata: {} });
|
|
12
|
+
const _results = await memory.search({ query: 'fact', limit: 5 });
|
|
13
|
+
|
|
14
|
+
// Start the server: bun packages/server/src/index.ts
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Consumer Integration Patterns
|
|
2
|
+
|
|
3
|
+
For downstream projects that **consume** pyx-memory (e.g., agent-forge, custom AI agents).
|
|
4
|
+
|
|
5
|
+
**Rule: Only depend on `@pyx-memory/client` + `@pyx-memory/shared`. Never import `@pyx-memory/core`.**
|
|
6
|
+
|
|
7
|
+
`@pyx-memory/core` is pyx-memory's internal implementation (SQLiteStore, LanceDB, embedding providers,
|
|
8
|
+
RAG engines, graph stores). Importing it creates tight coupling — any internal change can break your project.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Pattern 8: Consumer (Sidecar-Only)
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import { MemoryClient, MemoryServerError } from '@pyx-memory/client';
|
|
16
|
+
import type { MemoryInterface, ExtendedMemoryInterface } from '@pyx-memory/client';
|
|
17
|
+
import type { MemoryEntry, MemorySearchResult } from '@pyx-memory/shared';
|
|
18
|
+
|
|
19
|
+
const MEMORY_URL = process.env.MEMORY_URL; // e.g., 'http://localhost:7822'
|
|
20
|
+
|
|
21
|
+
let memory: MemoryClient | null = null;
|
|
22
|
+
|
|
23
|
+
if (MEMORY_URL) {
|
|
24
|
+
memory = new MemoryClient(MEMORY_URL, process.env.MEMORY_API_KEY);
|
|
25
|
+
await memory.initialize(); // verifies connectivity
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Use memory if available
|
|
29
|
+
if (memory) {
|
|
30
|
+
await memory.store({ content: 'fact', type: 'long-term', metadata: {} });
|
|
31
|
+
const results = await memory.search({ query: 'fact', limit: 5 });
|
|
32
|
+
|
|
33
|
+
// Graph queries — available on MemoryClient directly (no @pyx-memory/core needed)
|
|
34
|
+
const nodes = await memory.graphNodes();
|
|
35
|
+
const traversal = await memory.graphQuery({ nodeId: 'node-1', depth: 2 });
|
|
36
|
+
|
|
37
|
+
// File ingestion — also available on MemoryClient
|
|
38
|
+
const file = new File([buffer], 'report.pdf', { type: 'application/pdf' });
|
|
39
|
+
const result = await memory.ingestFile(file);
|
|
40
|
+
|
|
41
|
+
// Lifecycle
|
|
42
|
+
await memory.consolidate();
|
|
43
|
+
await memory.runDecay();
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Pattern 9: Graceful Degradation (DisabledMemory)
|
|
50
|
+
|
|
51
|
+
When your project should work with or without pyx-memory, implement a no-op wrapper.
|
|
52
|
+
See [examples/disabled-memory.ts](../examples/disabled-memory.ts) for a copy-paste ready implementation.
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { MemoryClient } from '@pyx-memory/client';
|
|
56
|
+
|
|
57
|
+
const memory: MemoryInterface = process.env.MEMORY_URL
|
|
58
|
+
? new MemoryClient(process.env.MEMORY_URL, process.env.MEMORY_API_KEY)
|
|
59
|
+
: new DisabledMemory();
|
|
60
|
+
|
|
61
|
+
await memory.initialize();
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Health Endpoint Pattern
|
|
67
|
+
|
|
68
|
+
Report memory status in your app's health check:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
// In your health route
|
|
72
|
+
const memoryStatus = process.env.MEMORY_URL
|
|
73
|
+
? { status: 'connected', url: process.env.MEMORY_URL }
|
|
74
|
+
: { status: 'disabled' };
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Adding as Sidecar (Docker)
|
|
80
|
+
|
|
81
|
+
```yaml
|
|
82
|
+
# docker-compose.yaml
|
|
83
|
+
services:
|
|
84
|
+
memory:
|
|
85
|
+
build:
|
|
86
|
+
context: ./vendor/pyx-memory
|
|
87
|
+
dockerfile: docker/Dockerfile
|
|
88
|
+
ports:
|
|
89
|
+
- "7822:7822"
|
|
90
|
+
volumes:
|
|
91
|
+
- memory-data:/data
|
|
92
|
+
environment:
|
|
93
|
+
- DATA_DIR=/data
|
|
94
|
+
# Embedding is internal (BGE-M3, 1024d) — no API keys needed
|
|
95
|
+
# - EMBEDDING_DIMENSIONS=1024 # optional override
|
|
96
|
+
|
|
97
|
+
your-app:
|
|
98
|
+
environment:
|
|
99
|
+
- MEMORY_URL=http://memory:7822
|
|
100
|
+
|
|
101
|
+
volumes:
|
|
102
|
+
memory-data:
|
|
103
|
+
```
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# Embedded Integration Patterns
|
|
2
|
+
|
|
3
|
+
For projects using pyx-memory directly in-process with full feature access.
|
|
4
|
+
|
|
5
|
+
## Contents
|
|
6
|
+
- [Pattern 1: Testing / Development](#pattern-1-testing--development)
|
|
7
|
+
- [Pattern 2: Production](#pattern-2-production)
|
|
8
|
+
- [Pattern 3: Production with Store Targets](#pattern-3-production-with-store-targets)
|
|
9
|
+
- [Pattern 4: With Knowledge Graph](#pattern-4-with-knowledge-graph)
|
|
10
|
+
- [Pattern 5: With LLM Lifecycle](#pattern-5-with-llm-lifecycle)
|
|
11
|
+
- [Pattern 6: File Ingestion](#pattern-6-file-ingestion)
|
|
12
|
+
- [Pattern 7: Factory with Auto-Mode Switching](#pattern-7-factory-with-auto-mode-switching)
|
|
13
|
+
- [Adding as Git Submodule](#adding-as-git-submodule-recommended-for-embedded-mode)
|
|
14
|
+
- [MemoryOptions Quick Reference](#memoryoptions-quick-reference)
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Pattern 1: Testing / Development
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { Memory } from '@pyx-memory/core';
|
|
22
|
+
|
|
23
|
+
const memory = new Memory({ dataDir: ':memory:' });
|
|
24
|
+
await memory.initialize();
|
|
25
|
+
// Memory internally creates a LocalEmbeddingProvider (BGE-M3, 1024d)
|
|
26
|
+
// No embedder needed — embedding is fully managed
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Pattern 2: Production
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { Memory } from '@pyx-memory/core';
|
|
33
|
+
|
|
34
|
+
const memory = new Memory({ dataDir: './data' });
|
|
35
|
+
await memory.initialize();
|
|
36
|
+
// Embedding is handled internally by LocalEmbeddingProvider (BGE-M3 via @huggingface/transformers, 1024d)
|
|
37
|
+
// No external embedding provider needed
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Pattern 3: Production with Store Targets
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { Memory } from '@pyx-memory/core';
|
|
44
|
+
|
|
45
|
+
const memory = new Memory({ dataDir: './data' });
|
|
46
|
+
await memory.initialize();
|
|
47
|
+
|
|
48
|
+
// Default: stores to sqlite + vector
|
|
49
|
+
await memory.store({
|
|
50
|
+
content: 'User prefers dark mode',
|
|
51
|
+
type: 'long-term',
|
|
52
|
+
metadata: { source: 'settings' },
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Explicit targets: sqlite only (skip vector indexing)
|
|
56
|
+
await memory.store({
|
|
57
|
+
content: 'Temporary note',
|
|
58
|
+
type: 'working',
|
|
59
|
+
metadata: {},
|
|
60
|
+
targets: ['sqlite'],
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Pattern 4: With Knowledge Graph
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { Memory, createGraphStore } from '@pyx-memory/core';
|
|
68
|
+
import type { StoreTarget, IngestEntity, IngestRelationship } from '@pyx-memory/shared';
|
|
69
|
+
|
|
70
|
+
// 1. Create and initialize graph store BEFORE Memory
|
|
71
|
+
const graphStore = createGraphStore({}); // returns SQLiteGraphStore (default)
|
|
72
|
+
await graphStore.initialize({}); // REQUIRED — Memory does NOT init this for you
|
|
73
|
+
|
|
74
|
+
// For Neo4j instead: createGraphStore({ neo4jUrl: 'bolt://localhost:7687' })
|
|
75
|
+
|
|
76
|
+
const memory = new Memory({
|
|
77
|
+
dataDir: './data',
|
|
78
|
+
graphStore, // enables graph RAG search
|
|
79
|
+
});
|
|
80
|
+
await memory.initialize();
|
|
81
|
+
|
|
82
|
+
// Graph storage is agent-driven — YOU provide entities and relationships explicitly
|
|
83
|
+
await memory.store({
|
|
84
|
+
content: 'Alice works at Acme Corp as a senior engineer',
|
|
85
|
+
type: 'long-term',
|
|
86
|
+
metadata: {},
|
|
87
|
+
targets: ['sqlite', 'vector', 'graph'],
|
|
88
|
+
entities: [
|
|
89
|
+
{ name: 'Alice', type: 'PERSON', properties: { role: 'senior engineer' } },
|
|
90
|
+
{ name: 'Acme Corp', type: 'ORGANIZATION' },
|
|
91
|
+
],
|
|
92
|
+
relationships: [
|
|
93
|
+
{ source: 'Alice', target: 'Acme Corp', type: 'WORKS_AT' },
|
|
94
|
+
],
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Graph-aware search
|
|
98
|
+
const results = await memory.search({ query: 'Alice employer', strategy: 'graph' });
|
|
99
|
+
|
|
100
|
+
// Cleanup both
|
|
101
|
+
await memory.shutdown();
|
|
102
|
+
await graphStore.shutdown();
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Pattern 5: With LLM Lifecycle
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { Memory } from '@pyx-memory/core';
|
|
109
|
+
import type { LLMCallback } from '@pyx-memory/core';
|
|
110
|
+
|
|
111
|
+
// LLMCallback: any function that takes a prompt string and returns a completion string
|
|
112
|
+
const llm: LLMCallback = async (prompt) => {
|
|
113
|
+
const res = await fetch('https://api.anthropic.com/v1/messages', {
|
|
114
|
+
method: 'POST',
|
|
115
|
+
headers: {
|
|
116
|
+
'x-api-key': process.env.ANTHROPIC_API_KEY!,
|
|
117
|
+
'content-type': 'application/json',
|
|
118
|
+
'anthropic-version': '2023-06-01',
|
|
119
|
+
},
|
|
120
|
+
body: JSON.stringify({
|
|
121
|
+
model: 'claude-sonnet-4-20250514',
|
|
122
|
+
max_tokens: 1024,
|
|
123
|
+
messages: [{ role: 'user', content: prompt }],
|
|
124
|
+
}),
|
|
125
|
+
});
|
|
126
|
+
const data = await res.json() as any;
|
|
127
|
+
return data.content[0].text;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const memory = new Memory({
|
|
131
|
+
dataDir: './data',
|
|
132
|
+
llm, // enables LLM-powered lifecycle
|
|
133
|
+
});
|
|
134
|
+
await memory.initialize();
|
|
135
|
+
|
|
136
|
+
// Now lifecycle methods use LLM intelligence
|
|
137
|
+
await memory.consolidate(); // LLM scoring + dedup + conflict resolution
|
|
138
|
+
await memory.summarizeSession('session-123'); // LLM summarization
|
|
139
|
+
await memory.runDecay(); // importance-based archival
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Without LLM**: Lifecycle still works using heuristic fallbacks (regex extraction, embedding-distance dedup, formula-based scoring). LLM makes it smarter, not mandatory.
|
|
143
|
+
|
|
144
|
+
## Pattern 6: File Ingestion
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import { IngestionAgent, Memory } from '@pyx-memory/core';
|
|
148
|
+
|
|
149
|
+
const memory = new Memory({ dataDir: './data' });
|
|
150
|
+
await memory.initialize();
|
|
151
|
+
|
|
152
|
+
const agent = new IngestionAgent({
|
|
153
|
+
llm: myLlmCallback, // optional: smart classification + enrichment
|
|
154
|
+
embedder: (texts) => myEmbedder.embed(texts), // optional: semantic chunking (separate from Memory's internal embedder)
|
|
155
|
+
useSemanticChunking: true,
|
|
156
|
+
useStructuralChunking: false,
|
|
157
|
+
enableEnrichment: true,
|
|
158
|
+
enableMetadata: true,
|
|
159
|
+
enableHierarchical: false, // requires LLM
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// Supported: .txt, .md, .csv, .pdf, .docx, .json, .html
|
|
163
|
+
const buffer = Buffer.from(await Bun.file('report.pdf').arrayBuffer());
|
|
164
|
+
const result = await agent.ingest(buffer, 'report.pdf', memory);
|
|
165
|
+
// result: { filename, fileType, chunks, entryIds, totalCharacters }
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Note**: `IngestionAgent` may accept its own `embedder` for semantic chunking. This is separate from Memory's internal embedding — Memory handles its own embedding automatically.
|
|
169
|
+
|
|
170
|
+
## Pattern 7: Factory with Auto-Mode Switching
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { createMemory } from '@pyx-memory/core';
|
|
174
|
+
|
|
175
|
+
// Embedded mode (default)
|
|
176
|
+
const memory = createMemory({
|
|
177
|
+
dataDir: './data',
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Sidecar mode (when MEMORY_URL is set)
|
|
181
|
+
const remote = createMemory({
|
|
182
|
+
memoryUrl: process.env.MEMORY_URL, // e.g., 'http://localhost:7822'
|
|
183
|
+
apiKey: process.env.MEMORY_API_KEY,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
await memory.initialize();
|
|
187
|
+
|
|
188
|
+
// WARNING: createMemory() returns MemoryInterface, NOT ExtendedMemoryInterface.
|
|
189
|
+
// If you need lifecycle methods, cast:
|
|
190
|
+
// const extended = memory as ExtendedMemoryInterface;
|
|
191
|
+
// Or prefer `new Memory()` / `new MemoryClient()` directly.
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Adding as Git Submodule (Recommended for Embedded Mode)
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
git submodule add https://github.com/fysoul17/pyx-memory-v1.git vendor/pyx-memory
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Add to your `package.json` workspaces:
|
|
203
|
+
|
|
204
|
+
```json
|
|
205
|
+
{
|
|
206
|
+
"workspaces": [
|
|
207
|
+
"packages/*",
|
|
208
|
+
"vendor/pyx-memory/packages/shared",
|
|
209
|
+
"vendor/pyx-memory/packages/client",
|
|
210
|
+
"vendor/pyx-memory/packages/core"
|
|
211
|
+
]
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Then: `bun install`
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## MemoryOptions Quick Reference
|
|
220
|
+
|
|
221
|
+
`embedder` has been removed from MemoryOptions. Memory internally creates a `LocalEmbeddingProvider` using BGE-M3 (1024 dimensions) via `@huggingface/transformers`. You never need to provide an embedding function.
|
|
222
|
+
|
|
223
|
+
See [reference/types.md](../reference/types.md#memoryoptions-reference) for the full MemoryOptions table.
|