mentedb 0.1.0

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 ADDED
@@ -0,0 +1,161 @@
1
+ # mentedb
2
+
3
+ The mind database for AI agents. TypeScript/Node.js SDK powered by napi-rs.
4
+
5
+ MenteDB is a purpose built database engine for AI agent memory. It provides
6
+ vector similarity search, a typed knowledge graph, token budget aware context
7
+ assembly, and cognitive features such as contradiction detection and trajectory
8
+ tracking. This package delivers the full Rust engine as a native Node.js addon
9
+ with zero runtime dependencies.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install mentedb
15
+ ```
16
+
17
+ The package ships a prebuilt native binary. If no prebuild is available for your
18
+ platform, `npm run build` compiles from source (requires Rust and
19
+ [napi-rs](https://napi.rs)).
20
+
21
+ ## Quick start
22
+
23
+ ```typescript
24
+ import { MenteDB, MemoryType, EdgeType } from 'mentedb';
25
+
26
+ const db = new MenteDB('./my-agent-memory');
27
+
28
+ // Store a memory
29
+ const id = db.store({
30
+ content: 'The deploy key rotates every 90 days',
31
+ memoryType: MemoryType.Semantic,
32
+ embedding: embeddingFromYourModel,
33
+ tags: ['infra', 'security'],
34
+ });
35
+
36
+ // Vector similarity search
37
+ const hits = db.search(queryEmbedding, 5);
38
+
39
+ // MQL recall with token budget
40
+ const ctx = db.recall('RECALL similar("deploy key rotation") LIMIT 10');
41
+
42
+ // Relate memories
43
+ db.relate(id, otherId, EdgeType.Supersedes);
44
+
45
+ // Forget a memory
46
+ db.forget(id);
47
+
48
+ // Close the database
49
+ db.close();
50
+ ```
51
+
52
+ ## Cognitive features
53
+
54
+ ### CognitionStream
55
+
56
+ Monitor an LLM token stream for contradictions and reinforcements against
57
+ stored facts.
58
+
59
+ ```typescript
60
+ import { CognitionStream } from 'mentedb';
61
+
62
+ const stream = new CognitionStream(1000);
63
+ for (const token of llmTokens) {
64
+ stream.feedToken(token);
65
+ }
66
+ const text = stream.drainBuffer();
67
+ ```
68
+
69
+ ### TrajectoryTracker
70
+
71
+ Track the reasoning arc of a conversation and predict upcoming topics.
72
+
73
+ ```typescript
74
+ import { TrajectoryTracker } from 'mentedb';
75
+
76
+ const tracker = new TrajectoryTracker();
77
+
78
+ tracker.recordTurn('JWT auth design', 'investigating', [
79
+ 'Which algorithm?',
80
+ 'Token lifetime?',
81
+ ]);
82
+ tracker.recordTurn('Token lifetime', 'decided:15 minutes');
83
+
84
+ const resume = tracker.getResumeContext();
85
+ const next = tracker.predictNextTopics();
86
+ ```
87
+
88
+ ## API reference
89
+
90
+ ### `MenteDB`
91
+
92
+ | Method | Description |
93
+ |--------|-------------|
94
+ | `new MenteDB(dataDir)` | Open or create a database at the given path. |
95
+ | `store(options)` | Store a memory. Returns its UUID string. |
96
+ | `recall(query)` | Recall memories via an MQL query. Returns `RecallResult`. |
97
+ | `search(embedding, k)` | Vector similarity search. Returns `SearchResult[]`. |
98
+ | `relate(source, target, edgeType?, weight?)` | Create a typed edge between two memories. |
99
+ | `forget(memoryId)` | Remove a memory by ID. |
100
+ | `close()` | Flush and close the database. |
101
+
102
+ ### `CognitionStream`
103
+
104
+ | Method | Description |
105
+ |--------|-------------|
106
+ | `new CognitionStream(bufferSize?)` | Create a token stream monitor. |
107
+ | `feedToken(token)` | Push a token into the ring buffer. |
108
+ | `drainBuffer()` | Drain and return the accumulated text. |
109
+
110
+ ### `TrajectoryTracker`
111
+
112
+ | Method | Description |
113
+ |--------|-------------|
114
+ | `new TrajectoryTracker(maxTurns?)` | Create a trajectory tracker. |
115
+ | `recordTurn(topic, decisionState, openQuestions?)` | Record a conversation turn. |
116
+ | `getResumeContext()` | Build a resume context string. |
117
+ | `predictNextTopics()` | Predict the next likely topics. |
118
+
119
+ ## Types
120
+
121
+ ```typescript
122
+ enum MemoryType {
123
+ Episodic, Semantic, Procedural, AntiPattern, Reasoning, Correction
124
+ }
125
+
126
+ enum EdgeType {
127
+ Caused, Before, Related, Contradicts, Supports, Supersedes, Derived, PartOf
128
+ }
129
+
130
+ interface StoreOptions {
131
+ content: string;
132
+ memoryType?: MemoryType;
133
+ embedding?: number[];
134
+ agentId?: string;
135
+ tags?: string[];
136
+ }
137
+
138
+ interface RecallResult {
139
+ text: string;
140
+ totalTokens: number;
141
+ memoryCount: number;
142
+ }
143
+
144
+ interface SearchResult {
145
+ id: string;
146
+ score: number;
147
+ }
148
+ ```
149
+
150
+ ## Building from source
151
+
152
+ ```bash
153
+ cd sdks/typescript
154
+ cargo check # verify Rust compiles
155
+ npm run build # build the native addon
156
+ npm test # run tests
157
+ ```
158
+
159
+ ## License
160
+
161
+ Apache 2.0
package/npm/client.ts ADDED
@@ -0,0 +1,143 @@
1
+ import {
2
+ MemoryType,
3
+ EdgeType,
4
+ type StoreOptions,
5
+ type RecallResult,
6
+ type SearchResult,
7
+ } from './types';
8
+
9
+ let nativeBinding: any;
10
+
11
+ try {
12
+ nativeBinding = require('../mentedb.node');
13
+ } catch {
14
+ nativeBinding = null;
15
+ }
16
+
17
+ function requireNative(): any {
18
+ if (!nativeBinding) {
19
+ throw new Error(
20
+ 'Native extension not loaded. Build with: npm run build'
21
+ );
22
+ }
23
+ return nativeBinding;
24
+ }
25
+
26
+ /**
27
+ * MenteDB client. Wraps the native Rust database engine and exposes a
28
+ * TypeScript-friendly API for storing, recalling, searching, relating, and
29
+ * forgetting memories.
30
+ */
31
+ export class MenteDB {
32
+ private native: any;
33
+
34
+ constructor(dataDir: string = './mentedb-data') {
35
+ const binding = requireNative();
36
+ this.native = new binding.MenteDB(dataDir);
37
+ }
38
+
39
+ /** Store a memory and return its UUID. */
40
+ store(options: StoreOptions): string {
41
+ const {
42
+ content,
43
+ memoryType = MemoryType.Episodic,
44
+ embedding = [],
45
+ agentId,
46
+ tags,
47
+ } = options;
48
+ return this.native.store(content, memoryType, embedding, agentId, tags);
49
+ }
50
+
51
+ /** Recall memories using an MQL query string. */
52
+ recall(query: string): RecallResult {
53
+ return this.native.recall(query);
54
+ }
55
+
56
+ /** Vector similarity search returning top-k results. */
57
+ search(embedding: number[], k: number = 10): SearchResult[] {
58
+ return this.native.search(embedding, k);
59
+ }
60
+
61
+ /** Create a typed, weighted edge between two memories. */
62
+ relate(
63
+ source: string,
64
+ target: string,
65
+ edgeType: EdgeType = EdgeType.Related,
66
+ weight: number = 1.0,
67
+ ): void {
68
+ this.native.relate(source, target, edgeType, weight);
69
+ }
70
+
71
+ /** Remove a memory by ID. */
72
+ forget(memoryId: string): void {
73
+ this.native.forget(memoryId);
74
+ }
75
+
76
+ /** Flush all data and close the database. */
77
+ close(): void {
78
+ this.native.close();
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Monitors an LLM token stream for contradictions, forgotten facts,
84
+ * corrections, and reinforcements.
85
+ */
86
+ export class CognitionStream {
87
+ private native: any;
88
+
89
+ constructor(bufferSize: number = 1000) {
90
+ const binding = requireNative();
91
+ this.native = new binding.JsCognitionStream(bufferSize);
92
+ }
93
+
94
+ /** Push a token into the stream buffer. */
95
+ feedToken(token: string): void {
96
+ this.native.feedToken(token);
97
+ }
98
+
99
+ /** Drain the accumulated buffer and return its content. */
100
+ drainBuffer(): string {
101
+ return this.native.drainBuffer();
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Tracks the reasoning arc of a conversation and predicts next topics.
107
+ */
108
+ export class TrajectoryTracker {
109
+ private native: any;
110
+
111
+ constructor(maxTurns: number = 100) {
112
+ const binding = requireNative();
113
+ this.native = new binding.JsTrajectoryTracker(maxTurns);
114
+ }
115
+
116
+ /**
117
+ * Record a conversation turn.
118
+ *
119
+ * `decisionState` accepts one of:
120
+ * - `"investigating"`
121
+ * - `"interrupted"`
122
+ * - `"completed"`
123
+ * - `"narrowed:<choice>"`
124
+ * - `"decided:<decision>"`
125
+ */
126
+ recordTurn(
127
+ topic: string,
128
+ decisionState: string,
129
+ openQuestions: string[] = [],
130
+ ): void {
131
+ this.native.recordTurn(topic, decisionState, openQuestions);
132
+ }
133
+
134
+ /** Get a resume context string describing the current trajectory. */
135
+ getResumeContext(): string | null {
136
+ return this.native.getResumeContext() ?? null;
137
+ }
138
+
139
+ /** Predict the next likely topics based on trajectory. */
140
+ predictNextTopics(): string[] {
141
+ return this.native.predictNextTopics();
142
+ }
143
+ }
package/npm/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { MenteDB, CognitionStream, TrajectoryTracker } from './client';
2
+ export { MemoryType, EdgeType } from './types';
3
+ export type { RecallResult, SearchResult, StoreOptions } from './types';
package/npm/types.ts ADDED
@@ -0,0 +1,38 @@
1
+ export enum MemoryType {
2
+ Episodic = 'episodic',
3
+ Semantic = 'semantic',
4
+ Procedural = 'procedural',
5
+ AntiPattern = 'anti_pattern',
6
+ Reasoning = 'reasoning',
7
+ Correction = 'correction',
8
+ }
9
+
10
+ export enum EdgeType {
11
+ Caused = 'caused',
12
+ Before = 'before',
13
+ Related = 'related',
14
+ Contradicts = 'contradicts',
15
+ Supports = 'supports',
16
+ Supersedes = 'supersedes',
17
+ Derived = 'derived',
18
+ PartOf = 'part_of',
19
+ }
20
+
21
+ export interface RecallResult {
22
+ text: string;
23
+ totalTokens: number;
24
+ memoryCount: number;
25
+ }
26
+
27
+ export interface SearchResult {
28
+ id: string;
29
+ score: number;
30
+ }
31
+
32
+ export interface StoreOptions {
33
+ content: string;
34
+ memoryType?: MemoryType;
35
+ embedding?: number[];
36
+ agentId?: string;
37
+ tags?: string[];
38
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "mentedb",
3
+ "version": "0.1.0",
4
+ "description": "The mind database for AI agents",
5
+ "main": "npm/index.js",
6
+ "types": "npm/index.d.ts",
7
+ "scripts": {
8
+ "build": "napi build --release",
9
+ "test": "jest"
10
+ },
11
+ "license": "Apache-2.0",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/nambok/mentedb"
15
+ },
16
+ "keywords": [
17
+ "database",
18
+ "ai",
19
+ "agents",
20
+ "memory",
21
+ "rust",
22
+ "vector",
23
+ "knowledge-graph"
24
+ ],
25
+ "napi": {
26
+ "name": "mentedb",
27
+ "triples": {}
28
+ }
29
+ }