@memvid/sdk 2.0.113

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.
Files changed (46) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +244 -0
  3. package/dist/__tests__/basic.test.d.ts +1 -0
  4. package/dist/__tests__/basic.test.js +41 -0
  5. package/dist/adapters/autogen.d.ts +23 -0
  6. package/dist/adapters/autogen.js +163 -0
  7. package/dist/adapters/basic.d.ts +1 -0
  8. package/dist/adapters/basic.js +11 -0
  9. package/dist/adapters/crewai.d.ts +23 -0
  10. package/dist/adapters/crewai.js +160 -0
  11. package/dist/adapters/google_adk.d.ts +25 -0
  12. package/dist/adapters/google_adk.js +158 -0
  13. package/dist/adapters/haystack.d.ts +1 -0
  14. package/dist/adapters/haystack.js +11 -0
  15. package/dist/adapters/langchain.d.ts +28 -0
  16. package/dist/adapters/langchain.js +156 -0
  17. package/dist/adapters/langgraph.d.ts +1 -0
  18. package/dist/adapters/langgraph.js +11 -0
  19. package/dist/adapters/llamaindex.d.ts +33 -0
  20. package/dist/adapters/llamaindex.js +195 -0
  21. package/dist/adapters/mcp.d.ts +1 -0
  22. package/dist/adapters/mcp.js +11 -0
  23. package/dist/adapters/openai.d.ts +26 -0
  24. package/dist/adapters/openai.js +169 -0
  25. package/dist/adapters/semantic_kernel.d.ts +1 -0
  26. package/dist/adapters/semantic_kernel.js +11 -0
  27. package/dist/adapters/vercel_ai.d.ts +27 -0
  28. package/dist/adapters/vercel_ai.js +148 -0
  29. package/dist/clip.d.ts +182 -0
  30. package/dist/clip.js +371 -0
  31. package/dist/embeddings.d.ts +156 -0
  32. package/dist/embeddings.js +289 -0
  33. package/dist/entities.d.ts +251 -0
  34. package/dist/entities.js +489 -0
  35. package/dist/error.d.ts +91 -0
  36. package/dist/error.js +203 -0
  37. package/dist/index.d.ts +53 -0
  38. package/dist/index.js +458 -0
  39. package/dist/noop.d.ts +2 -0
  40. package/dist/noop.js +55 -0
  41. package/dist/registry.d.ts +5 -0
  42. package/dist/registry.js +53 -0
  43. package/dist/types.d.ts +275 -0
  44. package/dist/types.js +2 -0
  45. package/index.node +0 -0
  46. package/package.json +81 -0
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2024 Memvid Inc.
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,244 @@
1
+ # @memvid/sdk
2
+
3
+ Single-file AI memory system for Node.js. Store documents, search with BM25 ranking, and run retrieval-augmented generation (RAG) queries from a portable `.mv2` file.
4
+
5
+ Built on Rust via N-API for native performance. No database setup, no network dependencies, no configuration files.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @memvid/sdk
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```typescript
16
+ import { use, create } from "@memvid/sdk";
17
+
18
+ // Create a new memory file
19
+ const mv = await use("basic", "notes.mv2", { mode: "auto" });
20
+
21
+ // Store a document
22
+ await mv.put({
23
+ title: "Project kickoff",
24
+ label: "meeting",
25
+ text: "Discussed timeline, assigned tasks to team members.",
26
+ metadata: { date: "2024-01-15" },
27
+ });
28
+
29
+ // Search by keyword
30
+ const results = await mv.find("timeline");
31
+ console.log(results.hits);
32
+
33
+ // Ask a question (retrieves relevant context)
34
+ const answer = await mv.ask("What was discussed in the kickoff?");
35
+ console.log(answer.context);
36
+
37
+ // Commit and close
38
+ await mv.seal();
39
+ ```
40
+
41
+ ## Core API
42
+
43
+ ### Opening a memory
44
+
45
+ ```typescript
46
+ const mv = await use(kind, path, options?)
47
+ ```
48
+
49
+ | Parameter | Type | Description |
50
+ |-----------|------|-------------|
51
+ | `kind` | `string` | Adapter type: `"basic"`, `"langchain"`, `"llamaindex"`, `"openai"`, `"crewai"`, `"vercel-ai"`, `"autogen"` |
52
+ | `path` | `string` | Path to `.mv2` file |
53
+ | `options.mode` | `string` | `"open"` (default), `"create"`, or `"auto"` |
54
+ | `options.enableLex` | `boolean` | Enable lexical index (default: `true`) |
55
+ | `options.enableVec` | `boolean` | Enable vector index (default: `true`) |
56
+ | `options.readOnly` | `boolean` | Open in read-only mode (default: `false`) |
57
+ | `options.apiKey` | `string` | Memvid API key for capacity beyond 1GB |
58
+
59
+ ### Storing documents
60
+
61
+ ```typescript
62
+ await mv.put({
63
+ title: "Document title",
64
+ label: "category",
65
+ text: "Document content...",
66
+ metadata: { key: "value" },
67
+ uri: "mv2://custom/path",
68
+ tags: ["tag1", "tag2"],
69
+ });
70
+ ```
71
+
72
+ ### Batch ingestion
73
+
74
+ For bulk imports, `putMany` processes documents in parallel:
75
+
76
+ ```typescript
77
+ const docs = [
78
+ { title: "Doc 1", text: "First document content..." },
79
+ { title: "Doc 2", text: "Second document content..." },
80
+ // ... thousands more
81
+ ];
82
+
83
+ const frameIds = await mv.putMany(docs, { compressionLevel: 3 });
84
+ console.log(`Ingested ${frameIds.length} documents`);
85
+ ```
86
+
87
+ ### Searching
88
+
89
+ ```typescript
90
+ const results = await mv.find(query, options?)
91
+ ```
92
+
93
+ | Option | Type | Description |
94
+ |--------|------|-------------|
95
+ | `k` | `number` | Number of results (default: `10`) |
96
+ | `snippetChars` | `number` | Snippet length (default: `240`) |
97
+ | `scope` | `string` | Filter by URI prefix |
98
+
99
+ ### Retrieval-augmented generation
100
+
101
+ ```typescript
102
+ const response = await mv.ask(question, options?)
103
+ ```
104
+
105
+ | Option | Type | Description |
106
+ |--------|------|-------------|
107
+ | `k` | `number` | Documents to retrieve (default: `6`) |
108
+ | `mode` | `string` | `"auto"`, `"lex"`, or `"sem"` |
109
+ | `model` | `string` | LLM for synthesis (e.g., `"openai:gpt-4o-mini"`) |
110
+ | `modelApiKey` | `string` | API key for the LLM provider |
111
+ | `contextOnly` | `boolean` | Skip synthesis, return context only |
112
+ | `returnSources` | `boolean` | Include source metadata in response |
113
+
114
+ ### Timeline queries
115
+
116
+ ```typescript
117
+ const entries = await mv.timeline({
118
+ limit: 50,
119
+ since: 1704067200, // Unix timestamp
120
+ reverse: true,
121
+ });
122
+ ```
123
+
124
+ ### Statistics
125
+
126
+ ```typescript
127
+ const stats = await mv.stats();
128
+ // { frameCount, sizeBytes, hasLexIndex, hasVecIndex, ... }
129
+ ```
130
+
131
+ ### File operations
132
+
133
+ ```typescript
134
+ // Commit pending changes
135
+ await mv.seal();
136
+
137
+ // Verify file integrity
138
+ import { verifyMemvid } from "@memvid/sdk";
139
+ const report = await verifyMemvid("notes.mv2", { deep: true });
140
+
141
+ // Repair indexes
142
+ import { doctorMemvid } from "@memvid/sdk";
143
+ await doctorMemvid("notes.mv2", { rebuildLexIndex: true });
144
+ ```
145
+
146
+ ## Framework adapters
147
+
148
+ Adapters expose framework-native tools when the corresponding dependency is installed.
149
+
150
+ ### LangChain
151
+
152
+ ```typescript
153
+ import { use } from "@memvid/sdk";
154
+
155
+ const mv = await use("langchain", "notes.mv2");
156
+ const tools = mv.tools; // StructuredTool instances for put/find/ask
157
+ ```
158
+
159
+ ### LlamaIndex
160
+
161
+ ```typescript
162
+ const mv = await use("llamaindex", "notes.mv2");
163
+ const queryEngine = mv.asQueryEngine();
164
+ ```
165
+
166
+ ### OpenAI function calling
167
+
168
+ ```typescript
169
+ const mv = await use("openai", "notes.mv2");
170
+ const functions = mv.functions; // JSON schemas for tool_calls
171
+ ```
172
+
173
+ ### Vercel AI SDK
174
+
175
+ ```typescript
176
+ const mv = await use("vercel-ai", "notes.mv2");
177
+ ```
178
+
179
+ ## Table extraction
180
+
181
+ Extract structured tables from PDFs:
182
+
183
+ ```typescript
184
+ const result = await mv.putPdfTables("report.pdf", { embedRows: true });
185
+ console.log(`Extracted ${result.tablesCount} tables`);
186
+
187
+ const tables = await mv.listTables();
188
+ const data = await mv.getTable(tables[0].tableId, { format: "json" });
189
+ ```
190
+
191
+ ## Error handling
192
+
193
+ Errors include a code prefix for programmatic handling:
194
+
195
+ | Code | Description |
196
+ |------|-------------|
197
+ | `MV001` | Storage capacity exceeded |
198
+ | `MV002` | Invalid ticket signature |
199
+ | `MV003` | Ticket replay detected |
200
+ | `MV004` | Lexical index not enabled |
201
+ | `MV005` | Time index missing |
202
+ | `MV006` | Verification failed |
203
+ | `MV007` | File locked by another process |
204
+
205
+ ```typescript
206
+ try {
207
+ await mv.put({ ... });
208
+ } catch (err) {
209
+ if (err.message.startsWith("MV001")) {
210
+ console.error("Out of storage capacity");
211
+ }
212
+ }
213
+ ```
214
+
215
+ ## Environment variables
216
+
217
+ | Variable | Description |
218
+ |----------|-------------|
219
+ | `MEMVID_API_KEY` | API key for capacity beyond free tier |
220
+ | `MEMVID_API_URL` | Control plane URL (for enterprise deployments) |
221
+ | `MEMVID_MODELS_DIR` | Path to embedding model cache |
222
+
223
+ ## Building from source
224
+
225
+ ```bash
226
+ # Install dependencies
227
+ pnpm install
228
+
229
+ # Build TypeScript
230
+ pnpm run build
231
+
232
+ # Build native module (requires Rust toolchain)
233
+ cargo build --release
234
+ cp target/release/libmemvid_node.dylib index.node # macOS
235
+ ```
236
+
237
+ ## Requirements
238
+
239
+ - Node.js 18+
240
+ - macOS (Apple Silicon or Intel), Linux (x64), or Windows (x64)
241
+
242
+ ## License
243
+
244
+ Apache-2.0. See [LICENSE](./LICENSE).
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const node_test_1 = require("node:test");
7
+ const strict_1 = __importDefault(require("node:assert/strict"));
8
+ const node_fs_1 = require("node:fs");
9
+ const node_path_1 = require("node:path");
10
+ const node_os_1 = require("node:os");
11
+ const index_1 = require("../index");
12
+ function tempPath(name) {
13
+ const dir = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), "memvid-sdk-node-"));
14
+ return { dir, file: (0, node_path_1.join)(dir, name) };
15
+ }
16
+ (0, node_test_1.test)("basic use() workflow", async (t) => {
17
+ const { dir, file } = tempPath("basic.mv2");
18
+ const mv = await (0, index_1.create)(file);
19
+ const frameId = await mv.put({
20
+ title: "hello",
21
+ label: "note",
22
+ metadata: { topic: "demo" },
23
+ text: "hello world",
24
+ });
25
+ strict_1.default.ok(frameId);
26
+ const stats = await mv.stats();
27
+ strict_1.default.equal(stats.frame_count, 1);
28
+ const results = (await mv.find("hello", { k: 1 }));
29
+ strict_1.default.ok(Array.isArray(results.hits));
30
+ strict_1.default.equal(results.hits.length, 1);
31
+ await strict_1.default.rejects(() => mv.applyTicket("{}"), /MV002/);
32
+ await strict_1.default.rejects(() => mv.ask("llm", { model: "unsupported", modelApiKey: "key" }), /unsupported model/);
33
+ await mv.seal();
34
+ const reopened = await (0, index_1.use)("basic", file);
35
+ const reopenedStats = await reopened.stats();
36
+ strict_1.default.equal(reopenedStats.frame_count, 1);
37
+ await reopened.seal();
38
+ t.after(() => {
39
+ (0, node_fs_1.rmSync)(dir, { recursive: true, force: true });
40
+ });
41
+ });
@@ -0,0 +1,23 @@
1
+ /**
2
+ * AutoGen adapter exposing Memvid core methods as AutoGen-compatible tools.
3
+ *
4
+ * AutoGen (Microsoft) uses a function-based tool pattern compatible with
5
+ * OpenAI's function calling API. This adapter provides three tools:
6
+ * - memvid_put: Store documents in memory
7
+ * - memvid_find: Search for relevant documents
8
+ * - memvid_ask: Query with RAG-style answer synthesis
9
+ *
10
+ * Usage:
11
+ * import { use } from "memvid-sdk";
12
+ *
13
+ * const mem = await use("autogen", "knowledge.mv2");
14
+ *
15
+ * // Access tools for AutoGen agents
16
+ * const tools = mem.tools; // Array of tool definitions
17
+ *
18
+ * // Tools follow OpenAI function calling format and can be used with
19
+ * // AutoGen's AssistantAgent or any OpenAI-compatible agent framework
20
+ *
21
+ * Note: AutoGen for Node.js uses OpenAI-compatible tool definitions.
22
+ */
23
+ export {};
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ /**
3
+ * AutoGen adapter exposing Memvid core methods as AutoGen-compatible tools.
4
+ *
5
+ * AutoGen (Microsoft) uses a function-based tool pattern compatible with
6
+ * OpenAI's function calling API. This adapter provides three tools:
7
+ * - memvid_put: Store documents in memory
8
+ * - memvid_find: Search for relevant documents
9
+ * - memvid_ask: Query with RAG-style answer synthesis
10
+ *
11
+ * Usage:
12
+ * import { use } from "memvid-sdk";
13
+ *
14
+ * const mem = await use("autogen", "knowledge.mv2");
15
+ *
16
+ * // Access tools for AutoGen agents
17
+ * const tools = mem.tools; // Array of tool definitions
18
+ *
19
+ * // Tools follow OpenAI function calling format and can be used with
20
+ * // AutoGen's AssistantAgent or any OpenAI-compatible agent framework
21
+ *
22
+ * Note: AutoGen for Node.js uses OpenAI-compatible tool definitions.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ const noop_1 = require("../noop");
26
+ const registry_1 = require("../registry");
27
+ const KIND = "autogen";
28
+ (0, registry_1.register)(KIND, async (core, _apiKey) => {
29
+ // AutoGen uses OpenAI-compatible function definitions
30
+ // We provide both the schema and the callable implementation
31
+ // Define the memvid_put tool
32
+ const memvidPutTool = {
33
+ type: "function",
34
+ function: {
35
+ name: "memvid_put",
36
+ description: "Store a document in Memvid memory for later retrieval.",
37
+ parameters: {
38
+ type: "object",
39
+ properties: {
40
+ title: {
41
+ type: "string",
42
+ description: "Title of the document",
43
+ },
44
+ label: {
45
+ type: "string",
46
+ description: "Category or label for the document",
47
+ },
48
+ text: {
49
+ type: "string",
50
+ description: "Text content to store",
51
+ },
52
+ metadata: {
53
+ type: "object",
54
+ description: "Optional key-value metadata",
55
+ additionalProperties: true,
56
+ },
57
+ },
58
+ required: ["title", "label", "text"],
59
+ },
60
+ },
61
+ callable: async (args) => {
62
+ const frameId = await core.put({
63
+ title: args.title,
64
+ label: args.label,
65
+ text: args.text,
66
+ metadata: args.metadata ?? {},
67
+ enable_embedding: true,
68
+ auto_tag: true,
69
+ extract_dates: true,
70
+ });
71
+ return `Document stored with frame_id: ${frameId}`;
72
+ },
73
+ };
74
+ // Define the memvid_find tool
75
+ const memvidFindTool = {
76
+ type: "function",
77
+ function: {
78
+ name: "memvid_find",
79
+ description: "Search Memvid memory for documents matching a query.",
80
+ parameters: {
81
+ type: "object",
82
+ properties: {
83
+ query: {
84
+ type: "string",
85
+ description: "Search query string",
86
+ },
87
+ top_k: {
88
+ type: "number",
89
+ description: "Number of results to return (default: 5)",
90
+ },
91
+ },
92
+ required: ["query"],
93
+ },
94
+ },
95
+ callable: async (args) => {
96
+ const query = args.query;
97
+ const topK = args.top_k ?? 5;
98
+ const response = (await core.find(query, { k: topK }));
99
+ const hits = response.hits ?? [];
100
+ if (hits.length === 0) {
101
+ return `No results found for query: '${query}'`;
102
+ }
103
+ const results = [];
104
+ for (let i = 0; i < hits.length; i++) {
105
+ const hit = hits[i];
106
+ const title = hit.title ?? "Untitled";
107
+ const snippet = (hit.text ?? hit.snippet ?? "").slice(0, 200);
108
+ const score = hit.score ?? 0;
109
+ results.push(`${i + 1}. [${title}] (score: ${score.toFixed(2)}): ${snippet}...`);
110
+ }
111
+ return `Found ${hits.length} results:\n${results.join("\n")}`;
112
+ },
113
+ };
114
+ // Define the memvid_ask tool
115
+ const memvidAskTool = {
116
+ type: "function",
117
+ function: {
118
+ name: "memvid_ask",
119
+ description: "Ask a question and get an answer synthesized from Memvid memory.",
120
+ parameters: {
121
+ type: "object",
122
+ properties: {
123
+ question: {
124
+ type: "string",
125
+ description: "Question to answer",
126
+ },
127
+ mode: {
128
+ type: "string",
129
+ description: "Search mode: 'auto', 'lex', or 'sem'",
130
+ enum: ["auto", "lex", "sem"],
131
+ },
132
+ },
133
+ required: ["question"],
134
+ },
135
+ },
136
+ callable: async (args) => {
137
+ const question = args.question;
138
+ const mode = args.mode ?? "auto";
139
+ const response = (await core.ask(question, { mode }));
140
+ const answer = response.answer ?? "No answer generated";
141
+ const sources = response.sources ?? [];
142
+ let result = `Answer: ${answer}`;
143
+ if (sources.length > 0) {
144
+ const sourceTitles = sources.slice(0, 3).map((s) => s.title ?? "Unknown");
145
+ result += `\n\nSources: ${sourceTitles.join(", ")}`;
146
+ }
147
+ return result;
148
+ },
149
+ };
150
+ const tools = [memvidPutTool, memvidFindTool, memvidAskTool];
151
+ // Also expose the raw functions for direct use
152
+ const functions = [
153
+ memvidPutTool.callable,
154
+ memvidFindTool.callable,
155
+ memvidAskTool.callable,
156
+ ];
157
+ return {
158
+ tools,
159
+ functions,
160
+ nodes: (0, noop_1.createNoOp)("autogen adapter nodes not provided", "memvid.adapters.autogen.nodes"),
161
+ asQueryEngine: null,
162
+ };
163
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const noop_1 = require("../noop");
4
+ const registry_1 = require("../registry");
5
+ const KIND = "basic";
6
+ (0, registry_1.register)(KIND, async () => ({
7
+ tools: (0, noop_1.createNoOp)("basic kind exposes no tools", "memvid.adapters.basic.tools"),
8
+ functions: [],
9
+ nodes: (0, noop_1.createNoOp)("basic kind exposes no nodes", "memvid.adapters.basic.nodes"),
10
+ asQueryEngine: null,
11
+ }));