tapirus 1.0.1 → 1.0.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/CORE_LICENSE +36 -0
- package/LICENSE +21 -0
- package/NOTICE +8 -0
- package/README.md +85 -228
- package/index.d.ts +162 -30
- package/index.js +138 -67
- package/package.json +54 -45
- package/tapirus.darwin-arm64.node +0 -0
- package/tapirus.darwin-x64.node +0 -0
- package/tapirus.linux-arm64-gnu.node +0 -0
- package/tapirus.linux-x64-gnu.node +0 -0
- package/tapirus.win32-x64-msvc.node +0 -0
- package/Cargo.toml +0 -15
- package/build.rs +0 -5
- package/engine.js +0 -507
- package/src/lib.rs +0 -84
- package/test.js +0 -34
package/CORE_LICENSE
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
Parameters:
|
|
4
|
+
|
|
5
|
+
Licensor:
|
|
6
|
+
Ahmad Faiz (TapirusLab / TapirusDB)
|
|
7
|
+
|
|
8
|
+
Licensed Work:
|
|
9
|
+
TapirusDB ("tapirus") database engine source code and documentation.
|
|
10
|
+
|
|
11
|
+
Additional Use Grant:
|
|
12
|
+
You may make use of the Licensed Work (including copying, modifying, and
|
|
13
|
+
compiling it) for any application or purpose, provided that you do not offer
|
|
14
|
+
the Licensed Work as a hosted commercial Managed Database-as-a-Service (DBaaS)
|
|
15
|
+
or cloud-hosted database platform in competition with the Licensor without
|
|
16
|
+
an explicit commercial license agreement.
|
|
17
|
+
|
|
18
|
+
Individual developer usage, research, embedded application embedding,
|
|
19
|
+
self-hosted single-node deployments, and edge silicon use cases are 100%
|
|
20
|
+
permitted and royalty-free under this grant.
|
|
21
|
+
|
|
22
|
+
Change Date:
|
|
23
|
+
September 16, 2030
|
|
24
|
+
|
|
25
|
+
Change License:
|
|
26
|
+
Apache License, Version 2.0
|
|
27
|
+
|
|
28
|
+
-------------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
Notice:
|
|
31
|
+
|
|
32
|
+
The Business Source License 1.1 (the "License") is a license that allows you
|
|
33
|
+
to use the Licensed Work for free, subject to the conditions above. On the
|
|
34
|
+
Change Date, the Licensed Work will become subject to the Change License.
|
|
35
|
+
|
|
36
|
+
For full license terms and conditions, see https://mariadb.com/bsl11/
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TapirusDB Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
The packaged native addon includes the TapirusDB engine under its existing
|
|
2
|
+
Business Source License 1.1. The core license parameters and Additional Use
|
|
3
|
+
Grant are reproduced in CORE_LICENSE.
|
|
4
|
+
|
|
5
|
+
The Node wrapper source is declared MIT. That declaration does not change
|
|
6
|
+
the license of the embedded database engine. The package's license expression
|
|
7
|
+
records both components. Dependency license declarations are inventoried in
|
|
8
|
+
the release CycloneDX file; it is not an ownership or license-compliance audit.
|
package/README.md
CHANGED
|
@@ -1,228 +1,85 @@
|
|
|
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
|
-
db.execute('
|
|
65
|
-
db.execute(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### Step 3: Run your script with Node.js
|
|
89
|
-
```powershell
|
|
90
|
-
node app.mjs
|
|
91
|
-
# Output: Query result: [ { id: 1, name: 'Alex', active: 1 } ]
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### Step 4: Interactive Mode (Node.js REPL)
|
|
95
|
-
If you want to type commands interactively in PowerShell:
|
|
96
|
-
```powershell
|
|
97
|
-
PS C:\workspace\my-tapirus-app> node
|
|
98
|
-
> const { open } = require('tapirus');
|
|
99
|
-
> const db = open('production.tapir');
|
|
100
|
-
> db.execute("CREATE TABLE users (id INT, name TEXT);");
|
|
101
|
-
> db.execute("INSERT INTO users VALUES (1, 'Alex');");
|
|
102
|
-
> db.query("SELECT * FROM users;");
|
|
103
|
-
[ { id: 1, raw: "INSERT INTO users VALUES (1, 'Alex')" } ]
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
---
|
|
107
|
-
|
|
108
|
-
## 🚀 Quickstart
|
|
109
|
-
|
|
110
|
-
### 1. Relational SQL & ACID Transactions
|
|
111
|
-
|
|
112
|
-
```typescript
|
|
113
|
-
import { open } from 'tapirus';
|
|
114
|
-
|
|
115
|
-
// Open or create a persistent database file (or ":memory:")
|
|
116
|
-
const db = open('production.tapir');
|
|
117
|
-
|
|
118
|
-
// Create structured table
|
|
119
|
-
db.execute(`
|
|
120
|
-
CREATE TABLE IF NOT EXISTS agents (
|
|
121
|
-
id INTEGER PRIMARY KEY,
|
|
122
|
-
name TEXT NOT NULL,
|
|
123
|
-
model TEXT NOT NULL,
|
|
124
|
-
memory_mb REAL
|
|
125
|
-
);
|
|
126
|
-
`);
|
|
127
|
-
|
|
128
|
-
// Insert records with parameters
|
|
129
|
-
db.execute(
|
|
130
|
-
'INSERT INTO agents (id, name, model, memory_mb) VALUES (?, ?, ?, ?);',
|
|
131
|
-
[1, 'Echo-Agent', 'Phi-3-Mini', 3.8]
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
// Query rows as typed objects
|
|
135
|
-
const rows = db.query<{ id: number; name: string; model: string; memory_mb: number }>(
|
|
136
|
-
'SELECT id, name, model, memory_mb FROM agents WHERE memory_mb < 100;'
|
|
137
|
-
);
|
|
138
|
-
console.log('Active Agents:', rows);
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
---
|
|
142
|
-
|
|
143
|
-
### 2. Native HNSW Vector Similarity Search
|
|
144
|
-
|
|
145
|
-
```typescript
|
|
146
|
-
import { open } from 'tapirus';
|
|
147
|
-
|
|
148
|
-
const db = open('production.tapir');
|
|
149
|
-
|
|
150
|
-
// Create table with dense vector embedding column
|
|
151
|
-
db.execute(`
|
|
152
|
-
CREATE TABLE IF NOT EXISTS knowledge (
|
|
153
|
-
id INTEGER PRIMARY KEY,
|
|
154
|
-
content TEXT NOT NULL,
|
|
155
|
-
embedding VECTOR(4)
|
|
156
|
-
);
|
|
157
|
-
`);
|
|
158
|
-
|
|
159
|
-
// Insert embeddings
|
|
160
|
-
db.execute(`
|
|
161
|
-
INSERT INTO knowledge VALUES
|
|
162
|
-
(1, 'Safe Systems Architecture', [0.12, 0.45, 0.88, -0.23]),
|
|
163
|
-
(2, 'Quantum Neural Topology', [-0.42, 0.81, 0.15, 0.33]);
|
|
164
|
-
`);
|
|
165
|
-
|
|
166
|
-
// Query top-K nearest neighbors using Cosine similarity
|
|
167
|
-
const queryVector = [0.10, 0.40, 0.85, -0.20];
|
|
168
|
-
const matches = db.query(`
|
|
169
|
-
SELECT id, content, VECTOR_COSINE(embedding, ?) AS score
|
|
170
|
-
FROM knowledge
|
|
171
|
-
ORDER BY score DESC
|
|
172
|
-
LIMIT 5;
|
|
173
|
-
`, [queryVector]);
|
|
174
|
-
|
|
175
|
-
console.log('Top Matches:', matches);
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
---
|
|
179
|
-
|
|
180
|
-
### 3. Knowledge Graph & openCypher GraphRAG
|
|
181
|
-
|
|
182
|
-
```typescript
|
|
183
|
-
import { open } from 'tapirus';
|
|
184
|
-
|
|
185
|
-
const db = open('production.tapir');
|
|
186
|
-
|
|
187
|
-
// Add property graph nodes & edges
|
|
188
|
-
db.graphAddNode(1, 'Agent', { name: 'Echo', role: 'Planner' });
|
|
189
|
-
db.graphAddNode(2, 'Database', { name: 'TapirusDB', version: '1.0.0' });
|
|
190
|
-
db.graphAddEdge(1, 2, 'USES', 1.0, { since: '2026' });
|
|
191
|
-
|
|
192
|
-
// openCypher pattern traversal
|
|
193
|
-
const results = db.graphMatch(
|
|
194
|
-
'MATCH (a:Agent)-[r:USES]->(d:Database) RETURN a.name, d.name;'
|
|
195
|
-
);
|
|
196
|
-
console.log('Graph Relationships:', results);
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
---
|
|
200
|
-
|
|
201
|
-
### 4. Schemaless JSON Document Store
|
|
202
|
-
|
|
203
|
-
```typescript
|
|
204
|
-
import { open } from 'tapirus';
|
|
205
|
-
|
|
206
|
-
const db = open('production.tapir');
|
|
207
|
-
const users = db.collection('users');
|
|
208
|
-
|
|
209
|
-
// Insert nested JSON payload
|
|
210
|
-
const docId = users.insertOne({
|
|
211
|
-
username: 'alex',
|
|
212
|
-
profile: { role: 'Architect', location: 'Kuala Lumpur' },
|
|
213
|
-
models: ['phi-3', 'qwen-2.5']
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
// Retrieve by document ID
|
|
217
|
-
const user = users.findOne({ _id: docId });
|
|
218
|
-
console.log('User document:', user);
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
---
|
|
222
|
-
|
|
223
|
-
## 📜 License
|
|
224
|
-
|
|
225
|
-
The TapirusDB Node.js SDK is licensed under the [MIT License](LICENSE).
|
|
226
|
-
The underlying TapirusDB core engine is licensed under [BUSL-1.1](https://github.com/tapiruslab/TapirusDB/blob/main/LICENSE).
|
|
227
|
-
|
|
228
|
-
For complete documentation, benchmarks, and architectural details, visit **[tapirusdb.com](https://tapirusdb.com)**.
|
|
1
|
+
# TapirusDB Node.js SDK
|
|
2
|
+
|
|
3
|
+
The supported runtime floor is Node.js 22; CI also covers the 24 and 26 LTS
|
|
4
|
+
lines. Release builds target Linux x64/ARM64 (glibc), macOS Intel/Apple Silicon,
|
|
5
|
+
and Windows x64. Linux musl and Windows ARM64 addons are not produced by the
|
|
6
|
+
SDK release workflow. The Rust core's broader target matrix is separate.
|
|
7
|
+
|
|
8
|
+
New source APIs include upsert, atomic batches, TTL, model identity, revision
|
|
9
|
+
checks and indexed retrieval diagnostics. `TapirusSessionDatabase` provides
|
|
10
|
+
independently owned transactions over serialized storage. See
|
|
11
|
+
[AI and embedded workflows](../../docs/AI_EMBEDDED_WORKFLOWS.md).
|
|
12
|
+
|
|
13
|
+
This package is a synchronous Node.js binding to the TapirusDB Rust engine. It requires a matching native `.node` addon. It does not switch to an in-memory JavaScript implementation if that addon is missing; opening a database fails with a diagnostic error instead.
|
|
14
|
+
|
|
15
|
+
## Install and open a database
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install tapirus
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
const { open } = require('tapirus');
|
|
23
|
+
|
|
24
|
+
const db = open('app.tapir');
|
|
25
|
+
db.execute('CREATE TABLE IF NOT EXISTS notes (id INTEGER PRIMARY KEY, body TEXT NOT NULL);');
|
|
26
|
+
db.execute('INSERT INTO notes VALUES (?, ?);', [1, 'Stored on disk']);
|
|
27
|
+
console.log(db.query('SELECT id, body FROM notes WHERE id = ?;', [1]));
|
|
28
|
+
db.close();
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Use `open(':memory:')` when a transient database is intended. `close()` checkpoints the connection and propagates checkpoint errors. For deployments where native artifacts are built locally, set `TAPIRUS_NATIVE_PATH` to the addon file.
|
|
32
|
+
|
|
33
|
+
## Bound parameters
|
|
34
|
+
|
|
35
|
+
Use `?` placeholders for values. The SDK sends parameters through the engine's prepared-statement API, so question marks inside quoted SQL strings remain literal text.
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
db.execute('INSERT INTO notes VALUES (?, ?);', [2, "O'Reilly"]);
|
|
39
|
+
const rows = db.query("SELECT '?' AS literal, ? AS bound;", ['value']);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Supported JavaScript parameter values are strings, booleans, finite numbers, `bigint`, `null`, numeric arrays for vectors, and `Uint8Array` for blobs. Integers outside JavaScript's safe number range must use `bigint`.
|
|
43
|
+
|
|
44
|
+
## Vector search and memory
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
const nearest = db.vectorSearch('notes_with_vectors', 'embedding', [0.1, 0.2, 0.3], 5);
|
|
48
|
+
const memoryId = db.remember('The user prefers concise answers', 0.7, ['preference']);
|
|
49
|
+
const memories = db.recall('answer style', 5);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The vector column must exist on the named table and the query dimension must match its schema. TAP classification, verification, routing and scoring are heuristic engine operations; their scores are not calibrated probabilities.
|
|
53
|
+
|
|
54
|
+
## Committed change notifications
|
|
55
|
+
|
|
56
|
+
For model-supplied embeddings, namespace/session filters, transactional source storage and source citations, use `storeMemory`, `searchMemories` and `forgetMemory`. See the [AI memory guide](../../docs/AI_MEMORY.md).
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
const subscription = db.subscribe('notes', change => {
|
|
60
|
+
console.log(change.op, change.table, change.row_id);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
db.execute('BEGIN;');
|
|
64
|
+
db.execute('INSERT INTO notes VALUES (?, ?);', [3, 'Committed later']);
|
|
65
|
+
db.execute('COMMIT;');
|
|
66
|
+
subscription.unsubscribe();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Notifications are delivered after commit and after the database locks are released. Changes removed by rollback are not delivered. `row_id` is the inserted row ID for a single-row insert; it is `0` when an operation has no single known row ID.
|
|
70
|
+
|
|
71
|
+
## Native package maintenance
|
|
72
|
+
|
|
73
|
+
The supported npm package is `tapirus` in `sdks/nodejs`. Its release workflow builds platform addons and runs the persistence smoke test before publishing. The older `packages/npm` wrapper is synchronized for local compatibility and marked private; it is not a second published SDK.
|
|
74
|
+
|
|
75
|
+
Build and validate locally from the repository root:
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
node scripts/build-node-sdk.js --debug
|
|
79
|
+
node sdks/nodejs/test.js
|
|
80
|
+
node scripts/test-node-package.js
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The package test installs the generated npm tarball into a fresh consumer directory and checks persistence in a second Node process. SQL integers beyond the safe JavaScript number range are returned as `bigint`.
|
|
84
|
+
|
|
85
|
+
The wrapper source is declared MIT; the packaged native addon embeds the BUSL-1.1 core. `CORE_LICENSE` and `NOTICE` accompany the binary, and the npm license expression includes both existing component licenses.
|
package/index.d.ts
CHANGED
|
@@ -1,47 +1,179 @@
|
|
|
1
|
-
|
|
2
|
-
* TapirusDB Node.js & TypeScript SDK (tapirus)
|
|
3
|
-
* Native Safe-Rust NAPI-RS binding with in-memory quad-model fallback.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export type Value = string | number | boolean | null | number[] | Uint8Array;
|
|
1
|
+
export type Value = string | number | bigint | boolean | null | number[] | Uint8Array;
|
|
7
2
|
|
|
8
3
|
export interface DatabaseOptions {
|
|
9
|
-
pageSize?: number;
|
|
10
4
|
passphrase?: string;
|
|
11
|
-
|
|
5
|
+
memory?: MemoryConfig;
|
|
12
6
|
}
|
|
13
7
|
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
export interface ChangeEvent {
|
|
9
|
+
op: 'Insert' | 'Update' | 'Delete';
|
|
10
|
+
table: string;
|
|
11
|
+
row_id: number;
|
|
12
|
+
timestamp: number;
|
|
13
|
+
data: unknown;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Subscription {
|
|
17
|
+
unsubscribe(): boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface MemoryDocument {
|
|
21
|
+
content: string;
|
|
22
|
+
embedding?: number[];
|
|
23
|
+
importance?: number;
|
|
24
|
+
tags?: string[];
|
|
25
|
+
namespace?: string;
|
|
26
|
+
sessionId?: string;
|
|
27
|
+
externalId?: string;
|
|
28
|
+
sourceVersion?: string;
|
|
29
|
+
embeddingModel?: string;
|
|
30
|
+
expiresAt?: number;
|
|
31
|
+
ttlSeconds?: number;
|
|
32
|
+
expectedRevision?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface MemorySearch {
|
|
36
|
+
query?: string;
|
|
37
|
+
embedding?: number[];
|
|
38
|
+
limit?: number;
|
|
39
|
+
namespace?: string;
|
|
40
|
+
sessionId?: string;
|
|
41
|
+
tags?: string[];
|
|
42
|
+
embeddingModel?: string;
|
|
43
|
+
candidateLimit?: number;
|
|
44
|
+
fusion?: 'rrf' | 'weighted';
|
|
45
|
+
rrfK?: number;
|
|
46
|
+
vectorWeight?: number;
|
|
47
|
+
lexicalWeight?: number;
|
|
48
|
+
recencyWeight?: number;
|
|
49
|
+
importanceWeight?: number;
|
|
50
|
+
halfLifeSeconds?: number;
|
|
51
|
+
minScore?: number;
|
|
52
|
+
exact?: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface MemoryConfig {
|
|
56
|
+
maxDocuments?: number;
|
|
57
|
+
maxEstimatedBytes?: number;
|
|
58
|
+
maxDocumentBytes?: number;
|
|
59
|
+
maxVectorDimensions?: number;
|
|
60
|
+
maxVectorSpaces?: number;
|
|
61
|
+
maxBatchDocuments?: number;
|
|
62
|
+
maxCandidates?: number;
|
|
63
|
+
hnswM?: number;
|
|
64
|
+
efConstruction?: number;
|
|
65
|
+
efSearch?: number;
|
|
66
|
+
}
|
|
67
|
+
export interface MemoryStats {
|
|
68
|
+
documents: number;
|
|
69
|
+
estimated_resident_bytes: number;
|
|
70
|
+
max_estimated_bytes: number;
|
|
71
|
+
vector_spaces: number;
|
|
72
|
+
indexed_vectors: number;
|
|
73
|
+
pending_index_updates: number;
|
|
74
|
+
}
|
|
75
|
+
export interface MemoryDeleteScope {
|
|
76
|
+
namespace?: string;
|
|
77
|
+
sessionId?: string;
|
|
78
|
+
externalId?: string;
|
|
79
|
+
sourceVersion?: string;
|
|
80
|
+
exceptSourceVersion?: string;
|
|
81
|
+
tags?: string[];
|
|
82
|
+
all?: boolean;
|
|
83
|
+
}
|
|
84
|
+
export interface MemorySearchResponse {
|
|
85
|
+
results: MemoryResult[];
|
|
86
|
+
diagnostics: {
|
|
87
|
+
total_documents: number; candidate_limit: number; lexical_candidates: number;
|
|
88
|
+
vector_candidates: number; scored_candidates: number; exact_vector_search: boolean;
|
|
89
|
+
vector_indexes_used: number; fusion: 'rrf' | 'weighted';
|
|
90
|
+
};
|
|
20
91
|
}
|
|
21
92
|
|
|
22
|
-
export
|
|
93
|
+
export interface StorageHealth {
|
|
94
|
+
reopen_required: boolean;
|
|
95
|
+
checkpoint_error: string | null;
|
|
96
|
+
wal_frames: number;
|
|
97
|
+
}
|
|
23
98
|
|
|
24
|
-
export
|
|
99
|
+
export interface MemoryResult {
|
|
100
|
+
entry: { id: number; content: string; vector: number[] | null; tags: string[]; namespace: string | null; session_id: string | null;
|
|
101
|
+
external_id: string | null; source_version: string | null; embedding_model: string | null;
|
|
102
|
+
expires_at: number | null; revision: number; updated_at: number; content_hash: string };
|
|
103
|
+
combined_score: number;
|
|
104
|
+
semantic_score: number;
|
|
105
|
+
lexical_score: number;
|
|
106
|
+
recency_score: number;
|
|
107
|
+
is_associative: boolean;
|
|
108
|
+
}
|
|
25
109
|
|
|
26
110
|
export class TapirusDatabase {
|
|
27
|
-
|
|
111
|
+
constructor(filePath?: string, options?: DatabaseOptions);
|
|
112
|
+
static open(path?: string, options?: DatabaseOptions): TapirusDatabase;
|
|
28
113
|
static openInMemory(options?: DatabaseOptions): TapirusDatabase;
|
|
29
114
|
static version(): string;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
115
|
+
readonly isNative: true;
|
|
116
|
+
readonly isOpen: boolean;
|
|
117
|
+
readonly path: string;
|
|
118
|
+
execute(sql: string, params?: Value[]): number;
|
|
119
|
+
query<T = Record<string, unknown>>(sql: string, params?: Value[]): T[];
|
|
120
|
+
vectorSearch<T = Record<string, unknown>>(table: string, vectorColumn: string, vector: number[], limit?: number): T[];
|
|
121
|
+
graphAlgorithm(algorithm: string): Record<string, unknown>[];
|
|
122
|
+
tapClassifyDetailed(text: string, candidates: string[]): Record<string, unknown>;
|
|
123
|
+
tapClassify(text: string, candidates: string[]): string;
|
|
124
|
+
tapVerify(premise: string, hypothesis: string, threshold?: number): boolean;
|
|
125
|
+
tapScore(text: string, criteria: string): number;
|
|
126
|
+
tapRoute(state: string, routes: string[]): string;
|
|
127
|
+
remember(text: string, importance?: number, tags?: string[]): number;
|
|
128
|
+
storeMemory(document: MemoryDocument): number;
|
|
129
|
+
upsertMemory(document: MemoryDocument): number;
|
|
130
|
+
storeMemoryBatch(documents: MemoryDocument[]): number[];
|
|
131
|
+
upsertMemoryBatch(documents: MemoryDocument[]): number[];
|
|
132
|
+
searchMemories(search: MemorySearch): MemoryResult[];
|
|
133
|
+
searchMemoriesDetailed(search: MemorySearch): MemorySearchResponse;
|
|
134
|
+
configureMemory(config: MemoryConfig): MemoryStats;
|
|
135
|
+
memoryStats(): MemoryStats;
|
|
136
|
+
storageHealth(): StorageHealth;
|
|
137
|
+
prepareMemoryIndexes(): MemoryStats;
|
|
138
|
+
purgeExpiredMemories(): number;
|
|
139
|
+
deleteMemories(scope: MemoryDeleteScope): number;
|
|
140
|
+
forgetMemory(id: number): boolean;
|
|
141
|
+
recall(query: string, limit?: number): Record<string, unknown>[];
|
|
37
142
|
recallPrompt(query: string, limit?: number): string;
|
|
38
|
-
|
|
39
|
-
|
|
143
|
+
graphRagQuery(options: { query: string; limit?: number }): Record<string, unknown>;
|
|
144
|
+
subscribe(table: string, listener: (change: ChangeEvent) => void): Subscription;
|
|
145
|
+
checkpoint(): number;
|
|
146
|
+
vacuumInto(targetPath: string): number;
|
|
40
147
|
close(): void;
|
|
41
148
|
}
|
|
42
149
|
|
|
43
|
-
export
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
150
|
+
export function open(filePath?: string, options?: DatabaseOptions): TapirusDatabase;
|
|
151
|
+
export function version(): string;
|
|
152
|
+
export const Tapirus: typeof TapirusDatabase;
|
|
153
|
+
|
|
154
|
+
/** Sessions serialize access; a transaction belongs to one session. */
|
|
155
|
+
export class TapirusSessionDatabase {
|
|
156
|
+
constructor(filePath?: string, options?: DatabaseOptions);
|
|
157
|
+
session(options?: { busyTimeoutMs?: number }): TapirusSession;
|
|
158
|
+
close(): void;
|
|
159
|
+
}
|
|
160
|
+
export interface TapirusSession extends Pick<TapirusDatabase,
|
|
161
|
+
'execute' | 'query' | 'storeMemory' | 'upsertMemory' | 'storeMemoryBatch' |
|
|
162
|
+
'upsertMemoryBatch' | 'searchMemories' | 'searchMemoriesDetailed' |
|
|
163
|
+
'configureMemory' | 'memoryStats' | 'storageHealth' | 'prepareMemoryIndexes' |
|
|
164
|
+
'purgeExpiredMemories' | 'deleteMemories' | 'forgetMemory' | 'checkpoint' | 'close'> {
|
|
165
|
+
begin(): void;
|
|
166
|
+
commit(): void;
|
|
167
|
+
rollback(): void;
|
|
168
|
+
/** The callback must be synchronous. */
|
|
169
|
+
transaction<T>(callback: (session: TapirusSession) => T extends PromiseLike<unknown> ? never : T): T;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
declare const _default: {
|
|
173
|
+
open: typeof open;
|
|
174
|
+
version: typeof version;
|
|
175
|
+
Tapirus: typeof TapirusDatabase;
|
|
176
|
+
TapirusDatabase: typeof TapirusDatabase;
|
|
177
|
+
TapirusSessionDatabase: typeof TapirusSessionDatabase;
|
|
47
178
|
};
|
|
179
|
+
export default _default;
|