/** * Agent Forum v4 - Multi-Vec Isolation PoC * * Verifies the concept of preventing semantic bleed by utilizing isolated, * separate vector databases for different domains (e.g., docs vs telemetry) * rather than dumping all embeddings into a single database. */ // Mock representation of an embedded vector database instance class MockVectorDB { private data: Map = new Map(); public name: string; constructor(name: string) { this.name = name; } insert(id: string, vector: number[]) { this.data.set(id, vector); } // Simplified cosine similarity mock query(vector: number[]): { id: string, score: number }[] { const results = []; for (const [id, vec] of this.data.entries()) { // In a real scenario, this is mathematically calculating cosine similarity // For the PoC, we just check if it's the exact same vector for a 1.0 score const isExactMatch = vector.every((val, i) => val === vec[i]); if (isExactMatch) { results.push({ id, score: 1.0 }); } else { // Mock random low score for non-matches results.push({ id, score: 0.1 }); } } return results.sort((a, b) => b.score - a.score); } } function runPoC() { console.log("Running Multi-Vec Isolation PoC tests..."); // 1. Initialize isolated databases const docsDb = new MockVectorDB("docs_graph.sqlite"); const telemetryDb = new MockVectorDB("telemetry_graph.sqlite"); // 2. Insert domain-specific data // Mock vector for "How to implement authentication" const authDocVector = [0.1, 0.8, 0.2]; docsDb.insert("doc_auth_guide", authDocVector); // Mock vector for "High latency in database query" const latencyTelemetryVector = [0.9, 0.1, 0.1]; telemetryDb.insert("tel_high_latency", latencyTelemetryVector); // 3. Query the Docs DB for an architecture question console.log(`Querying ${docsDb.name} for architecture context...`); const docsResult = docsDb.query(authDocVector); if (docsResult[0].id === "doc_auth_guide" && docsResult[0].score > 0.8) { console.log(`✅ Found relevant doc in ${docsDb.name}`); } else { console.error(`❌ Failed to find doc in ${docsDb.name}`); Deno.exit(1); } // 4. Prove Semantic Isolation (No Bleed) // If we query the Telemetry DB with an architecture question, it should NOT return telemetry data console.log(`Querying ${telemetryDb.name} with architecture context to prove isolation...`); const isolatedResult = telemetryDb.query(authDocVector); if (isolatedResult[0].score < 0.5) { console.log(`✅ Semantic isolation confirmed. Telemetry DB did not return high confidence for a docs query.`); } else { console.error(`❌ Semantic bleed detected!`); Deno.exit(1); } console.log("✅ Multi-Vec Isolation PoC successful: Domain-specific semantic bleed prevented."); } if (import.meta.main) { runPoC(); }