-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-memory-insert.js
More file actions
64 lines (52 loc) · 1.88 KB
/
test-memory-insert.js
File metadata and controls
64 lines (52 loc) · 1.88 KB
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
import { db } from './server/db.js';
import { sql } from 'drizzle-orm';
async function createTestMemory() {
try {
console.log('Creating test memory...');
// Generate a small test vector (3 dimensions for simplicity)
const embedding = Array(1536).fill(0).map(() => Math.random());
// Insert directly using raw SQL to ensure proper vector type handling
const result = await db.execute(sql`
INSERT INTO memories (content, embedding, type, message_id, metadata)
VALUES (
'Test Memory Content',
${JSON.stringify(embedding)}::vector,
'prompt',
null,
${'{"source": "test", "test": true}'}::jsonb
)
RETURNING *
`);
console.log('Memory created with ID:', result[0].id);
// Verify the count
const [{ count }] = await db.select({ count: sql`count(*)` }).from(sql`memories`);
console.log('Total memories in database:', count);
return result[0];
} catch (error) {
console.error('Error creating test memory:', error);
throw error;
}
}
async function main() {
try {
console.log('== Memory Test Script ==');
// First check the current count
const [{ count: initialCount }] = await db.select({ count: sql`count(*)` }).from(sql`memories`);
console.log('Initial memory count:', initialCount);
// Create a test memory
const memory = await createTestMemory();
console.log('Test memory created successfully:', memory.id);
// Get memory by ID to verify it exists
const [fetchedMemory] = await db.execute(
sql`SELECT * FROM memories WHERE id = ${memory.id}`
);
console.log('Retrieved memory by ID:', fetchedMemory.id);
console.log('Test completed successfully');
} catch (error) {
console.error('Error in test:', error);
} finally {
// Important to close the connection when done
process.exit(0);
}
}
main();