Some checks failed
CI/CD Pipeline / Backend - Lint & Test (push) Has been cancelled
CI/CD Pipeline / Frontend - Lint & Test (push) Has been cancelled
CI/CD Pipeline / Security Scan (push) Has been cancelled
CI/CD Pipeline / Build Backend (push) Has been cancelled
CI/CD Pipeline / Build Frontend (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Deploy to Staging (push) Has been cancelled
CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / Performance Tests (push) Has been cancelled
CI/CD Pipeline / Dependency Updates (push) Has been cancelled
- Updated Anthropic API to latest version (2024-01-01) - Set Claude 3.7 Sonnet Latest as primary model - Removed deprecated Opus 3.5 references - Fixed LLM response validation and JSON parsing - Improved error handling and logging - Updated model configurations and pricing - Enhanced document processing reliability - Fixed TypeScript type issues - Updated environment configuration
76 lines
2.9 KiB
JavaScript
76 lines
2.9 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const { createClient } = require('@supabase/supabase-js');
|
|
require('dotenv').config();
|
|
|
|
const supabaseUrl = process.env.SUPABASE_URL;
|
|
const supabaseServiceKey = process.env.SUPABASE_SERVICE_KEY;
|
|
|
|
const supabase = createClient(supabaseUrl, supabaseServiceKey);
|
|
|
|
async function fixVectorTable() {
|
|
console.log('🔧 Fixing document_chunks table with vector type...\n');
|
|
|
|
try {
|
|
// Drop the existing table
|
|
console.log('📋 Dropping existing document_chunks table...');
|
|
const { error: dropError } = await supabase.rpc('exec_sql', {
|
|
sql: 'DROP TABLE IF EXISTS document_chunks CASCADE;'
|
|
});
|
|
|
|
if (dropError) {
|
|
console.log(`❌ Drop error: ${dropError.message}`);
|
|
} else {
|
|
console.log('✅ Document chunks table dropped successfully');
|
|
}
|
|
|
|
// Recreate with proper vector type
|
|
console.log('📋 Creating document_chunks table with vector type...');
|
|
const { error: createError } = await supabase.rpc('exec_sql', {
|
|
sql: `
|
|
CREATE TABLE document_chunks (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
document_id UUID REFERENCES documents(id) ON DELETE CASCADE,
|
|
content TEXT NOT NULL,
|
|
metadata JSONB,
|
|
embedding vector(1536),
|
|
chunk_index INTEGER NOT NULL,
|
|
section VARCHAR(255),
|
|
page_number INTEGER,
|
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
`
|
|
});
|
|
|
|
if (createError) {
|
|
console.log(`❌ Create error: ${createError.message}`);
|
|
} else {
|
|
console.log('✅ Document chunks table created with vector type');
|
|
}
|
|
|
|
// Create indexes
|
|
console.log('📋 Creating indexes...');
|
|
const indexSql = `
|
|
CREATE INDEX IF NOT EXISTS idx_document_chunks_document_id ON document_chunks(document_id);
|
|
CREATE INDEX IF NOT EXISTS idx_document_chunks_chunk_index ON document_chunks(chunk_index);
|
|
CREATE INDEX IF NOT EXISTS idx_document_chunks_embedding ON document_chunks USING ivfflat (embedding vector_cosine_ops);
|
|
`;
|
|
|
|
const { error: indexError } = await supabase.rpc('exec_sql', { sql: indexSql });
|
|
|
|
if (indexError) {
|
|
console.log(`❌ Index creation error: ${indexError.message}`);
|
|
} else {
|
|
console.log('✅ Indexes created successfully');
|
|
}
|
|
|
|
console.log('\n🎉 Vector table fixed successfully!');
|
|
|
|
} catch (error) {
|
|
console.log('❌ Error fixing vector table:', error.message);
|
|
}
|
|
}
|
|
|
|
fixVectorTable();
|