brainy/fix-db-add.cjs
David Snelling fb80808f44 feat: Remove dangerous getAllNouns/getAllVerbs methods, add safe pagination
BREAKING CHANGE: Removed getAllNouns() and getAllVerbs() from StorageAdapter interface
These methods could cause expensive full scans on cloud storage (S3/R2) leading to
high costs and performance issues. Replaced with safe paginated methods.

Changes:
- Remove getAllNouns/getAllVerbs from StorageAdapter interface and implementations
- Add internal optimization methods for intelligent preloading when safe
- Fix OPFS storage file naming consistency (.json extension)
- Fix S3 high-volume mode detection thresholds (was too aggressive)
- Fix TypeScript compilation errors with async methods
- Update all tests to use paginated methods

Performance:
- Add smart dataset size detection for automatic optimization
- Maintain all internal performance optimizations through safe preloading
- Only preload data in read-only mode or when dataset is small (<10k entities)

Fixes:
- Fix intelligent verb scoring tests metadata structure
- Fix S3 storage getVerbsBySource/Target/Type methods
- Fix memory usage in search operations using pagination

Docs:
- Add comprehensive storage architecture documentation
- Document known bash redirection issue
- Update README with architecture doc link

All affected tests passing
2025-08-10 16:25:12 -07:00

28 lines
No EOL
2.6 KiB
JavaScript

const fs = require('fs');
const filePath = '/home/dpsifr/Projects/brainy/tests/intelligent-verb-scoring.test.ts';
let content = fs.readFileSync(filePath, 'utf8');
// Fix db.add calls that use text as first parameter
const fixes = [
["await db.add('developer1', 'John is a software developer who writes JavaScript')", "await db.add(testUtils.createTestVector(384), { id: 'developer1', data: 'John is a software developer who writes JavaScript' })"],
["await db.add('developer2', 'Jane is a programmer who codes in TypeScript')", "await db.add(testUtils.createTestVector(384), { id: 'developer2', data: 'Jane is a programmer who codes in TypeScript' })"],
["await db.add('restaurant1', 'Italian restaurant serving pasta')", "await db.add(testUtils.createTestVector(384), { id: 'restaurant1', data: 'Italian restaurant serving pasta' })"],
["await db.add('car1', 'Red sports car with V8 engine')", "await db.add(testUtils.createTestVector(384), { id: 'car1', data: 'Red sports car with V8 engine' })"],
["await db.add('user1', 'Software engineer')", "await db.add(testUtils.createTestVector(384), { id: 'user1', data: 'Software engineer' })"],
["await db.add('project1', 'Web development project')", "await db.add(testUtils.createTestVector(384), { id: 'project1', data: 'Web development project' })"],
["await db.add('entity3', 'Test entity 3')", "await db.add(testUtils.createTestVector(384), { id: 'entity3', data: 'Test entity 3' })"],
["await db.add('entity4', 'Test entity 4')", "await db.add(testUtils.createTestVector(384), { id: 'entity4', data: 'Test entity 4' })"],
["await db.add('entity1', 'Software developer with expertise in JavaScript')", "await db.add(testUtils.createTestVector(384), { id: 'entity1', data: 'Software developer with expertise in JavaScript' })"],
["await db.add('entity2', 'React application for web development')", "await db.add(testUtils.createTestVector(384), { id: 'entity2', data: 'React application for web development' })"],
["await db.add('person1', 'Software engineer')", "await db.add(testUtils.createTestVector(384), { id: 'person1', data: 'Software engineer' })"],
["await db.add('project1', 'Web application')", "await db.add(testUtils.createTestVector(384), { id: 'project1', data: 'Web application' })"],
["await db.add('company1', 'Technology startup')", "await db.add(testUtils.createTestVector(384), { id: 'company1', data: 'Technology startup' })"]
];
fixes.forEach(([from, to]) => {
content = content.replace(from, to);
});
fs.writeFileSync(filePath, content);
console.log('Fixed db.add calls in intelligent-verb-scoring.test.ts');