mira-consciousness
Version:
Memory & Intelligence Retention Archive - Preserving The Spark
144 lines (113 loc) โข 4.86 kB
JavaScript
#!/usr/bin/env node
/**
* Fix ChromaDB SQLite compatibility issues
* This script installs pysqlite3-binary and creates the necessary fix module
*/
import fs from 'fs-extra';
import path from 'path';
import { execSync } from 'child_process';
import chalk from 'chalk';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
console.log(chalk.blue('\n๐ง ChromaDB SQLite Compatibility Fix'));
console.log('โ'.repeat(50));
async function fixChromaDB() {
try {
// Check Python availability
const pythonCmd = process.platform === 'win32' ? 'python' : 'python3';
// Check system SQLite version
console.log(chalk.cyan('\n๐ Checking system SQLite version...'));
const checkScript = [
'import sqlite3',
'print(f"System SQLite: {sqlite3.sqlite_version}")',
'print("ChromaDB requires: 3.35.0+")',
'if tuple(map(int, sqlite3.sqlite_version.split("."))) < (3, 35, 0):',
' print("NEEDS_FIX")',
'else:',
' print("OK")'
].join(';');
const result = execSync(`${pythonCmd} -c "${checkScript}"`, { encoding: 'utf-8' }).trim();
const lines = result.split('\n');
console.log(chalk.gray(` ${lines[0]}`));
console.log(chalk.gray(` ${lines[1]}`));
if (lines[2] === 'OK') {
console.log(chalk.green('\nโ
Your system SQLite is already compatible with ChromaDB!'));
return;
}
console.log(chalk.yellow('\nโ ๏ธ System SQLite is too old for ChromaDB'));
// Install pysqlite3-binary
console.log(chalk.cyan('\n๐ฆ Installing pysqlite3-binary...'));
try {
execSync(`${pythonCmd} -m pip install pysqlite3-binary`, { stdio: 'inherit' });
console.log(chalk.green('โ pysqlite3-binary installed successfully'));
} catch (error) {
console.error(chalk.red('โ Failed to install pysqlite3-binary'));
console.log(chalk.yellow('\nPlease install manually:'));
console.log(chalk.gray(' pip install pysqlite3-binary'));
process.exit(1);
}
// Create the SQLite fix file
console.log(chalk.cyan('\n๐ Creating ChromaDB SQLite fix module...'));
const pythonMemoryDir = path.join(__dirname, '../python-memory');
const fixPath = path.join(pythonMemoryDir, 'chromadb_sqlite_fix.py');
const fixContent = `"""
ChromaDB SQLite Fix - Use pysqlite3 instead of built-in sqlite3
This module replaces the system sqlite3 with pysqlite3-binary to meet
ChromaDB's SQLite 3.35.0+ requirement.
Auto-generated by MIRA setup to ensure ChromaDB compatibility.
"""
import sys
def apply_sqlite_fix():
"""Replace sqlite3 with pysqlite3 to meet ChromaDB requirements."""
try:
# Import pysqlite3
import pysqlite3
# Replace sqlite3 with pysqlite3 in sys.modules
sys.modules['sqlite3'] = pysqlite3
sys.modules['sqlite3.dbapi2'] = pysqlite3.dbapi2
# Verify the version
import sqlite3
version = sqlite3.sqlite_version
print(f"โ
SQLite upgraded to version {version} using pysqlite3-binary")
return True
except ImportError:
print("โ pysqlite3-binary not installed. Run: pip install pysqlite3-binary")
return False
# Apply the fix immediately when imported
if __name__ != "__main__":
apply_sqlite_fix()
`;
await fs.writeFile(fixPath, fixContent);
console.log(chalk.green(`โ Fix module created at: ${fixPath}`));
// Test the fix
console.log(chalk.cyan('\n๐งช Testing the fix...'));
const testScript = [
'import sys',
`sys.path.insert(0, "${pythonMemoryDir}")`,
'import chromadb_sqlite_fix',
'import chromadb',
'print(f"ChromaDB version: {chromadb.__version__}")',
'print("โ
ChromaDB is now compatible!")'
].join(';');
try {
const testResult = execSync(`${pythonCmd} -c "${testScript}"`, { encoding: 'utf-8' });
console.log(chalk.gray(testResult.trim()));
console.log(chalk.green('\nโจ ChromaDB SQLite fix applied successfully!'));
console.log(chalk.gray('\nThe fix will be automatically applied when using MIRA.'));
console.log(chalk.gray('Your workspace is now ready for ChromaDB operations.'));
} catch (error) {
console.log(chalk.yellow('\nโ ๏ธ Fix created but ChromaDB test failed'));
console.log(chalk.gray('This is normal if ChromaDB is not yet installed.'));
console.log(chalk.gray('The fix will work once ChromaDB is installed.'));
}
} catch (error) {
console.error(chalk.red('\nโ Error:'), error.message);
process.exit(1);
}
}
// Run the fix
fixChromaDB().catch(error => {
console.error(chalk.red('\nโ Unexpected error:'), error);
process.exit(1);
});