const { VectorStore } = require('./dist/vector/store');
const { MockEmbedding } = require('./dist/vector/embedding');
const { SalesforceRAGRetriever } = require('./dist/vector/langchainRetriever');
async function testLangChainIntegration() {
console.log('Testing LangChain RAG Retriever integration...');
try {
// Initialize vector store
const embeddingModel = new MockEmbedding();
const vectorStore = new VectorStore({
host: 'localhost',
port: 5433,
database: 'sfdxrag',
user: 'postgres',
password: 'postgres'
}, embeddingModel);
console.log('\n=== 1. Testing Hybrid Retrieval ===');
const hybridRetriever = new SalesforceRAGRetriever({
vectorStore,
orgId: 'rag-test-org-123',
limit: 5,
searchMode: 'hybrid'
});
const hybridDocs = await hybridRetriever._getRelevantDocuments('phone number validation');
console.log('✓ Hybrid retrieval completed:', {
documentCount: hybridDocs.length,
searchMode: 'hybrid'
});
hybridDocs.forEach((doc, i) => {
console.log(` ${i + 1}. ${doc.metadata.name} (${doc.metadata.type}) - similarity: ${doc.metadata.similarity?.toFixed(3) || 'N/A'}`);
console.log(` Content preview: ${doc.pageContent.substring(0, 100)}...`);
});
console.log('\n=== 2. Testing Vector-Only Retrieval ===');
const vectorRetriever = new SalesforceRAGRetriever({
vectorStore,
orgId: 'rag-test-org-123',
limit: 3,
searchMode: 'vector'
});
const vectorDocs = await vectorRetriever._getRelevantDocuments('CallManagementService');
console.log('✓ Vector retrieval completed:', {
documentCount: vectorDocs.length,
searchMode: 'vector'
});
console.log('\n=== 3. Testing Type Filtering ===');
const typeFilteredRetriever = new SalesforceRAGRetriever({
vectorStore,
orgId: 'rag-test-org-123',
limit: 5,
searchMode: 'keyword',
types: ['ApexClass']
});
const typeDocs = await typeFilteredRetriever._getRelevantDocuments('validation');
console.log('✓ Type-filtered retrieval completed:', {
documentCount: typeDocs.length,
searchMode: 'keyword',
types: ['ApexClass']
});
console.log('\n=== 4. Testing Symbol Search ===');
const symbolRetriever = new SalesforceRAGRetriever({
vectorStore,
orgId: 'rag-test-org-123',
limit: 3,
searchMode: 'symbol'
});
const symbolDocs = await symbolRetriever._getRelevantDocuments('CallManagementService');
console.log('✓ Symbol retrieval completed:', {
documentCount: symbolDocs.length,
searchMode: 'symbol'
});
console.log('\n=== 5. Testing Configuration Updates ===');
const configurableRetriever = new SalesforceRAGRetriever({
vectorStore,
orgId: 'rag-test-org-123',
limit: 2,
searchMode: 'hybrid'
});
console.log('Initial config:', configurableRetriever.getConfig());
configurableRetriever.updateParams({
limit: 7,
searchMode: 'vector',
types: ['ApexClass', 'ApexTrigger']
});
console.log('Updated config:', configurableRetriever.getConfig());
const updatedDocs = await configurableRetriever._getRelevantDocuments('phone');
console.log('✓ Updated retriever completed:', {
documentCount: updatedDocs.length,
searchMode: 'vector',
types: ['ApexClass', 'ApexTrigger']
});
await vectorStore.close();
console.log('\n✅ LangChain integration testing completed successfully!');
} catch (error) {
console.error('❌ LangChain integration test failed:', error.message);
}
}
testLangChainIntegration();