From 22ba73e680971dc0cbe42420c1d41c010b9f426b Mon Sep 17 00:00:00 2001 From: Cyber MacGeddon Date: Sun, 8 Mar 2026 19:38:08 +0000 Subject: [PATCH] Fix embeddings integration --- .../test_document_rag_integration.py | 10 +++++++--- ...test_document_rag_streaming_integration.py | 3 ++- .../integration/test_graph_rag_integration.py | 10 +++++++--- .../test_graph_rag_streaming_integration.py | 3 ++- .../test_rag_streaming_protocol.py | 4 ++-- .../unit/test_retrieval/test_document_rag.py | 20 ++++++++++--------- 6 files changed, 31 insertions(+), 19 deletions(-) diff --git a/tests/integration/test_document_rag_integration.py b/tests/integration/test_document_rag_integration.py index 75f148f3..99e25ed5 100644 --- a/tests/integration/test_document_rag_integration.py +++ b/tests/integration/test_document_rag_integration.py @@ -27,9 +27,13 @@ class TestDocumentRagIntegration: def mock_embeddings_client(self): """Mock embeddings client that returns realistic vector embeddings""" client = AsyncMock() + # New batch format: [[[vectors_for_text1], ...]] + # One text input returns one vector set containing two vectors client.embed.return_value = [ - [0.1, 0.2, 0.3, 0.4, 0.5], # Realistic 5-dimensional embedding - [0.6, 0.7, 0.8, 0.9, 1.0] # Second embedding for testing + [ + [0.1, 0.2, 0.3, 0.4, 0.5], # First vector for text + [0.6, 0.7, 0.8, 0.9, 1.0] # Second vector for text + ] ] return client @@ -90,7 +94,7 @@ class TestDocumentRagIntegration: ) # Assert - Verify service coordination - mock_embeddings_client.embed.assert_called_once_with(query) + mock_embeddings_client.embed.assert_called_once_with([query]) mock_doc_embeddings_client.query.assert_called_once_with( [[0.1, 0.2, 0.3, 0.4, 0.5], [0.6, 0.7, 0.8, 0.9, 1.0]], diff --git a/tests/integration/test_document_rag_streaming_integration.py b/tests/integration/test_document_rag_streaming_integration.py index 52b86caf..db79ebac 100644 --- a/tests/integration/test_document_rag_streaming_integration.py +++ b/tests/integration/test_document_rag_streaming_integration.py @@ -30,7 +30,8 @@ class TestDocumentRagStreaming: def mock_embeddings_client(self): """Mock embeddings client""" client = AsyncMock() - client.embed.return_value = [[0.1, 0.2, 0.3, 0.4, 0.5]] + # New batch format: [[[vectors_for_text1]]] + client.embed.return_value = [[[0.1, 0.2, 0.3, 0.4, 0.5]]] return client @pytest.fixture diff --git a/tests/integration/test_graph_rag_integration.py b/tests/integration/test_graph_rag_integration.py index a0608819..94e8cf08 100644 --- a/tests/integration/test_graph_rag_integration.py +++ b/tests/integration/test_graph_rag_integration.py @@ -21,8 +21,12 @@ class TestGraphRagIntegration: def mock_embeddings_client(self): """Mock embeddings client that returns realistic vector embeddings""" client = AsyncMock() + # New batch format: [[[vectors_for_text1], ...]] + # One text input returns one vector set containing one vector client.embed.return_value = [ - [0.1, 0.2, 0.3, 0.4, 0.5], # Realistic 5-dimensional embedding + [ + [0.1, 0.2, 0.3, 0.4, 0.5], # Vector for text + ] ] return client @@ -120,8 +124,8 @@ class TestGraphRagIntegration: # Assert - Verify service coordination - # 1. Should compute embeddings for query - mock_embeddings_client.embed.assert_called_once_with(query) + # 1. Should compute embeddings for query (now expects list of texts) + mock_embeddings_client.embed.assert_called_once_with([query]) # 2. Should query graph embeddings to find relevant entities mock_graph_embeddings_client.query.assert_called_once() diff --git a/tests/integration/test_graph_rag_streaming_integration.py b/tests/integration/test_graph_rag_streaming_integration.py index 47dd84b6..f4d8ce8b 100644 --- a/tests/integration/test_graph_rag_streaming_integration.py +++ b/tests/integration/test_graph_rag_streaming_integration.py @@ -24,7 +24,8 @@ class TestGraphRagStreaming: def mock_embeddings_client(self): """Mock embeddings client""" client = AsyncMock() - client.embed.return_value = [[0.1, 0.2, 0.3, 0.4, 0.5]] + # New batch format: [[[vectors_for_text1]]] + client.embed.return_value = [[[0.1, 0.2, 0.3, 0.4, 0.5]]] return client @pytest.fixture diff --git a/tests/integration/test_rag_streaming_protocol.py b/tests/integration/test_rag_streaming_protocol.py index ba492687..19f2cf35 100644 --- a/tests/integration/test_rag_streaming_protocol.py +++ b/tests/integration/test_rag_streaming_protocol.py @@ -18,7 +18,7 @@ class TestGraphRagStreamingProtocol: def mock_embeddings_client(self): """Mock embeddings client""" client = AsyncMock() - client.embed.return_value = [[0.1, 0.2, 0.3]] + client.embed.return_value = [[[0.1, 0.2, 0.3]]] return client @pytest.fixture @@ -197,7 +197,7 @@ class TestDocumentRagStreamingProtocol: def mock_embeddings_client(self): """Mock embeddings client""" client = AsyncMock() - client.embed.return_value = [[0.1, 0.2, 0.3]] + client.embed.return_value = [[[0.1, 0.2, 0.3]]] return client @pytest.fixture diff --git a/tests/unit/test_retrieval/test_document_rag.py b/tests/unit/test_retrieval/test_document_rag.py index c9f5e8e1..9fd3fb95 100644 --- a/tests/unit/test_retrieval/test_document_rag.py +++ b/tests/unit/test_retrieval/test_document_rag.py @@ -132,9 +132,10 @@ class TestQuery: mock_embeddings_client = AsyncMock() mock_rag.embeddings_client = mock_embeddings_client - # Mock the embed method to return test vectors + # Mock the embed method to return test vectors in batch format + # New format: [[[vectors_for_text1]]] - returns first text's vector set expected_vectors = [[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]] - mock_embeddings_client.embed.return_value = expected_vectors + mock_embeddings_client.embed.return_value = [expected_vectors] # Initialize Query query = Query( @@ -148,10 +149,10 @@ class TestQuery: test_query = "What documents are relevant?" result = await query.get_vector(test_query) - # Verify embeddings client was called correctly - mock_embeddings_client.embed.assert_called_once_with(test_query) + # Verify embeddings client was called correctly (now expects list) + mock_embeddings_client.embed.assert_called_once_with([test_query]) - # Verify result matches expected vectors + # Verify result matches expected vectors (extracted from batch) assert result == expected_vectors @pytest.mark.asyncio @@ -170,8 +171,9 @@ class TestQuery: mock_rag.fetch_chunk = mock_fetch # Mock the embedding and document query responses + # New batch format: [[[vectors]]] - get_vector extracts [0] test_vectors = [[0.1, 0.2, 0.3]] - mock_embeddings_client.embed.return_value = test_vectors + mock_embeddings_client.embed.return_value = [test_vectors] # Mock document embeddings returns chunk_ids test_chunk_ids = ["doc/c1", "doc/c2"] @@ -190,10 +192,10 @@ class TestQuery: test_query = "Find relevant documents" result = await query.get_docs(test_query) - # Verify embeddings client was called - mock_embeddings_client.embed.assert_called_once_with(test_query) + # Verify embeddings client was called (now expects list) + mock_embeddings_client.embed.assert_called_once_with([test_query]) - # Verify doc embeddings client was called correctly + # Verify doc embeddings client was called correctly (with extracted vectors) mock_doc_embeddings_client.query.assert_called_once_with( test_vectors, limit=15,