mem0ai 2.0.0 → 2.0.2
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 +3 -0
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{module-KU56J2J6.mjs → module-QI3FML2A.mjs} +5 -4
- package/dist/module-QI3FML2A.mjs.map +1 -0
- package/dist/oss/index.d.mts +83 -6
- package/dist/oss/index.d.ts +83 -6
- package/dist/oss/index.js +107 -34
- package/dist/oss/index.js.map +1 -1
- package/dist/oss/index.mjs +105 -34
- package/dist/oss/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/module-KU56J2J6.mjs.map +0 -1
package/dist/oss/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { QdrantClient } from '@qdrant/js-client-rest';
|
|
2
3
|
|
|
3
4
|
interface Message {
|
|
4
5
|
role: string;
|
|
@@ -214,6 +215,26 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
214
215
|
} | undefined;
|
|
215
216
|
}>;
|
|
216
217
|
|
|
218
|
+
interface Entity {
|
|
219
|
+
userId?: string;
|
|
220
|
+
agentId?: string;
|
|
221
|
+
runId?: string;
|
|
222
|
+
}
|
|
223
|
+
interface AddMemoryOptions extends Entity {
|
|
224
|
+
metadata?: Record<string, any>;
|
|
225
|
+
filters?: SearchFilters;
|
|
226
|
+
prompt?: string;
|
|
227
|
+
}
|
|
228
|
+
interface SearchMemoryOptions extends Entity {
|
|
229
|
+
limit?: number;
|
|
230
|
+
filters?: SearchFilters;
|
|
231
|
+
}
|
|
232
|
+
interface GetAllMemoryOptions extends Entity {
|
|
233
|
+
limit?: number;
|
|
234
|
+
}
|
|
235
|
+
interface DeleteAllMemoryOptions extends Entity {
|
|
236
|
+
}
|
|
237
|
+
|
|
217
238
|
declare class Memory {
|
|
218
239
|
private config;
|
|
219
240
|
private customPrompt;
|
|
@@ -225,22 +246,22 @@ declare class Memory {
|
|
|
225
246
|
private apiVersion;
|
|
226
247
|
constructor(config?: Partial<MemoryConfig>);
|
|
227
248
|
static fromConfig(configDict: Record<string, any>): Memory;
|
|
228
|
-
add(messages: string | Message[],
|
|
249
|
+
add(messages: string | Message[], config: AddMemoryOptions): Promise<SearchResult>;
|
|
229
250
|
private addToVectorStore;
|
|
230
251
|
get(memoryId: string): Promise<MemoryItem | null>;
|
|
231
|
-
search(query: string,
|
|
252
|
+
search(query: string, config: SearchMemoryOptions): Promise<SearchResult>;
|
|
232
253
|
update(memoryId: string, data: string): Promise<{
|
|
233
254
|
message: string;
|
|
234
255
|
}>;
|
|
235
256
|
delete(memoryId: string): Promise<{
|
|
236
257
|
message: string;
|
|
237
258
|
}>;
|
|
238
|
-
deleteAll(
|
|
259
|
+
deleteAll(config: DeleteAllMemoryOptions): Promise<{
|
|
239
260
|
message: string;
|
|
240
261
|
}>;
|
|
241
262
|
history(memoryId: string): Promise<any[]>;
|
|
242
263
|
reset(): Promise<void>;
|
|
243
|
-
getAll(
|
|
264
|
+
getAll(config: GetAllMemoryOptions): Promise<SearchResult>;
|
|
244
265
|
private createMemory;
|
|
245
266
|
private updateMemory;
|
|
246
267
|
private deleteMemory;
|
|
@@ -321,9 +342,14 @@ interface VectorStore {
|
|
|
321
342
|
}
|
|
322
343
|
|
|
323
344
|
declare class MemoryVectorStore implements VectorStore {
|
|
324
|
-
private
|
|
345
|
+
private db;
|
|
325
346
|
private dimension;
|
|
347
|
+
private dbPath;
|
|
326
348
|
constructor(config: VectorStoreConfig);
|
|
349
|
+
private init;
|
|
350
|
+
private run;
|
|
351
|
+
private all;
|
|
352
|
+
private getOne;
|
|
327
353
|
private cosineSimilarity;
|
|
328
354
|
private filterVector;
|
|
329
355
|
insert(vectors: number[][], ids: string[], payloads: Record<string, any>[]): Promise<void>;
|
|
@@ -335,6 +361,57 @@ declare class MemoryVectorStore implements VectorStore {
|
|
|
335
361
|
list(filters?: SearchFilters, limit?: number): Promise<[VectorStoreResult[], number]>;
|
|
336
362
|
}
|
|
337
363
|
|
|
364
|
+
interface QdrantConfig extends VectorStoreConfig {
|
|
365
|
+
client?: QdrantClient;
|
|
366
|
+
host?: string;
|
|
367
|
+
port?: number;
|
|
368
|
+
path?: string;
|
|
369
|
+
url?: string;
|
|
370
|
+
apiKey?: string;
|
|
371
|
+
onDisk?: boolean;
|
|
372
|
+
collectionName: string;
|
|
373
|
+
embeddingModelDims: number;
|
|
374
|
+
}
|
|
375
|
+
declare class Qdrant implements VectorStore {
|
|
376
|
+
private client;
|
|
377
|
+
private readonly collectionName;
|
|
378
|
+
constructor(config: QdrantConfig);
|
|
379
|
+
private createCol;
|
|
380
|
+
private createFilter;
|
|
381
|
+
insert(vectors: number[][], ids: string[], payloads: Record<string, any>[]): Promise<void>;
|
|
382
|
+
search(query: number[], limit?: number, filters?: SearchFilters): Promise<VectorStoreResult[]>;
|
|
383
|
+
get(vectorId: string): Promise<VectorStoreResult | null>;
|
|
384
|
+
update(vectorId: string, vector: number[], payload: Record<string, any>): Promise<void>;
|
|
385
|
+
delete(vectorId: string): Promise<void>;
|
|
386
|
+
deleteCol(): Promise<void>;
|
|
387
|
+
list(filters?: SearchFilters, limit?: number): Promise<[VectorStoreResult[], number]>;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
interface RedisConfig extends VectorStoreConfig {
|
|
391
|
+
redisUrl: string;
|
|
392
|
+
collectionName: string;
|
|
393
|
+
embeddingModelDims: number;
|
|
394
|
+
username?: string;
|
|
395
|
+
password?: string;
|
|
396
|
+
}
|
|
397
|
+
declare class RedisDB implements VectorStore {
|
|
398
|
+
private client;
|
|
399
|
+
private readonly indexName;
|
|
400
|
+
private readonly indexPrefix;
|
|
401
|
+
private readonly schema;
|
|
402
|
+
constructor(config: RedisConfig);
|
|
403
|
+
private initialize;
|
|
404
|
+
private createIndex;
|
|
405
|
+
insert(vectors: number[][], ids: string[], payloads: Record<string, any>[]): Promise<void>;
|
|
406
|
+
search(query: number[], limit?: number, filters?: SearchFilters): Promise<VectorStoreResult[]>;
|
|
407
|
+
get(vectorId: string): Promise<VectorStoreResult | null>;
|
|
408
|
+
update(vectorId: string, vector: number[], payload: Record<string, any>): Promise<void>;
|
|
409
|
+
delete(vectorId: string): Promise<void>;
|
|
410
|
+
deleteCol(): Promise<void>;
|
|
411
|
+
list(filters?: SearchFilters, limit?: number): Promise<[VectorStoreResult[], number]>;
|
|
412
|
+
close(): Promise<void>;
|
|
413
|
+
}
|
|
414
|
+
|
|
338
415
|
declare class EmbedderFactory {
|
|
339
416
|
static create(provider: string, config: EmbeddingConfig): Embedder;
|
|
340
417
|
}
|
|
@@ -345,4 +422,4 @@ declare class VectorStoreFactory {
|
|
|
345
422
|
static create(provider: string, config: VectorStoreConfig): VectorStore;
|
|
346
423
|
}
|
|
347
424
|
|
|
348
|
-
export { AnthropicLLM, type Embedder, EmbedderFactory, type EmbeddingConfig, type GraphStoreConfig, GroqLLM, type LLM, type LLMConfig, LLMFactory, type LLMResponse, Memory, type MemoryConfig, MemoryConfigSchema, type MemoryItem, MemoryVectorStore, type Message, OpenAIEmbedder, OpenAILLM, OpenAIStructuredLLM, type SearchFilters, type SearchResult, type VectorStore, type VectorStoreConfig, VectorStoreFactory, type VectorStoreResult };
|
|
425
|
+
export { type AddMemoryOptions, AnthropicLLM, type DeleteAllMemoryOptions, type Embedder, EmbedderFactory, type EmbeddingConfig, type Entity, type GetAllMemoryOptions, type GraphStoreConfig, GroqLLM, type LLM, type LLMConfig, LLMFactory, type LLMResponse, Memory, type MemoryConfig, MemoryConfigSchema, type MemoryItem, MemoryVectorStore, type Message, OpenAIEmbedder, OpenAILLM, OpenAIStructuredLLM, Qdrant, RedisDB, type SearchFilters, type SearchMemoryOptions, type SearchResult, type VectorStore, type VectorStoreConfig, VectorStoreFactory, type VectorStoreResult };
|
package/dist/oss/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { QdrantClient } from '@qdrant/js-client-rest';
|
|
2
3
|
|
|
3
4
|
interface Message {
|
|
4
5
|
role: string;
|
|
@@ -214,6 +215,26 @@ declare const MemoryConfigSchema: z.ZodObject<{
|
|
|
214
215
|
} | undefined;
|
|
215
216
|
}>;
|
|
216
217
|
|
|
218
|
+
interface Entity {
|
|
219
|
+
userId?: string;
|
|
220
|
+
agentId?: string;
|
|
221
|
+
runId?: string;
|
|
222
|
+
}
|
|
223
|
+
interface AddMemoryOptions extends Entity {
|
|
224
|
+
metadata?: Record<string, any>;
|
|
225
|
+
filters?: SearchFilters;
|
|
226
|
+
prompt?: string;
|
|
227
|
+
}
|
|
228
|
+
interface SearchMemoryOptions extends Entity {
|
|
229
|
+
limit?: number;
|
|
230
|
+
filters?: SearchFilters;
|
|
231
|
+
}
|
|
232
|
+
interface GetAllMemoryOptions extends Entity {
|
|
233
|
+
limit?: number;
|
|
234
|
+
}
|
|
235
|
+
interface DeleteAllMemoryOptions extends Entity {
|
|
236
|
+
}
|
|
237
|
+
|
|
217
238
|
declare class Memory {
|
|
218
239
|
private config;
|
|
219
240
|
private customPrompt;
|
|
@@ -225,22 +246,22 @@ declare class Memory {
|
|
|
225
246
|
private apiVersion;
|
|
226
247
|
constructor(config?: Partial<MemoryConfig>);
|
|
227
248
|
static fromConfig(configDict: Record<string, any>): Memory;
|
|
228
|
-
add(messages: string | Message[],
|
|
249
|
+
add(messages: string | Message[], config: AddMemoryOptions): Promise<SearchResult>;
|
|
229
250
|
private addToVectorStore;
|
|
230
251
|
get(memoryId: string): Promise<MemoryItem | null>;
|
|
231
|
-
search(query: string,
|
|
252
|
+
search(query: string, config: SearchMemoryOptions): Promise<SearchResult>;
|
|
232
253
|
update(memoryId: string, data: string): Promise<{
|
|
233
254
|
message: string;
|
|
234
255
|
}>;
|
|
235
256
|
delete(memoryId: string): Promise<{
|
|
236
257
|
message: string;
|
|
237
258
|
}>;
|
|
238
|
-
deleteAll(
|
|
259
|
+
deleteAll(config: DeleteAllMemoryOptions): Promise<{
|
|
239
260
|
message: string;
|
|
240
261
|
}>;
|
|
241
262
|
history(memoryId: string): Promise<any[]>;
|
|
242
263
|
reset(): Promise<void>;
|
|
243
|
-
getAll(
|
|
264
|
+
getAll(config: GetAllMemoryOptions): Promise<SearchResult>;
|
|
244
265
|
private createMemory;
|
|
245
266
|
private updateMemory;
|
|
246
267
|
private deleteMemory;
|
|
@@ -321,9 +342,14 @@ interface VectorStore {
|
|
|
321
342
|
}
|
|
322
343
|
|
|
323
344
|
declare class MemoryVectorStore implements VectorStore {
|
|
324
|
-
private
|
|
345
|
+
private db;
|
|
325
346
|
private dimension;
|
|
347
|
+
private dbPath;
|
|
326
348
|
constructor(config: VectorStoreConfig);
|
|
349
|
+
private init;
|
|
350
|
+
private run;
|
|
351
|
+
private all;
|
|
352
|
+
private getOne;
|
|
327
353
|
private cosineSimilarity;
|
|
328
354
|
private filterVector;
|
|
329
355
|
insert(vectors: number[][], ids: string[], payloads: Record<string, any>[]): Promise<void>;
|
|
@@ -335,6 +361,57 @@ declare class MemoryVectorStore implements VectorStore {
|
|
|
335
361
|
list(filters?: SearchFilters, limit?: number): Promise<[VectorStoreResult[], number]>;
|
|
336
362
|
}
|
|
337
363
|
|
|
364
|
+
interface QdrantConfig extends VectorStoreConfig {
|
|
365
|
+
client?: QdrantClient;
|
|
366
|
+
host?: string;
|
|
367
|
+
port?: number;
|
|
368
|
+
path?: string;
|
|
369
|
+
url?: string;
|
|
370
|
+
apiKey?: string;
|
|
371
|
+
onDisk?: boolean;
|
|
372
|
+
collectionName: string;
|
|
373
|
+
embeddingModelDims: number;
|
|
374
|
+
}
|
|
375
|
+
declare class Qdrant implements VectorStore {
|
|
376
|
+
private client;
|
|
377
|
+
private readonly collectionName;
|
|
378
|
+
constructor(config: QdrantConfig);
|
|
379
|
+
private createCol;
|
|
380
|
+
private createFilter;
|
|
381
|
+
insert(vectors: number[][], ids: string[], payloads: Record<string, any>[]): Promise<void>;
|
|
382
|
+
search(query: number[], limit?: number, filters?: SearchFilters): Promise<VectorStoreResult[]>;
|
|
383
|
+
get(vectorId: string): Promise<VectorStoreResult | null>;
|
|
384
|
+
update(vectorId: string, vector: number[], payload: Record<string, any>): Promise<void>;
|
|
385
|
+
delete(vectorId: string): Promise<void>;
|
|
386
|
+
deleteCol(): Promise<void>;
|
|
387
|
+
list(filters?: SearchFilters, limit?: number): Promise<[VectorStoreResult[], number]>;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
interface RedisConfig extends VectorStoreConfig {
|
|
391
|
+
redisUrl: string;
|
|
392
|
+
collectionName: string;
|
|
393
|
+
embeddingModelDims: number;
|
|
394
|
+
username?: string;
|
|
395
|
+
password?: string;
|
|
396
|
+
}
|
|
397
|
+
declare class RedisDB implements VectorStore {
|
|
398
|
+
private client;
|
|
399
|
+
private readonly indexName;
|
|
400
|
+
private readonly indexPrefix;
|
|
401
|
+
private readonly schema;
|
|
402
|
+
constructor(config: RedisConfig);
|
|
403
|
+
private initialize;
|
|
404
|
+
private createIndex;
|
|
405
|
+
insert(vectors: number[][], ids: string[], payloads: Record<string, any>[]): Promise<void>;
|
|
406
|
+
search(query: number[], limit?: number, filters?: SearchFilters): Promise<VectorStoreResult[]>;
|
|
407
|
+
get(vectorId: string): Promise<VectorStoreResult | null>;
|
|
408
|
+
update(vectorId: string, vector: number[], payload: Record<string, any>): Promise<void>;
|
|
409
|
+
delete(vectorId: string): Promise<void>;
|
|
410
|
+
deleteCol(): Promise<void>;
|
|
411
|
+
list(filters?: SearchFilters, limit?: number): Promise<[VectorStoreResult[], number]>;
|
|
412
|
+
close(): Promise<void>;
|
|
413
|
+
}
|
|
414
|
+
|
|
338
415
|
declare class EmbedderFactory {
|
|
339
416
|
static create(provider: string, config: EmbeddingConfig): Embedder;
|
|
340
417
|
}
|
|
@@ -345,4 +422,4 @@ declare class VectorStoreFactory {
|
|
|
345
422
|
static create(provider: string, config: VectorStoreConfig): VectorStore;
|
|
346
423
|
}
|
|
347
424
|
|
|
348
|
-
export { AnthropicLLM, type Embedder, EmbedderFactory, type EmbeddingConfig, type GraphStoreConfig, GroqLLM, type LLM, type LLMConfig, LLMFactory, type LLMResponse, Memory, type MemoryConfig, MemoryConfigSchema, type MemoryItem, MemoryVectorStore, type Message, OpenAIEmbedder, OpenAILLM, OpenAIStructuredLLM, type SearchFilters, type SearchResult, type VectorStore, type VectorStoreConfig, VectorStoreFactory, type VectorStoreResult };
|
|
425
|
+
export { type AddMemoryOptions, AnthropicLLM, type DeleteAllMemoryOptions, type Embedder, EmbedderFactory, type EmbeddingConfig, type Entity, type GetAllMemoryOptions, type GraphStoreConfig, GroqLLM, type LLM, type LLMConfig, LLMFactory, type LLMResponse, Memory, type MemoryConfig, MemoryConfigSchema, type MemoryItem, MemoryVectorStore, type Message, OpenAIEmbedder, OpenAILLM, OpenAIStructuredLLM, Qdrant, RedisDB, type SearchFilters, type SearchMemoryOptions, type SearchResult, type VectorStore, type VectorStoreConfig, VectorStoreFactory, type VectorStoreResult };
|
package/dist/oss/index.js
CHANGED
|
@@ -40,6 +40,8 @@ __export(index_exports, {
|
|
|
40
40
|
OpenAIEmbedder: () => OpenAIEmbedder,
|
|
41
41
|
OpenAILLM: () => OpenAILLM,
|
|
42
42
|
OpenAIStructuredLLM: () => OpenAIStructuredLLM,
|
|
43
|
+
Qdrant: () => Qdrant,
|
|
44
|
+
RedisDB: () => RedisDB,
|
|
43
45
|
VectorStoreFactory: () => VectorStoreFactory
|
|
44
46
|
});
|
|
45
47
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -249,10 +251,50 @@ var GroqLLM = class {
|
|
|
249
251
|
};
|
|
250
252
|
|
|
251
253
|
// src/oss/src/vector_stores/memory.ts
|
|
254
|
+
var import_sqlite3 = __toESM(require("sqlite3"));
|
|
255
|
+
var import_path = __toESM(require("path"));
|
|
252
256
|
var MemoryVectorStore = class {
|
|
253
257
|
constructor(config) {
|
|
254
|
-
this.vectors = /* @__PURE__ */ new Map();
|
|
255
258
|
this.dimension = config.dimension || 1536;
|
|
259
|
+
this.dbPath = import_path.default.join(process.cwd(), "vector_store.db");
|
|
260
|
+
if (config.dbPath) {
|
|
261
|
+
this.dbPath = config.dbPath;
|
|
262
|
+
}
|
|
263
|
+
this.db = new import_sqlite3.default.Database(this.dbPath);
|
|
264
|
+
this.init().catch(console.error);
|
|
265
|
+
}
|
|
266
|
+
async init() {
|
|
267
|
+
await this.run(`
|
|
268
|
+
CREATE TABLE IF NOT EXISTS vectors (
|
|
269
|
+
id TEXT PRIMARY KEY,
|
|
270
|
+
vector BLOB NOT NULL,
|
|
271
|
+
payload TEXT NOT NULL
|
|
272
|
+
)
|
|
273
|
+
`);
|
|
274
|
+
}
|
|
275
|
+
async run(sql, params = []) {
|
|
276
|
+
return new Promise((resolve, reject) => {
|
|
277
|
+
this.db.run(sql, params, (err) => {
|
|
278
|
+
if (err) reject(err);
|
|
279
|
+
else resolve();
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
async all(sql, params = []) {
|
|
284
|
+
return new Promise((resolve, reject) => {
|
|
285
|
+
this.db.all(sql, params, (err, rows) => {
|
|
286
|
+
if (err) reject(err);
|
|
287
|
+
else resolve(rows);
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
async getOne(sql, params = []) {
|
|
292
|
+
return new Promise((resolve, reject) => {
|
|
293
|
+
this.db.get(sql, params, (err, row) => {
|
|
294
|
+
if (err) reject(err);
|
|
295
|
+
else resolve(row);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
256
298
|
}
|
|
257
299
|
cosineSimilarity(a, b) {
|
|
258
300
|
let dotProduct = 0;
|
|
@@ -278,11 +320,11 @@ var MemoryVectorStore = class {
|
|
|
278
320
|
`Vector dimension mismatch. Expected ${this.dimension}, got ${vectors[i].length}`
|
|
279
321
|
);
|
|
280
322
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
323
|
+
const vectorBuffer = Buffer.from(new Float32Array(vectors[i]).buffer);
|
|
324
|
+
await this.run(
|
|
325
|
+
`INSERT OR REPLACE INTO vectors (id, vector, payload) VALUES (?, ?, ?)`,
|
|
326
|
+
[ids[i], vectorBuffer, JSON.stringify(payloads[i])]
|
|
327
|
+
);
|
|
286
328
|
}
|
|
287
329
|
}
|
|
288
330
|
async search(query, limit = 10, filters) {
|
|
@@ -291,13 +333,21 @@ var MemoryVectorStore = class {
|
|
|
291
333
|
`Query dimension mismatch. Expected ${this.dimension}, got ${query.length}`
|
|
292
334
|
);
|
|
293
335
|
}
|
|
336
|
+
const rows = await this.all(`SELECT * FROM vectors`);
|
|
294
337
|
const results = [];
|
|
295
|
-
for (const
|
|
296
|
-
|
|
297
|
-
|
|
338
|
+
for (const row of rows) {
|
|
339
|
+
const vector = new Float32Array(row.vector.buffer);
|
|
340
|
+
const payload = JSON.parse(row.payload);
|
|
341
|
+
const memoryVector = {
|
|
342
|
+
id: row.id,
|
|
343
|
+
vector: Array.from(vector),
|
|
344
|
+
payload
|
|
345
|
+
};
|
|
346
|
+
if (this.filterVector(memoryVector, filters)) {
|
|
347
|
+
const score = this.cosineSimilarity(query, Array.from(vector));
|
|
298
348
|
results.push({
|
|
299
|
-
id:
|
|
300
|
-
payload:
|
|
349
|
+
id: memoryVector.id,
|
|
350
|
+
payload: memoryVector.payload,
|
|
301
351
|
score
|
|
302
352
|
});
|
|
303
353
|
}
|
|
@@ -306,11 +356,14 @@ var MemoryVectorStore = class {
|
|
|
306
356
|
return results.slice(0, limit);
|
|
307
357
|
}
|
|
308
358
|
async get(vectorId) {
|
|
309
|
-
const
|
|
310
|
-
|
|
359
|
+
const row = await this.getOne(`SELECT * FROM vectors WHERE id = ?`, [
|
|
360
|
+
vectorId
|
|
361
|
+
]);
|
|
362
|
+
if (!row) return null;
|
|
363
|
+
const payload = JSON.parse(row.payload);
|
|
311
364
|
return {
|
|
312
|
-
id:
|
|
313
|
-
payload
|
|
365
|
+
id: row.id,
|
|
366
|
+
payload
|
|
314
367
|
};
|
|
315
368
|
}
|
|
316
369
|
async update(vectorId, vector, payload) {
|
|
@@ -319,27 +372,34 @@ var MemoryVectorStore = class {
|
|
|
319
372
|
`Vector dimension mismatch. Expected ${this.dimension}, got ${vector.length}`
|
|
320
373
|
);
|
|
321
374
|
}
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
});
|
|
375
|
+
const vectorBuffer = Buffer.from(new Float32Array(vector).buffer);
|
|
376
|
+
await this.run(`UPDATE vectors SET vector = ?, payload = ? WHERE id = ?`, [
|
|
377
|
+
vectorBuffer,
|
|
378
|
+
JSON.stringify(payload),
|
|
379
|
+
vectorId
|
|
380
|
+
]);
|
|
329
381
|
}
|
|
330
382
|
async delete(vectorId) {
|
|
331
|
-
this.vectors
|
|
383
|
+
await this.run(`DELETE FROM vectors WHERE id = ?`, [vectorId]);
|
|
332
384
|
}
|
|
333
385
|
async deleteCol() {
|
|
334
|
-
this.vectors
|
|
386
|
+
await this.run(`DROP TABLE IF EXISTS vectors`);
|
|
387
|
+
await this.init();
|
|
335
388
|
}
|
|
336
389
|
async list(filters, limit = 100) {
|
|
390
|
+
const rows = await this.all(`SELECT * FROM vectors`);
|
|
337
391
|
const results = [];
|
|
338
|
-
for (const
|
|
339
|
-
|
|
392
|
+
for (const row of rows) {
|
|
393
|
+
const payload = JSON.parse(row.payload);
|
|
394
|
+
const memoryVector = {
|
|
395
|
+
id: row.id,
|
|
396
|
+
vector: Array.from(new Float32Array(row.vector.buffer)),
|
|
397
|
+
payload
|
|
398
|
+
};
|
|
399
|
+
if (this.filterVector(memoryVector, filters)) {
|
|
340
400
|
results.push({
|
|
341
|
-
id:
|
|
342
|
-
payload:
|
|
401
|
+
id: memoryVector.id,
|
|
402
|
+
payload: memoryVector.payload
|
|
343
403
|
});
|
|
344
404
|
}
|
|
345
405
|
}
|
|
@@ -1217,10 +1277,10 @@ function removeCodeBlocks(text) {
|
|
|
1217
1277
|
}
|
|
1218
1278
|
|
|
1219
1279
|
// src/oss/src/storage/SQLiteManager.ts
|
|
1220
|
-
var
|
|
1280
|
+
var import_sqlite32 = __toESM(require("sqlite3"));
|
|
1221
1281
|
var SQLiteManager = class {
|
|
1222
1282
|
constructor(dbPath) {
|
|
1223
|
-
this.db = new
|
|
1283
|
+
this.db = new import_sqlite32.default.Database(dbPath);
|
|
1224
1284
|
this.init().catch(console.error);
|
|
1225
1285
|
}
|
|
1226
1286
|
async init() {
|
|
@@ -1377,7 +1437,15 @@ var Memory = class _Memory {
|
|
|
1377
1437
|
throw e;
|
|
1378
1438
|
}
|
|
1379
1439
|
}
|
|
1380
|
-
async add(messages,
|
|
1440
|
+
async add(messages, config) {
|
|
1441
|
+
const {
|
|
1442
|
+
userId,
|
|
1443
|
+
agentId,
|
|
1444
|
+
runId,
|
|
1445
|
+
metadata = {},
|
|
1446
|
+
filters = {},
|
|
1447
|
+
prompt
|
|
1448
|
+
} = config;
|
|
1381
1449
|
if (userId) filters.userId = metadata.userId = userId;
|
|
1382
1450
|
if (agentId) filters.agentId = metadata.agentId = agentId;
|
|
1383
1451
|
if (runId) filters.runId = metadata.runId = runId;
|
|
@@ -1520,7 +1588,8 @@ ${parsedMessages}`] : getFactRetrievalMessages(parsedMessages);
|
|
|
1520
1588
|
}
|
|
1521
1589
|
return { ...memoryItem, ...filters };
|
|
1522
1590
|
}
|
|
1523
|
-
async search(query,
|
|
1591
|
+
async search(query, config) {
|
|
1592
|
+
const { userId, agentId, runId, limit = 100, filters = {} } = config;
|
|
1524
1593
|
if (userId) filters.userId = userId;
|
|
1525
1594
|
if (agentId) filters.agentId = agentId;
|
|
1526
1595
|
if (runId) filters.runId = runId;
|
|
@@ -1567,7 +1636,8 @@ ${parsedMessages}`] : getFactRetrievalMessages(parsedMessages);
|
|
|
1567
1636
|
await this.deleteMemory(memoryId);
|
|
1568
1637
|
return { message: "Memory deleted successfully!" };
|
|
1569
1638
|
}
|
|
1570
|
-
async deleteAll(
|
|
1639
|
+
async deleteAll(config) {
|
|
1640
|
+
const { userId, agentId, runId } = config;
|
|
1571
1641
|
const filters = {};
|
|
1572
1642
|
if (userId) filters.userId = userId;
|
|
1573
1643
|
if (agentId) filters.agentId = agentId;
|
|
@@ -1594,7 +1664,8 @@ ${parsedMessages}`] : getFactRetrievalMessages(parsedMessages);
|
|
|
1594
1664
|
this.config.vectorStore.config
|
|
1595
1665
|
);
|
|
1596
1666
|
}
|
|
1597
|
-
async getAll(
|
|
1667
|
+
async getAll(config) {
|
|
1668
|
+
const { userId, agentId, runId, limit = 100 } = config;
|
|
1598
1669
|
const filters = {};
|
|
1599
1670
|
if (userId) filters.userId = userId;
|
|
1600
1671
|
if (agentId) filters.agentId = agentId;
|
|
@@ -1706,6 +1777,8 @@ ${parsedMessages}`] : getFactRetrievalMessages(parsedMessages);
|
|
|
1706
1777
|
OpenAIEmbedder,
|
|
1707
1778
|
OpenAILLM,
|
|
1708
1779
|
OpenAIStructuredLLM,
|
|
1780
|
+
Qdrant,
|
|
1781
|
+
RedisDB,
|
|
1709
1782
|
VectorStoreFactory
|
|
1710
1783
|
});
|
|
1711
1784
|
//# sourceMappingURL=index.js.map
|