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
119 lines
4.3 KiB
JavaScript
119 lines
4.3 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 testVectorIntegration() {
|
|
console.log('🧪 Testing vector integration...\n');
|
|
|
|
try {
|
|
// Test 1: Create a test document first
|
|
console.log('📋 Test 1: Creating test document...');
|
|
const { data: docData, error: docError } = await supabase
|
|
.from('documents')
|
|
.insert({
|
|
user_id: 'test-user-id',
|
|
original_file_name: 'vector-test.pdf',
|
|
file_path: 'test/path',
|
|
file_size: 1024,
|
|
status: 'completed'
|
|
})
|
|
.select()
|
|
.single();
|
|
|
|
if (docError) {
|
|
console.log(`❌ Document creation error: ${docError.message}`);
|
|
return;
|
|
} else {
|
|
console.log('✅ Test document created successfully');
|
|
}
|
|
|
|
// Test 2: Insert a document chunk with vector embedding
|
|
console.log('📋 Test 2: Inserting document chunk with vector embedding...');
|
|
const testEmbedding = Array.from({length: 1536}, () => Math.random() - 0.5); // Random vector
|
|
|
|
const { data: insertData, error: insertError } = await supabase
|
|
.from('document_chunks')
|
|
.insert({
|
|
document_id: docData.id,
|
|
content: 'This is a test document chunk for vector integration testing.',
|
|
metadata: { test: true, source: 'vector-test' },
|
|
embedding: testEmbedding,
|
|
chunk_index: 0,
|
|
section: 'test-section',
|
|
page_number: 1
|
|
})
|
|
.select();
|
|
|
|
if (insertError) {
|
|
console.log(`❌ Insert error: ${insertError.message}`);
|
|
return;
|
|
} else {
|
|
console.log('✅ Document chunk inserted successfully');
|
|
}
|
|
|
|
// Test 3: Query the inserted chunk
|
|
console.log('📋 Test 3: Querying inserted document chunk...');
|
|
const { data: queryData, error: queryError } = await supabase
|
|
.from('document_chunks')
|
|
.select('*')
|
|
.eq('document_id', docData.id)
|
|
.single();
|
|
|
|
if (queryError) {
|
|
console.log(`❌ Query error: ${queryError.message}`);
|
|
} else {
|
|
console.log('✅ Document chunk queried successfully');
|
|
console.log(` Content: ${queryData.content}`);
|
|
console.log(` Embedding length: ${queryData.embedding.length}`);
|
|
}
|
|
|
|
// Test 4: Vector similarity search
|
|
console.log('📋 Test 4: Testing vector similarity search...');
|
|
const searchEmbedding = Array.from({length: 1536}, () => Math.random() - 0.5);
|
|
|
|
const { data: searchData, error: searchError } = await supabase.rpc('match_document_chunks', {
|
|
query_embedding: searchEmbedding,
|
|
match_threshold: 0.1,
|
|
match_count: 5
|
|
});
|
|
|
|
if (searchError) {
|
|
console.log(`❌ Vector search error: ${searchError.message}`);
|
|
} else {
|
|
console.log('✅ Vector similarity search working');
|
|
console.log(` Found ${searchData?.length || 0} similar chunks`);
|
|
}
|
|
|
|
// Clean up test data
|
|
console.log('📋 Cleaning up test data...');
|
|
const { error: deleteChunkError } = await supabase
|
|
.from('document_chunks')
|
|
.delete()
|
|
.eq('document_id', docData.id);
|
|
|
|
const { error: deleteDocError } = await supabase
|
|
.from('documents')
|
|
.delete()
|
|
.eq('id', docData.id);
|
|
|
|
if (deleteChunkError || deleteDocError) {
|
|
console.log(`❌ Cleanup error: ${deleteChunkError?.message || deleteDocError?.message}`);
|
|
} else {
|
|
console.log('✅ Test data cleaned up');
|
|
}
|
|
|
|
console.log('\n🎉 Vector integration test completed successfully!');
|
|
|
|
} catch (error) {
|
|
console.log('❌ Vector integration test failed:', error.message);
|
|
}
|
|
}
|
|
|
|
testVectorIntegration();
|