@traqr/memory 0.1.4 → 0.1.5
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 +93 -102
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,134 +1,125 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @traqr/memory
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript library for persistent AI agent memory. Multi-strategy retrieval (semantic + BM25 + RRF), 3-zone cosine triage, entity extraction, type-aware lifecycle. Postgres + pgvector.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Use this library if you're building your own memory-powered application. For an MCP server that works out of the box, see [traqr-memory-mcp](https://www.npmjs.com/package/traqr-memory-mcp).
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Install
|
|
8
8
|
|
|
9
|
-
**Option A: Supabase (easiest, free tier)**
|
|
10
|
-
1. Create a project at [supabase.com](https://supabase.com)
|
|
11
|
-
2. Go to SQL Editor, paste contents of `setup.sql`, run
|
|
12
|
-
3. Copy your project URL + service role key from Settings > API
|
|
13
|
-
|
|
14
|
-
**Option B: AWS RDS / Aurora**
|
|
15
|
-
1. Create RDS Postgres 15+ instance
|
|
16
|
-
2. Enable pgvector: `CREATE EXTENSION vector;`
|
|
17
|
-
3. Run setup.sql via psql: `psql $DATABASE_URL -f setup.sql`
|
|
18
|
-
|
|
19
|
-
**Option C: Docker (local dev)**
|
|
20
9
|
```bash
|
|
21
|
-
|
|
22
|
-
-e POSTGRES_PASSWORD=postgres \
|
|
23
|
-
-p 5432:5432 \
|
|
24
|
-
pgvector/pgvector:pg16
|
|
25
|
-
psql postgresql://postgres:postgres@localhost:5432/postgres -f setup.sql
|
|
10
|
+
npm install @traqr/memory
|
|
26
11
|
```
|
|
27
12
|
|
|
28
|
-
|
|
13
|
+
## Quick Usage
|
|
29
14
|
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
# Optional
|
|
43
|
-
export COHERE_API_KEY="..." # Cohere Rerank v3.5
|
|
44
|
-
```
|
|
15
|
+
```typescript
|
|
16
|
+
import { configureMemory, storeMemory, searchMemoriesV2, triageAndStore } from '@traqr/memory'
|
|
17
|
+
|
|
18
|
+
// Configure once at startup
|
|
19
|
+
configureMemory({
|
|
20
|
+
supabaseUrl: process.env.SUPABASE_URL,
|
|
21
|
+
supabaseKey: process.env.SUPABASE_SERVICE_ROLE_KEY,
|
|
22
|
+
})
|
|
23
|
+
// OR for raw Postgres:
|
|
24
|
+
configureMemory({
|
|
25
|
+
databaseUrl: process.env.DATABASE_URL,
|
|
26
|
+
})
|
|
45
27
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
28
|
+
// Store a memory
|
|
29
|
+
const memory = await storeMemory({
|
|
30
|
+
content: 'React Server Components require "use client" for interactive components',
|
|
31
|
+
sourceType: 'session',
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
// Search by meaning (multi-strategy: semantic + BM25 + RRF fusion)
|
|
35
|
+
const results = await searchMemoriesV2('React component patterns', { limit: 5 })
|
|
36
|
+
|
|
37
|
+
// Store with deduplication triage (cosine similarity zones + LLM borderline)
|
|
38
|
+
const result = await triageAndStore({
|
|
39
|
+
content: 'Always use useCallback for event handlers passed to memoized children',
|
|
40
|
+
sourceType: 'session',
|
|
41
|
+
})
|
|
42
|
+
// result.zone: 'noop' (duplicate) | 'add' (new) | 'borderline' (LLM decided)
|
|
60
43
|
```
|
|
61
44
|
|
|
62
|
-
|
|
45
|
+
## VectorDB Providers
|
|
46
|
+
|
|
47
|
+
Two providers, same SQL functions, different transport:
|
|
63
48
|
|
|
64
|
-
|
|
49
|
+
| Provider | Connection | Transport | When to use |
|
|
50
|
+
|----------|-----------|-----------|-------------|
|
|
51
|
+
| Supabase | `SUPABASE_URL` + `SUPABASE_SERVICE_ROLE_KEY` | PostgREST (HTTP) | Easiest setup, free tier |
|
|
52
|
+
| Postgres | `DATABASE_URL` | pg wire protocol | RDS, Aurora, Docker, self-hosted |
|
|
65
53
|
|
|
66
|
-
|
|
54
|
+
Auto-detected from environment variables. Or explicit:
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { getVectorDB } from '@traqr/memory'
|
|
67
58
|
|
|
68
|
-
|
|
59
|
+
const db = getVectorDB({ type: 'postgres' })
|
|
60
|
+
await db.ping() // true
|
|
61
|
+
```
|
|
69
62
|
|
|
70
|
-
|
|
71
|
-
|------|-------------|
|
|
72
|
-
| `memory_store` | Remember something. Only content required — everything else auto-derived. |
|
|
73
|
-
| `memory_search` | Search memories by meaning. Returns summaries. |
|
|
74
|
-
| `memory_read` | Expand a memory by ID. Full content + version history. |
|
|
75
|
-
| `memory_enhance` | Deepen understanding. Creates connected memories via triage pipeline. |
|
|
76
|
-
| `memory_browse` | Navigate by facet. Domain > category > summaries. Zero embedding cost. |
|
|
77
|
-
| `memory_context` | Load task-relevant context — principles, preferences, gotchas. |
|
|
78
|
-
| `memory_pulse` | Batch: capture multiple learnings + search + update in one call. |
|
|
79
|
-
| `memory_audit` | System health, stats, quality metrics. |
|
|
80
|
-
| `memory_archive` | Archive stale content that was once correct. |
|
|
81
|
-
| `memory_forget` | Forget incorrect or harmful content permanently. |
|
|
63
|
+
For raw Postgres, install the `pg` package: `npm install pg`
|
|
82
64
|
|
|
83
|
-
##
|
|
65
|
+
## Embedding Providers
|
|
84
66
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
67
|
+
| Provider | Env Var | Model | Dimensions |
|
|
68
|
+
|----------|---------|-------|-----------|
|
|
69
|
+
| OpenAI | `OPENAI_API_KEY` | text-embedding-3-small | 1536 |
|
|
70
|
+
| Gemini | `GOOGLE_API_KEY` | gemini-embedding-001 | 1536 |
|
|
71
|
+
| Bedrock | `EMBEDDING_PROVIDER=bedrock` + AWS creds | amazon.nova-embed-v1:0 | 1536 |
|
|
72
|
+
| Ollama | `EMBEDDING_PROVIDER=ollama` | nomic-embed-text | 768 |
|
|
73
|
+
| None | `EMBEDDING_PROVIDER=none` | — | 0 (BM25 only) |
|
|
92
74
|
|
|
93
|
-
|
|
94
|
-
- Multi-strategy retrieval: semantic + BM25 > RRF fusion > optional Cohere rerank
|
|
95
|
-
- 3-zone cosine triage: NOOP (>=0.90), ADD (<0.60), borderline (GPT-4o-mini decision)
|
|
96
|
-
- Type-aware lifecycle: facts invalidate, preferences supersede, patterns coexist
|
|
97
|
-
- Entity extraction: multi-signal canonicalization (name > ILIKE > embedding)
|
|
98
|
-
- Quality gate: 3-layer ingestion filter prevents noise
|
|
75
|
+
Set `EMBEDDING_PROVIDER` explicitly, or it auto-detects from available API keys.
|
|
99
76
|
|
|
100
|
-
|
|
77
|
+
```typescript
|
|
78
|
+
import { getEmbeddingProvider } from '@traqr/memory'
|
|
101
79
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
80
|
+
const ep = getEmbeddingProvider()
|
|
81
|
+
console.log(ep.provider, ep.model, ep.dimensions)
|
|
82
|
+
// 'openai', 'text-embedding-3-small', 1536
|
|
83
|
+
```
|
|
106
84
|
|
|
107
|
-
##
|
|
85
|
+
## Key Exports
|
|
108
86
|
|
|
109
87
|
```typescript
|
|
110
|
-
|
|
88
|
+
// High-level operations
|
|
89
|
+
import {
|
|
90
|
+
storeMemory, searchMemoriesV2, getMemory, updateMemory, deleteMemory,
|
|
91
|
+
triageAndStore, storeWithDedup, archiveMemory, remember, recall,
|
|
92
|
+
} from '@traqr/memory'
|
|
111
93
|
|
|
112
|
-
//
|
|
113
|
-
|
|
94
|
+
// VectorDB layer
|
|
95
|
+
import { getVectorDB, resetVectorDB } from '@traqr/memory'
|
|
96
|
+
import type { VectorDBProvider, Memory, MemorySearchResult } from '@traqr/memory'
|
|
97
|
+
|
|
98
|
+
// Embeddings
|
|
99
|
+
import { generateEmbedding, getEmbeddingProvider } from '@traqr/memory'
|
|
100
|
+
import type { EmbeddingProvider, EmbeddingResult } from '@traqr/memory'
|
|
114
101
|
|
|
115
|
-
//
|
|
116
|
-
|
|
102
|
+
// Configuration
|
|
103
|
+
import { configureMemory, getMemoryConfig } from '@traqr/memory'
|
|
117
104
|
|
|
118
|
-
//
|
|
119
|
-
|
|
120
|
-
|
|
105
|
+
// Auto-derive (extracts domain, category, topic, tags from content)
|
|
106
|
+
import { deriveAll } from '@traqr/memory'
|
|
107
|
+
|
|
108
|
+
// Multi-strategy retrieval internals
|
|
109
|
+
import { reciprocalRankFusion, detectStrategies } from '@traqr/memory'
|
|
121
110
|
```
|
|
122
111
|
|
|
123
|
-
##
|
|
112
|
+
## Database Setup
|
|
113
|
+
|
|
114
|
+
Run `setup.sql` on your Postgres 15+ database (pgvector required):
|
|
124
115
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
116
|
+
```bash
|
|
117
|
+
# Supabase: paste into SQL Editor
|
|
118
|
+
# Postgres: psql $DATABASE_URL -f setup.sql
|
|
119
|
+
# Docker:
|
|
120
|
+
docker run -d --name traqrdb -e POSTGRES_PASSWORD=postgres -p 5432:5432 pgvector/pgvector:pg16
|
|
121
|
+
psql postgresql://postgres:postgres@localhost:5432/postgres -f node_modules/traqr-memory-mcp/setup.sql
|
|
122
|
+
```
|
|
132
123
|
|
|
133
124
|
## License
|
|
134
125
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@traqr/memory",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Persistent memory for AI agents. Multi-strategy retrieval (semantic + BM25 + RRF), 3-zone cosine triage, type-aware lifecycle, entity canonicalization. Postgres + pgvector.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|