import { Memory } from "../../src/memory"; import dotenv from "dotenv"; // Load environment variables dotenv.config(); async function testSimpleMultihop() { console.log("๐Ÿงช Starting Simple Multihop Test"); if (!process.env.OPENAI_API_KEY) { console.error("Error: OPENAI_API_KEY environment variable is required"); process.exit(1); } const memory = new Memory({ embedder: { provider: "openai", config: { apiKey: process.env.OPENAI_API_KEY, model: "text-embedding-3-small", }, }, vectorStore: { provider: "memory", config: { dimension: 1536, }, }, llm: { provider: "openai_structured", config: { apiKey: process.env.OPENAI_API_KEY, model: "gpt-3.5-turbo", }, }, historyDbPath: ":memory:", }); const userId = "test-user"; // Add simple, clear memories console.log("๐Ÿ“ Adding test memories..."); await memory.add("I am working on a project called Alpha", { userId }); await memory.add("Project Alpha is a mobile app", { userId }); await memory.add("The app is for fitness tracking", { userId }); await memory.add("Sarah is our designer", { userId }); await memory.add("We use React Native for development", { userId }); console.log("โœ… Test memories added"); // Test 1: Simple search without multihop console.log("\n๐Ÿ” Test 1: Standard search"); try { const standardResult = await memory.search("What is Project Alpha?", { userId, useSearchAgents: false, limit: 3 }); console.log(`โœ… Standard search: ${standardResult.results.length} results`); } catch (error) { console.error("โŒ Standard search failed:", error); } // Test 2: Simple multihop search with very basic query console.log("\n๐Ÿ” Test 2: Multihop search (max 2 hops)"); try { const multihopResult = await memory.search("Tell me about the project", { userId, useSearchAgents: true, enableMultihop: true, maxHops: 2, limit: 3 }); console.log(`โœ… Multihop search: ${multihopResult.results.length} results`); if (multihopResult.agentAnalysis) { console.log(` - Multihop enabled: ${multihopResult.agentAnalysis.isMultihop || false}`); console.log(` - Hops used: ${multihopResult.agentAnalysis.multihopResults?.length || 'N/A'}`); } } catch (error) { console.error("โŒ Multihop search failed:", error); } // Test 3: Simple chat console.log("\n๐Ÿ’ฌ Test 3: Chat with custom instructions"); try { const chatResult = await memory.chat("What is Project Alpha?", { userId, enableMultihop: true, maxHops: 2, customInstructions: "Keep the response brief and factual." }); console.log(`โœ… Chat successful`); console.log(` - Response length: ${chatResult.response.length} chars`); console.log(` - Custom instructions applied: ${chatResult.metadata.customInstructions || false}`); console.log(` - Response: ${(chatResult.response || '[No response]').substring(0, 100)}...`); } catch (error) { console.error("โŒ Chat failed:", error); } // Clean up await memory.reset(); console.log("\nโœ… Simple multihop test completed!"); } testSimpleMultihop() .catch(error => { console.error("Fatal error:", error); process.exit(1); });