cozo-memory 1.0.5 → 1.0.7

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.
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("./index");
4
+ async function debugHybridSearch() {
5
+ console.log('Initializing MemoryServer...');
6
+ const server = new index_1.MemoryServer();
7
+ await server.initPromise;
8
+ // Check database content
9
+ console.log('\n=== Database Content ===');
10
+ const entities = await server.db.run('?[id, name, type] := *entity{id, name, type, @ "NOW"}');
11
+ console.log(`Entities: ${entities.rows.length}`);
12
+ entities.rows.slice(0, 3).forEach((row) => {
13
+ console.log(` - ${row[1]} (${row[2]})`);
14
+ });
15
+ const observations = await server.db.run('?[id, text] := *observation{id, text, @ "NOW"}');
16
+ console.log(`\nObservations: ${observations.rows.length}`);
17
+ observations.rows.slice(0, 3).forEach((row) => {
18
+ console.log(` - ${row[1].substring(0, 60)}...`);
19
+ });
20
+ // Test embedding
21
+ console.log('\n=== Test Embedding ===');
22
+ const testEmbedding = await server.embeddingService.embed('Alice');
23
+ console.log(`Embedding dimensions: ${testEmbedding.length}`);
24
+ console.log(`First 5 values: ${testEmbedding.slice(0, 5)}`);
25
+ // Test HNSW search directly
26
+ console.log('\n=== Test HNSW Search Directly ===');
27
+ try {
28
+ const hnswQuery = `
29
+ ?[id, name, type, dist] :=
30
+ ~entity:name_semantic{id | query: vec([${testEmbedding.join(',')}]), k: 5, bind_distance: dist},
31
+ *entity{id, name, type, @ "NOW"}
32
+ `;
33
+ const hnswResult = await server.db.run(hnswQuery);
34
+ console.log(`HNSW results: ${hnswResult.rows.length}`);
35
+ hnswResult.rows.forEach((row) => {
36
+ console.log(` - ${row[1]} (${row[2]}) - distance: ${row[3]}`);
37
+ });
38
+ }
39
+ catch (e) {
40
+ console.error('HNSW error:', e.message);
41
+ }
42
+ // Test hybridSearch
43
+ console.log('\n=== Test HybridSearch ===');
44
+ const searchResult = await server.hybridSearch.search({
45
+ query: 'Alice',
46
+ limit: 5,
47
+ includeEntities: true,
48
+ includeObservations: true
49
+ });
50
+ console.log('HybridSearch result:', JSON.stringify(searchResult, null, 2));
51
+ }
52
+ debugHybridSearch().catch(console.error);
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("./index");
4
+ async function testMCPSearch() {
5
+ console.log('Initializing MemoryServer...');
6
+ const server = new index_1.MemoryServer();
7
+ await server.initPromise;
8
+ console.log('\n=== Test 1: Create Entity via MCP mutate_memory ===');
9
+ const createResult = await server.mutateMemory({
10
+ action: 'create_entity',
11
+ name: 'Test Search Entity',
12
+ type: 'test',
13
+ metadata: { purpose: 'search_test' }
14
+ });
15
+ console.log('Created:', createResult);
16
+ const entityId = createResult.id;
17
+ console.log('\n=== Test 2: Add Observation via MCP mutate_memory ===');
18
+ const obsResult = await server.mutateMemory({
19
+ action: 'add_observation',
20
+ entity_id: entityId,
21
+ text: 'This is a test observation for searching with keywords like authentication and OAuth',
22
+ metadata: { test: true }
23
+ });
24
+ console.log('Added observation:', obsResult);
25
+ console.log('\n=== Test 3: Search via MCP query_memory ===');
26
+ const searchResult = await server.queryMemory({
27
+ action: 'search',
28
+ query: 'authentication',
29
+ limit: 5
30
+ });
31
+ console.log('Search result:', JSON.stringify(searchResult, null, 2));
32
+ console.log('\n=== Test 4: Search for "Alice" ===');
33
+ const aliceResult = await server.queryMemory({
34
+ action: 'search',
35
+ query: 'Alice',
36
+ limit: 5
37
+ });
38
+ console.log('Alice search result:', JSON.stringify(aliceResult, null, 2));
39
+ console.log('\n=== Test 5: Search for "TypeScript" ===');
40
+ const tsResult = await server.queryMemory({
41
+ action: 'search',
42
+ query: 'TypeScript',
43
+ limit: 5
44
+ });
45
+ console.log('TypeScript search result:', JSON.stringify(tsResult, null, 2));
46
+ }
47
+ testMCPSearch().catch(console.error);
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("./index");
4
+ async function testSearch() {
5
+ console.log('Initializing MemoryServer...');
6
+ const server = new index_1.MemoryServer();
7
+ await server.initPromise;
8
+ console.log('\n=== Testing Search ===');
9
+ // Test simple search
10
+ const result = await server.hybridSearch.search({
11
+ query: 'Alice',
12
+ limit: 5,
13
+ includeEntities: true,
14
+ includeObservations: true
15
+ });
16
+ console.log('Search result:', JSON.stringify(result, null, 2));
17
+ // Check if result is array or object
18
+ console.log('\nResult type:', typeof result);
19
+ console.log('Is array:', Array.isArray(result));
20
+ if (Array.isArray(result)) {
21
+ console.log(`Found ${result.length} results`);
22
+ }
23
+ else {
24
+ console.log('Result keys:', Object.keys(result));
25
+ }
26
+ }
27
+ testSearch().catch(console.error);
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("./index");
4
+ async function testUserProfileEditing() {
5
+ console.log("=== Testing User Profile Editing ===\n");
6
+ const server = new index_1.MemoryServer();
7
+ await server.start();
8
+ try {
9
+ // 1. View current profile
10
+ console.log("1. Current user profile:");
11
+ const currentProfile = await server.editUserProfile({});
12
+ console.log(JSON.stringify(currentProfile, null, 2));
13
+ // 2. Update metadata
14
+ console.log("\n2. Updating profile metadata:");
15
+ const metadataUpdate = await server.editUserProfile({
16
+ metadata: {
17
+ timezone: "Europe/Berlin",
18
+ language: "de",
19
+ work_hours: "09:00-17:00"
20
+ }
21
+ });
22
+ console.log(JSON.stringify(metadataUpdate, null, 2));
23
+ // 3. Add new preferences
24
+ console.log("\n3. Adding new preferences:");
25
+ const addPrefs = await server.editUserProfile({
26
+ observations: [
27
+ { text: "Prefers TypeScript over JavaScript for type safety" },
28
+ { text: "Likes clean, minimal code without unnecessary comments" },
29
+ { text: "Prefers functional programming patterns" }
30
+ ]
31
+ });
32
+ console.log(JSON.stringify(addPrefs, null, 2));
33
+ // 4. Clear and reset preferences
34
+ console.log("\n4. Clearing and resetting preferences:");
35
+ const resetPrefs = await server.editUserProfile({
36
+ clear_observations: true,
37
+ observations: [
38
+ { text: "Works primarily with Node.js and TypeScript", metadata: { category: "tech_stack" } },
39
+ { text: "Prefers concise documentation", metadata: { category: "style" } }
40
+ ]
41
+ });
42
+ console.log(JSON.stringify(resetPrefs, null, 2));
43
+ // 5. Update name and type
44
+ console.log("\n5. Updating profile name and type:");
45
+ const nameUpdate = await server.editUserProfile({
46
+ name: "Developer Profile",
47
+ type: "UserProfile"
48
+ });
49
+ console.log(JSON.stringify(nameUpdate, null, 2));
50
+ console.log("\n=== Test completed successfully ===");
51
+ }
52
+ catch (error) {
53
+ console.error("Test failed:", error);
54
+ }
55
+ finally {
56
+ process.exit(0);
57
+ }
58
+ }
59
+ testUserProfileEditing();
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * Utility functions for timestamp handling
4
+ * Provides both Unix microsecond timestamps and ISO 8601 strings
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.toDualTimestamp = toDualTimestamp;
8
+ exports.nowDual = nowDual;
9
+ exports.parseToDual = parseToDual;
10
+ /**
11
+ * Convert CozoDB microsecond timestamp to dual format
12
+ */
13
+ function toDualTimestamp(microseconds) {
14
+ const milliseconds = Math.floor(microseconds / 1000);
15
+ const date = new Date(milliseconds);
16
+ return {
17
+ timestamp: microseconds,
18
+ iso: date.toISOString()
19
+ };
20
+ }
21
+ /**
22
+ * Get current time in dual format
23
+ */
24
+ function nowDual() {
25
+ const now = Date.now();
26
+ return {
27
+ timestamp: now * 1000, // Convert to microseconds
28
+ iso: new Date(now).toISOString()
29
+ };
30
+ }
31
+ /**
32
+ * Parse ISO string or Unix timestamp to dual format
33
+ */
34
+ function parseToDual(input) {
35
+ if (typeof input === 'number') {
36
+ return toDualTimestamp(input);
37
+ }
38
+ const date = new Date(input);
39
+ const milliseconds = date.getTime();
40
+ return {
41
+ timestamp: milliseconds * 1000, // Convert to microseconds
42
+ iso: date.toISOString()
43
+ };
44
+ }