@@ -31,15 +31,15 @@ def test_model_caching(self, mock_st_class):
3131 assert client1 .model is client2 .model
3232
3333 @patch ("lib.rag.embeddings.SentenceTransformer" )
34- def test_bge_prefix_added (self , mock_st_class ):
35- """BGE models need instruction prefix."""
34+ def test_bge_query_prefix_added (self , mock_st_class ):
35+ """BGE queries need instruction prefix."""
3636 mock_model = MagicMock ()
3737 mock_model .encode .return_value = np .array ([[0.1 ] * 768 ])
3838 mock_st_class .return_value = mock_model
3939
4040 config = RAGConfig (hf_model = "BAAI/bge-base-en-v1.5" )
4141 client = EmbeddingClient (config )
42- client .embed (["hello world" ])
42+ client .embed (["hello world" ], is_query = True )
4343
4444 call_args = mock_model .encode .call_args
4545 texts = call_args [0 ][0 ]
@@ -48,6 +48,23 @@ def test_bge_prefix_added(self, mock_st_class):
4848 for t in texts
4949 )
5050
51+ @patch ("lib.rag.embeddings.SentenceTransformer" )
52+ def test_bge_document_no_prefix (self , mock_st_class ):
53+ """BGE documents should NOT get prefix — only queries do."""
54+ mock_model = MagicMock ()
55+ mock_model .encode .return_value = np .array ([[0.1 ] * 768 ])
56+ mock_st_class .return_value = mock_model
57+
58+ config = RAGConfig (hf_model = "BAAI/bge-base-en-v1.5" )
59+ client = EmbeddingClient (config )
60+ client .embed (["hello world" ], is_query = False )
61+
62+ call_args = mock_model .encode .call_args
63+ texts = call_args [0 ][0 ]
64+ assert not any (t .startswith ("Represent" ) for t in texts )
65+ # Raw text preserved
66+ assert texts [0 ] == "hello world"
67+
5168 @patch ("lib.rag.embeddings.SentenceTransformer" )
5269 def test_non_bge_no_prefix (self , mock_st_class ):
5370 """Non-BGE models should not get prefix."""
@@ -57,7 +74,7 @@ def test_non_bge_no_prefix(self, mock_st_class):
5774
5875 config = RAGConfig (hf_model = "sentence-transformers/all-MiniLM-L6-v2" )
5976 client = EmbeddingClient (config )
60- client .embed (["hello world" ])
77+ client .embed (["hello world" ], is_query = True )
6178
6279 call_args = mock_model .encode .call_args
6380 texts = call_args [0 ][0 ]
@@ -84,7 +101,6 @@ def test_embed_single(self, mock_st_class):
84101
85102 assert isinstance (result , list )
86103 assert len (result ) == 768
87- # Value is normalized by encode(); just check it's a valid float
88104 assert isinstance (result [0 ], float )
89105
90106 @patch ("lib.rag.embeddings.SentenceTransformer" )
0 commit comments