import asyncio import os import sys import numpy as np # Add server directory to path sys.path.append('/Users/mac/Projects/customerAgent/server') from app.services.vector_operations import VectorOperations async def test_alignment(): text = "Healthcare Services" print(f"🚀 Testing embedding alignment for: \"{text}\"") # Get passage embedding passage_emb = await VectorOperations.get_embedding(text, is_query=False) passage_vec = np.array(passage_emb, dtype=np.float32) # Get query embedding query_emb = await VectorOperations.get_embedding(text, is_query=True) query_vec = np.array(query_emb, dtype=np.float32) # Manual similarity def cosine_sim(v1, v2): v1 = v1 / np.linalg.norm(v1) v2 = v2 / np.linalg.norm(v2) return np.dot(v1, v2) sim = cosine_sim(passage_vec, query_vec) print(f"📊 Similarity between 'passage: {text}' and 'query: {text}': {sim:.4f}") # Test WITHOUT prefixes (internal raw similarity) # Note: get_embedding ALWAYS adds prefixes. # Let's see what happens if we use the same prefix for both. query_vec_2 = np.array(await VectorOperations.get_embedding(text, is_query=True), dtype=np.float32) sim_same = cosine_sim(query_vec, query_vec_2) print(f"📊 Similarity between 'query: {text}' and 'query: {text}': {sim_same:.4f}") if __name__ == "__main__": asyncio.run(test_alignment())