@prmichaelsen/remember-mcp 1.0.4 → 1.0.6
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/dist/server-factory.js +105 -107
- package/dist/server.js +105 -107
- package/package.json +1 -1
- package/src/tools/create-memory.ts +5 -2
- package/src/tools/create-relationship.ts +5 -2
- package/src/tools/search-memory.ts +10 -9
package/dist/server-factory.js
CHANGED
|
@@ -1393,7 +1393,9 @@ async function handleCreateMemory(args, userId, context) {
|
|
|
1393
1393
|
base_weight: args.weight ?? 0.5,
|
|
1394
1394
|
computed_weight: args.weight ?? 0.5
|
|
1395
1395
|
};
|
|
1396
|
-
const result = await collection.data.insert(
|
|
1396
|
+
const result = await collection.data.insert({
|
|
1397
|
+
properties: memory
|
|
1398
|
+
});
|
|
1397
1399
|
logger.info("Memory created successfully", { memoryId: result, userId });
|
|
1398
1400
|
const response = {
|
|
1399
1401
|
memory_id: result,
|
|
@@ -1407,103 +1409,6 @@ async function handleCreateMemory(args, userId, context) {
|
|
|
1407
1409
|
}
|
|
1408
1410
|
}
|
|
1409
1411
|
|
|
1410
|
-
// src/utils/weaviate-filters.ts
|
|
1411
|
-
import { Filters } from "weaviate-client";
|
|
1412
|
-
function buildCombinedSearchFilters(collection, filters) {
|
|
1413
|
-
const memoryFilters = buildDocTypeFilters(collection, "memory", filters);
|
|
1414
|
-
const relationshipFilters = buildDocTypeFilters(collection, "relationship", filters);
|
|
1415
|
-
const validFilters = [memoryFilters, relationshipFilters].filter((f) => f !== void 0 && f !== null);
|
|
1416
|
-
if (validFilters.length === 0) {
|
|
1417
|
-
return void 0;
|
|
1418
|
-
} else if (validFilters.length === 1) {
|
|
1419
|
-
return validFilters[0];
|
|
1420
|
-
} else {
|
|
1421
|
-
return combineFiltersWithOr(validFilters);
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
function buildDocTypeFilters(collection, docType, filters) {
|
|
1425
|
-
const filterList = [];
|
|
1426
|
-
filterList.push(
|
|
1427
|
-
collection.filter.byProperty("doc_type").equal(docType)
|
|
1428
|
-
);
|
|
1429
|
-
if (docType === "memory" && filters?.types && filters.types.length > 0) {
|
|
1430
|
-
if (filters.types.length === 1) {
|
|
1431
|
-
filterList.push(
|
|
1432
|
-
collection.filter.byProperty("type").equal(filters.types[0])
|
|
1433
|
-
);
|
|
1434
|
-
} else {
|
|
1435
|
-
filterList.push(
|
|
1436
|
-
collection.filter.byProperty("type").containsAny(filters.types)
|
|
1437
|
-
);
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
if (filters?.weight_min !== void 0) {
|
|
1441
|
-
filterList.push(
|
|
1442
|
-
collection.filter.byProperty("weight").greaterThanOrEqual(filters.weight_min)
|
|
1443
|
-
);
|
|
1444
|
-
}
|
|
1445
|
-
if (filters?.weight_max !== void 0) {
|
|
1446
|
-
filterList.push(
|
|
1447
|
-
collection.filter.byProperty("weight").lessThanOrEqual(filters.weight_max)
|
|
1448
|
-
);
|
|
1449
|
-
}
|
|
1450
|
-
if (filters?.trust_min !== void 0) {
|
|
1451
|
-
filterList.push(
|
|
1452
|
-
collection.filter.byProperty("trust").greaterThanOrEqual(filters.trust_min)
|
|
1453
|
-
);
|
|
1454
|
-
}
|
|
1455
|
-
if (filters?.trust_max !== void 0) {
|
|
1456
|
-
filterList.push(
|
|
1457
|
-
collection.filter.byProperty("trust").lessThanOrEqual(filters.trust_max)
|
|
1458
|
-
);
|
|
1459
|
-
}
|
|
1460
|
-
if (filters?.date_from) {
|
|
1461
|
-
filterList.push(
|
|
1462
|
-
collection.filter.byProperty("created_at").greaterThanOrEqual(new Date(filters.date_from))
|
|
1463
|
-
);
|
|
1464
|
-
}
|
|
1465
|
-
if (filters?.date_to) {
|
|
1466
|
-
filterList.push(
|
|
1467
|
-
collection.filter.byProperty("created_at").lessThanOrEqual(new Date(filters.date_to))
|
|
1468
|
-
);
|
|
1469
|
-
}
|
|
1470
|
-
if (filters?.tags && filters.tags.length > 0) {
|
|
1471
|
-
if (filters.tags.length === 1) {
|
|
1472
|
-
filterList.push(
|
|
1473
|
-
collection.filter.byProperty("tags").containsAny([filters.tags[0]])
|
|
1474
|
-
);
|
|
1475
|
-
} else {
|
|
1476
|
-
filterList.push(
|
|
1477
|
-
collection.filter.byProperty("tags").containsAny(filters.tags)
|
|
1478
|
-
);
|
|
1479
|
-
}
|
|
1480
|
-
}
|
|
1481
|
-
return combineFiltersWithAnd(filterList);
|
|
1482
|
-
}
|
|
1483
|
-
function buildMemoryOnlyFilters(collection, filters) {
|
|
1484
|
-
return buildDocTypeFilters(collection, "memory", filters);
|
|
1485
|
-
}
|
|
1486
|
-
function combineFiltersWithAnd(filters) {
|
|
1487
|
-
const validFilters = filters.filter((f) => f !== void 0 && f !== null);
|
|
1488
|
-
if (validFilters.length === 0) {
|
|
1489
|
-
return void 0;
|
|
1490
|
-
}
|
|
1491
|
-
if (validFilters.length === 1) {
|
|
1492
|
-
return validFilters[0];
|
|
1493
|
-
}
|
|
1494
|
-
return Filters.and(...validFilters);
|
|
1495
|
-
}
|
|
1496
|
-
function combineFiltersWithOr(filters) {
|
|
1497
|
-
const validFilters = filters.filter((f) => f !== void 0 && f !== null);
|
|
1498
|
-
if (validFilters.length === 0) {
|
|
1499
|
-
return void 0;
|
|
1500
|
-
}
|
|
1501
|
-
if (validFilters.length === 1) {
|
|
1502
|
-
return validFilters[0];
|
|
1503
|
-
}
|
|
1504
|
-
return Filters.or(...validFilters);
|
|
1505
|
-
}
|
|
1506
|
-
|
|
1507
1412
|
// src/tools/search-memory.ts
|
|
1508
1413
|
var searchMemoryTool = {
|
|
1509
1414
|
name: "remember_search_memory",
|
|
@@ -1607,19 +1512,15 @@ async function handleSearchMemory(args, userId) {
|
|
|
1607
1512
|
const alpha = args.alpha ?? 0.7;
|
|
1608
1513
|
const limit = args.limit ?? 10;
|
|
1609
1514
|
const offset = args.offset ?? 0;
|
|
1610
|
-
const filters = includeRelationships ? buildCombinedSearchFilters(collection, args.filters) : buildMemoryOnlyFilters(collection, args.filters);
|
|
1611
1515
|
const searchOptions = {
|
|
1612
1516
|
alpha,
|
|
1613
1517
|
limit: limit + offset
|
|
1614
1518
|
// Get extra for offset
|
|
1615
1519
|
};
|
|
1616
|
-
if (filters) {
|
|
1617
|
-
searchOptions.filters = filters;
|
|
1618
|
-
}
|
|
1619
1520
|
logger.info("Weaviate query", {
|
|
1620
1521
|
query: args.query,
|
|
1621
|
-
searchOptions: JSON.stringify(searchOptions, null, 2)
|
|
1622
|
-
hasFilters: !!filters
|
|
1522
|
+
searchOptions: JSON.stringify(searchOptions, null, 2)
|
|
1523
|
+
// hasFilters: !!filters,
|
|
1623
1524
|
});
|
|
1624
1525
|
const results = await collection.query.hybrid(args.query, searchOptions);
|
|
1625
1526
|
const paginatedResults = results.objects.slice(offset);
|
|
@@ -1652,8 +1553,9 @@ async function handleSearchMemory(args, userId) {
|
|
|
1652
1553
|
});
|
|
1653
1554
|
return JSON.stringify(searchResult, null, 2);
|
|
1654
1555
|
} catch (error) {
|
|
1655
|
-
|
|
1656
|
-
|
|
1556
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1557
|
+
logger.error("Failed to search memories:", { error: errorMessage, userId, query: args.query });
|
|
1558
|
+
throw new Error(`Failed to search memories: ${errorMessage}`);
|
|
1657
1559
|
}
|
|
1658
1560
|
}
|
|
1659
1561
|
|
|
@@ -2012,6 +1914,100 @@ async function handleFindSimilar(args, userId) {
|
|
|
2012
1914
|
}
|
|
2013
1915
|
}
|
|
2014
1916
|
|
|
1917
|
+
// src/utils/weaviate-filters.ts
|
|
1918
|
+
import { Filters } from "weaviate-client";
|
|
1919
|
+
function buildCombinedSearchFilters(collection, filters) {
|
|
1920
|
+
const memoryFilters = buildDocTypeFilters(collection, "memory", filters);
|
|
1921
|
+
const relationshipFilters = buildDocTypeFilters(collection, "relationship", filters);
|
|
1922
|
+
const validFilters = [memoryFilters, relationshipFilters].filter((f) => f !== void 0 && f !== null);
|
|
1923
|
+
if (validFilters.length === 0) {
|
|
1924
|
+
return void 0;
|
|
1925
|
+
} else if (validFilters.length === 1) {
|
|
1926
|
+
return validFilters[0];
|
|
1927
|
+
} else {
|
|
1928
|
+
return combineFiltersWithOr(validFilters);
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
function buildDocTypeFilters(collection, docType, filters) {
|
|
1932
|
+
const filterList = [];
|
|
1933
|
+
filterList.push(
|
|
1934
|
+
collection.filter.byProperty("doc_type").equal(docType)
|
|
1935
|
+
);
|
|
1936
|
+
if (docType === "memory" && filters?.types && filters.types.length > 0) {
|
|
1937
|
+
if (filters.types.length === 1) {
|
|
1938
|
+
filterList.push(
|
|
1939
|
+
collection.filter.byProperty("type").equal(filters.types[0])
|
|
1940
|
+
);
|
|
1941
|
+
} else {
|
|
1942
|
+
filterList.push(
|
|
1943
|
+
collection.filter.byProperty("type").containsAny(filters.types)
|
|
1944
|
+
);
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
if (filters?.weight_min !== void 0) {
|
|
1948
|
+
filterList.push(
|
|
1949
|
+
collection.filter.byProperty("weight").greaterThanOrEqual(filters.weight_min)
|
|
1950
|
+
);
|
|
1951
|
+
}
|
|
1952
|
+
if (filters?.weight_max !== void 0) {
|
|
1953
|
+
filterList.push(
|
|
1954
|
+
collection.filter.byProperty("weight").lessThanOrEqual(filters.weight_max)
|
|
1955
|
+
);
|
|
1956
|
+
}
|
|
1957
|
+
if (filters?.trust_min !== void 0) {
|
|
1958
|
+
filterList.push(
|
|
1959
|
+
collection.filter.byProperty("trust").greaterThanOrEqual(filters.trust_min)
|
|
1960
|
+
);
|
|
1961
|
+
}
|
|
1962
|
+
if (filters?.trust_max !== void 0) {
|
|
1963
|
+
filterList.push(
|
|
1964
|
+
collection.filter.byProperty("trust").lessThanOrEqual(filters.trust_max)
|
|
1965
|
+
);
|
|
1966
|
+
}
|
|
1967
|
+
if (filters?.date_from) {
|
|
1968
|
+
filterList.push(
|
|
1969
|
+
collection.filter.byProperty("created_at").greaterThanOrEqual(new Date(filters.date_from))
|
|
1970
|
+
);
|
|
1971
|
+
}
|
|
1972
|
+
if (filters?.date_to) {
|
|
1973
|
+
filterList.push(
|
|
1974
|
+
collection.filter.byProperty("created_at").lessThanOrEqual(new Date(filters.date_to))
|
|
1975
|
+
);
|
|
1976
|
+
}
|
|
1977
|
+
if (filters?.tags && filters.tags.length > 0) {
|
|
1978
|
+
if (filters.tags.length === 1) {
|
|
1979
|
+
filterList.push(
|
|
1980
|
+
collection.filter.byProperty("tags").containsAny([filters.tags[0]])
|
|
1981
|
+
);
|
|
1982
|
+
} else {
|
|
1983
|
+
filterList.push(
|
|
1984
|
+
collection.filter.byProperty("tags").containsAny(filters.tags)
|
|
1985
|
+
);
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
return combineFiltersWithAnd(filterList);
|
|
1989
|
+
}
|
|
1990
|
+
function combineFiltersWithAnd(filters) {
|
|
1991
|
+
const validFilters = filters.filter((f) => f !== void 0 && f !== null);
|
|
1992
|
+
if (validFilters.length === 0) {
|
|
1993
|
+
return void 0;
|
|
1994
|
+
}
|
|
1995
|
+
if (validFilters.length === 1) {
|
|
1996
|
+
return validFilters[0];
|
|
1997
|
+
}
|
|
1998
|
+
return Filters.and(...validFilters);
|
|
1999
|
+
}
|
|
2000
|
+
function combineFiltersWithOr(filters) {
|
|
2001
|
+
const validFilters = filters.filter((f) => f !== void 0 && f !== null);
|
|
2002
|
+
if (validFilters.length === 0) {
|
|
2003
|
+
return void 0;
|
|
2004
|
+
}
|
|
2005
|
+
if (validFilters.length === 1) {
|
|
2006
|
+
return validFilters[0];
|
|
2007
|
+
}
|
|
2008
|
+
return Filters.or(...validFilters);
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2015
2011
|
// src/tools/query-memory.ts
|
|
2016
2012
|
var queryMemoryTool = {
|
|
2017
2013
|
name: "remember_query_memory",
|
|
@@ -2298,7 +2294,9 @@ async function handleCreateRelationship(args, userId, context) {
|
|
|
2298
2294
|
version: 1,
|
|
2299
2295
|
tags: args.tags || []
|
|
2300
2296
|
};
|
|
2301
|
-
const relationshipId = await collection.data.insert(
|
|
2297
|
+
const relationshipId = await collection.data.insert({
|
|
2298
|
+
properties: relationship
|
|
2299
|
+
});
|
|
2302
2300
|
logger.info("Relationship created, updating connected memories", {
|
|
2303
2301
|
relationshipId,
|
|
2304
2302
|
userId
|
package/dist/server.js
CHANGED
|
@@ -1322,7 +1322,9 @@ async function handleCreateMemory(args, userId, context) {
|
|
|
1322
1322
|
base_weight: args.weight ?? 0.5,
|
|
1323
1323
|
computed_weight: args.weight ?? 0.5
|
|
1324
1324
|
};
|
|
1325
|
-
const result = await collection.data.insert(
|
|
1325
|
+
const result = await collection.data.insert({
|
|
1326
|
+
properties: memory
|
|
1327
|
+
});
|
|
1326
1328
|
logger.info("Memory created successfully", { memoryId: result, userId });
|
|
1327
1329
|
const response = {
|
|
1328
1330
|
memory_id: result,
|
|
@@ -1336,103 +1338,6 @@ async function handleCreateMemory(args, userId, context) {
|
|
|
1336
1338
|
}
|
|
1337
1339
|
}
|
|
1338
1340
|
|
|
1339
|
-
// src/utils/weaviate-filters.ts
|
|
1340
|
-
import { Filters } from "weaviate-client";
|
|
1341
|
-
function buildCombinedSearchFilters(collection, filters) {
|
|
1342
|
-
const memoryFilters = buildDocTypeFilters(collection, "memory", filters);
|
|
1343
|
-
const relationshipFilters = buildDocTypeFilters(collection, "relationship", filters);
|
|
1344
|
-
const validFilters = [memoryFilters, relationshipFilters].filter((f) => f !== void 0 && f !== null);
|
|
1345
|
-
if (validFilters.length === 0) {
|
|
1346
|
-
return void 0;
|
|
1347
|
-
} else if (validFilters.length === 1) {
|
|
1348
|
-
return validFilters[0];
|
|
1349
|
-
} else {
|
|
1350
|
-
return combineFiltersWithOr(validFilters);
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
function buildDocTypeFilters(collection, docType, filters) {
|
|
1354
|
-
const filterList = [];
|
|
1355
|
-
filterList.push(
|
|
1356
|
-
collection.filter.byProperty("doc_type").equal(docType)
|
|
1357
|
-
);
|
|
1358
|
-
if (docType === "memory" && filters?.types && filters.types.length > 0) {
|
|
1359
|
-
if (filters.types.length === 1) {
|
|
1360
|
-
filterList.push(
|
|
1361
|
-
collection.filter.byProperty("type").equal(filters.types[0])
|
|
1362
|
-
);
|
|
1363
|
-
} else {
|
|
1364
|
-
filterList.push(
|
|
1365
|
-
collection.filter.byProperty("type").containsAny(filters.types)
|
|
1366
|
-
);
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
if (filters?.weight_min !== void 0) {
|
|
1370
|
-
filterList.push(
|
|
1371
|
-
collection.filter.byProperty("weight").greaterThanOrEqual(filters.weight_min)
|
|
1372
|
-
);
|
|
1373
|
-
}
|
|
1374
|
-
if (filters?.weight_max !== void 0) {
|
|
1375
|
-
filterList.push(
|
|
1376
|
-
collection.filter.byProperty("weight").lessThanOrEqual(filters.weight_max)
|
|
1377
|
-
);
|
|
1378
|
-
}
|
|
1379
|
-
if (filters?.trust_min !== void 0) {
|
|
1380
|
-
filterList.push(
|
|
1381
|
-
collection.filter.byProperty("trust").greaterThanOrEqual(filters.trust_min)
|
|
1382
|
-
);
|
|
1383
|
-
}
|
|
1384
|
-
if (filters?.trust_max !== void 0) {
|
|
1385
|
-
filterList.push(
|
|
1386
|
-
collection.filter.byProperty("trust").lessThanOrEqual(filters.trust_max)
|
|
1387
|
-
);
|
|
1388
|
-
}
|
|
1389
|
-
if (filters?.date_from) {
|
|
1390
|
-
filterList.push(
|
|
1391
|
-
collection.filter.byProperty("created_at").greaterThanOrEqual(new Date(filters.date_from))
|
|
1392
|
-
);
|
|
1393
|
-
}
|
|
1394
|
-
if (filters?.date_to) {
|
|
1395
|
-
filterList.push(
|
|
1396
|
-
collection.filter.byProperty("created_at").lessThanOrEqual(new Date(filters.date_to))
|
|
1397
|
-
);
|
|
1398
|
-
}
|
|
1399
|
-
if (filters?.tags && filters.tags.length > 0) {
|
|
1400
|
-
if (filters.tags.length === 1) {
|
|
1401
|
-
filterList.push(
|
|
1402
|
-
collection.filter.byProperty("tags").containsAny([filters.tags[0]])
|
|
1403
|
-
);
|
|
1404
|
-
} else {
|
|
1405
|
-
filterList.push(
|
|
1406
|
-
collection.filter.byProperty("tags").containsAny(filters.tags)
|
|
1407
|
-
);
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
return combineFiltersWithAnd(filterList);
|
|
1411
|
-
}
|
|
1412
|
-
function buildMemoryOnlyFilters(collection, filters) {
|
|
1413
|
-
return buildDocTypeFilters(collection, "memory", filters);
|
|
1414
|
-
}
|
|
1415
|
-
function combineFiltersWithAnd(filters) {
|
|
1416
|
-
const validFilters = filters.filter((f) => f !== void 0 && f !== null);
|
|
1417
|
-
if (validFilters.length === 0) {
|
|
1418
|
-
return void 0;
|
|
1419
|
-
}
|
|
1420
|
-
if (validFilters.length === 1) {
|
|
1421
|
-
return validFilters[0];
|
|
1422
|
-
}
|
|
1423
|
-
return Filters.and(...validFilters);
|
|
1424
|
-
}
|
|
1425
|
-
function combineFiltersWithOr(filters) {
|
|
1426
|
-
const validFilters = filters.filter((f) => f !== void 0 && f !== null);
|
|
1427
|
-
if (validFilters.length === 0) {
|
|
1428
|
-
return void 0;
|
|
1429
|
-
}
|
|
1430
|
-
if (validFilters.length === 1) {
|
|
1431
|
-
return validFilters[0];
|
|
1432
|
-
}
|
|
1433
|
-
return Filters.or(...validFilters);
|
|
1434
|
-
}
|
|
1435
|
-
|
|
1436
1341
|
// src/tools/search-memory.ts
|
|
1437
1342
|
var searchMemoryTool = {
|
|
1438
1343
|
name: "remember_search_memory",
|
|
@@ -1536,19 +1441,15 @@ async function handleSearchMemory(args, userId) {
|
|
|
1536
1441
|
const alpha = args.alpha ?? 0.7;
|
|
1537
1442
|
const limit = args.limit ?? 10;
|
|
1538
1443
|
const offset = args.offset ?? 0;
|
|
1539
|
-
const filters = includeRelationships ? buildCombinedSearchFilters(collection, args.filters) : buildMemoryOnlyFilters(collection, args.filters);
|
|
1540
1444
|
const searchOptions = {
|
|
1541
1445
|
alpha,
|
|
1542
1446
|
limit: limit + offset
|
|
1543
1447
|
// Get extra for offset
|
|
1544
1448
|
};
|
|
1545
|
-
if (filters) {
|
|
1546
|
-
searchOptions.filters = filters;
|
|
1547
|
-
}
|
|
1548
1449
|
logger.info("Weaviate query", {
|
|
1549
1450
|
query: args.query,
|
|
1550
|
-
searchOptions: JSON.stringify(searchOptions, null, 2)
|
|
1551
|
-
hasFilters: !!filters
|
|
1451
|
+
searchOptions: JSON.stringify(searchOptions, null, 2)
|
|
1452
|
+
// hasFilters: !!filters,
|
|
1552
1453
|
});
|
|
1553
1454
|
const results = await collection.query.hybrid(args.query, searchOptions);
|
|
1554
1455
|
const paginatedResults = results.objects.slice(offset);
|
|
@@ -1581,8 +1482,9 @@ async function handleSearchMemory(args, userId) {
|
|
|
1581
1482
|
});
|
|
1582
1483
|
return JSON.stringify(searchResult, null, 2);
|
|
1583
1484
|
} catch (error) {
|
|
1584
|
-
|
|
1585
|
-
|
|
1485
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1486
|
+
logger.error("Failed to search memories:", { error: errorMessage, userId, query: args.query });
|
|
1487
|
+
throw new Error(`Failed to search memories: ${errorMessage}`);
|
|
1586
1488
|
}
|
|
1587
1489
|
}
|
|
1588
1490
|
|
|
@@ -1941,6 +1843,100 @@ async function handleFindSimilar(args, userId) {
|
|
|
1941
1843
|
}
|
|
1942
1844
|
}
|
|
1943
1845
|
|
|
1846
|
+
// src/utils/weaviate-filters.ts
|
|
1847
|
+
import { Filters } from "weaviate-client";
|
|
1848
|
+
function buildCombinedSearchFilters(collection, filters) {
|
|
1849
|
+
const memoryFilters = buildDocTypeFilters(collection, "memory", filters);
|
|
1850
|
+
const relationshipFilters = buildDocTypeFilters(collection, "relationship", filters);
|
|
1851
|
+
const validFilters = [memoryFilters, relationshipFilters].filter((f) => f !== void 0 && f !== null);
|
|
1852
|
+
if (validFilters.length === 0) {
|
|
1853
|
+
return void 0;
|
|
1854
|
+
} else if (validFilters.length === 1) {
|
|
1855
|
+
return validFilters[0];
|
|
1856
|
+
} else {
|
|
1857
|
+
return combineFiltersWithOr(validFilters);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
function buildDocTypeFilters(collection, docType, filters) {
|
|
1861
|
+
const filterList = [];
|
|
1862
|
+
filterList.push(
|
|
1863
|
+
collection.filter.byProperty("doc_type").equal(docType)
|
|
1864
|
+
);
|
|
1865
|
+
if (docType === "memory" && filters?.types && filters.types.length > 0) {
|
|
1866
|
+
if (filters.types.length === 1) {
|
|
1867
|
+
filterList.push(
|
|
1868
|
+
collection.filter.byProperty("type").equal(filters.types[0])
|
|
1869
|
+
);
|
|
1870
|
+
} else {
|
|
1871
|
+
filterList.push(
|
|
1872
|
+
collection.filter.byProperty("type").containsAny(filters.types)
|
|
1873
|
+
);
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
if (filters?.weight_min !== void 0) {
|
|
1877
|
+
filterList.push(
|
|
1878
|
+
collection.filter.byProperty("weight").greaterThanOrEqual(filters.weight_min)
|
|
1879
|
+
);
|
|
1880
|
+
}
|
|
1881
|
+
if (filters?.weight_max !== void 0) {
|
|
1882
|
+
filterList.push(
|
|
1883
|
+
collection.filter.byProperty("weight").lessThanOrEqual(filters.weight_max)
|
|
1884
|
+
);
|
|
1885
|
+
}
|
|
1886
|
+
if (filters?.trust_min !== void 0) {
|
|
1887
|
+
filterList.push(
|
|
1888
|
+
collection.filter.byProperty("trust").greaterThanOrEqual(filters.trust_min)
|
|
1889
|
+
);
|
|
1890
|
+
}
|
|
1891
|
+
if (filters?.trust_max !== void 0) {
|
|
1892
|
+
filterList.push(
|
|
1893
|
+
collection.filter.byProperty("trust").lessThanOrEqual(filters.trust_max)
|
|
1894
|
+
);
|
|
1895
|
+
}
|
|
1896
|
+
if (filters?.date_from) {
|
|
1897
|
+
filterList.push(
|
|
1898
|
+
collection.filter.byProperty("created_at").greaterThanOrEqual(new Date(filters.date_from))
|
|
1899
|
+
);
|
|
1900
|
+
}
|
|
1901
|
+
if (filters?.date_to) {
|
|
1902
|
+
filterList.push(
|
|
1903
|
+
collection.filter.byProperty("created_at").lessThanOrEqual(new Date(filters.date_to))
|
|
1904
|
+
);
|
|
1905
|
+
}
|
|
1906
|
+
if (filters?.tags && filters.tags.length > 0) {
|
|
1907
|
+
if (filters.tags.length === 1) {
|
|
1908
|
+
filterList.push(
|
|
1909
|
+
collection.filter.byProperty("tags").containsAny([filters.tags[0]])
|
|
1910
|
+
);
|
|
1911
|
+
} else {
|
|
1912
|
+
filterList.push(
|
|
1913
|
+
collection.filter.byProperty("tags").containsAny(filters.tags)
|
|
1914
|
+
);
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
return combineFiltersWithAnd(filterList);
|
|
1918
|
+
}
|
|
1919
|
+
function combineFiltersWithAnd(filters) {
|
|
1920
|
+
const validFilters = filters.filter((f) => f !== void 0 && f !== null);
|
|
1921
|
+
if (validFilters.length === 0) {
|
|
1922
|
+
return void 0;
|
|
1923
|
+
}
|
|
1924
|
+
if (validFilters.length === 1) {
|
|
1925
|
+
return validFilters[0];
|
|
1926
|
+
}
|
|
1927
|
+
return Filters.and(...validFilters);
|
|
1928
|
+
}
|
|
1929
|
+
function combineFiltersWithOr(filters) {
|
|
1930
|
+
const validFilters = filters.filter((f) => f !== void 0 && f !== null);
|
|
1931
|
+
if (validFilters.length === 0) {
|
|
1932
|
+
return void 0;
|
|
1933
|
+
}
|
|
1934
|
+
if (validFilters.length === 1) {
|
|
1935
|
+
return validFilters[0];
|
|
1936
|
+
}
|
|
1937
|
+
return Filters.or(...validFilters);
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1944
1940
|
// src/tools/query-memory.ts
|
|
1945
1941
|
var queryMemoryTool = {
|
|
1946
1942
|
name: "remember_query_memory",
|
|
@@ -2227,7 +2223,9 @@ async function handleCreateRelationship(args, userId, context) {
|
|
|
2227
2223
|
version: 1,
|
|
2228
2224
|
tags: args.tags || []
|
|
2229
2225
|
};
|
|
2230
|
-
const relationshipId = await collection.data.insert(
|
|
2226
|
+
const relationshipId = await collection.data.insert({
|
|
2227
|
+
properties: relationship
|
|
2228
|
+
});
|
|
2231
2229
|
logger.info("Relationship created, updating connected memories", {
|
|
2232
2230
|
relationshipId,
|
|
2233
2231
|
userId
|
package/package.json
CHANGED
|
@@ -180,8 +180,11 @@ export async function handleCreateMemory(
|
|
|
180
180
|
computed_weight: args.weight ?? 0.5,
|
|
181
181
|
};
|
|
182
182
|
|
|
183
|
-
// Insert into Weaviate
|
|
184
|
-
|
|
183
|
+
// Insert into Weaviate v3 API
|
|
184
|
+
// v3 expects: { properties: {...} }
|
|
185
|
+
const result = await collection.data.insert({
|
|
186
|
+
properties: memory as any,
|
|
187
|
+
});
|
|
185
188
|
|
|
186
189
|
logger.info('Memory created successfully', { memoryId: result, userId });
|
|
187
190
|
|
|
@@ -182,8 +182,11 @@ export async function handleCreateRelationship(
|
|
|
182
182
|
tags: args.tags || [],
|
|
183
183
|
};
|
|
184
184
|
|
|
185
|
-
// Insert relationship into Weaviate
|
|
186
|
-
|
|
185
|
+
// Insert relationship into Weaviate v3 API
|
|
186
|
+
// v3 expects: { properties: {...} }
|
|
187
|
+
const relationshipId = await collection.data.insert({
|
|
188
|
+
properties: relationship as any,
|
|
189
|
+
});
|
|
187
190
|
|
|
188
191
|
logger.info('Relationship created, updating connected memories', {
|
|
189
192
|
relationshipId,
|
|
@@ -127,9 +127,9 @@ export async function handleSearchMemory(
|
|
|
127
127
|
|
|
128
128
|
// Build filters using v3 API
|
|
129
129
|
// Use OR logic to search both memories and relationships
|
|
130
|
-
const filters = includeRelationships
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
// const filters = includeRelationships
|
|
131
|
+
// ? buildCombinedSearchFilters(collection, args.filters)
|
|
132
|
+
// : buildMemoryOnlyFilters(collection, args.filters);
|
|
133
133
|
|
|
134
134
|
// Build search options
|
|
135
135
|
const searchOptions: any = {
|
|
@@ -138,15 +138,15 @@ export async function handleSearchMemory(
|
|
|
138
138
|
};
|
|
139
139
|
|
|
140
140
|
// Add filters if present
|
|
141
|
-
if (filters) {
|
|
142
|
-
|
|
143
|
-
}
|
|
141
|
+
// if (filters) {
|
|
142
|
+
// searchOptions.filters = filters;
|
|
143
|
+
// }
|
|
144
144
|
|
|
145
145
|
// Log the query for debugging
|
|
146
146
|
logger.info('Weaviate query', {
|
|
147
147
|
query: args.query,
|
|
148
148
|
searchOptions: JSON.stringify(searchOptions, null, 2),
|
|
149
|
-
hasFilters: !!filters,
|
|
149
|
+
// hasFilters: !!filters,
|
|
150
150
|
});
|
|
151
151
|
|
|
152
152
|
// Perform hybrid search with Weaviate v3 API
|
|
@@ -191,7 +191,8 @@ export async function handleSearchMemory(
|
|
|
191
191
|
|
|
192
192
|
return JSON.stringify(searchResult, null, 2);
|
|
193
193
|
} catch (error) {
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
195
|
+
logger.error('Failed to search memories:', { error: errorMessage, userId, query: args.query });
|
|
196
|
+
throw new Error(`Failed to search memories: ${errorMessage}`);
|
|
196
197
|
}
|
|
197
198
|
}
|