@@ -41,8 +41,33 @@ def mock_index_client(self):
4141 def vector_store (self , mock_search_client , mock_index_client ):
4242 """Create an Azure AI Search vector store instance."""
4343 vector_store = AzureAISearchVectorStore (
44- collection_name = "test_vectors" ,
45- vector_store_schema_config = VectorStoreSchemaConfig (),
44+ vector_store_schema_config = VectorStoreSchemaConfig (
45+ index_name = "test_vectors" , vector_size = 5
46+ ),
47+ )
48+
49+ # Create the necessary mocks first
50+ vector_store .db_connection = mock_search_client
51+ vector_store .index_client = mock_index_client
52+
53+ vector_store .connect (
54+ url = TEST_AZURE_AI_SEARCH_URL ,
55+ api_key = TEST_AZURE_AI_SEARCH_KEY ,
56+ )
57+ return vector_store
58+
59+ @pytest .fixture
60+ def vector_store_custom (self , mock_search_client , mock_index_client ):
61+ """Create an Azure AI Search vector store instance."""
62+ vector_store = AzureAISearchVectorStore (
63+ vector_store_schema_config = VectorStoreSchemaConfig (
64+ index_name = "test_vectors" ,
65+ id_field = "id_custom" ,
66+ text_field = "text_custom" ,
67+ attributes_field = "attributes_custom" ,
68+ vector_field = "vector_custom" ,
69+ vector_size = 5 ,
70+ ),
4671 )
4772
4873 # Create the necessary mocks first
@@ -52,7 +77,6 @@ def vector_store(self, mock_search_client, mock_index_client):
5277 vector_store .connect (
5378 url = TEST_AZURE_AI_SEARCH_URL ,
5479 api_key = TEST_AZURE_AI_SEARCH_KEY ,
55- vector_size = 5 ,
5680 )
5781 return vector_store
5882
@@ -148,3 +172,72 @@ def none_embedder(text: str) -> None:
148172 )
149173 assert not mock_search_client .search .called
150174 assert len (results ) == 0
175+
176+ async def test_vector_store_customization (
177+ self ,
178+ vector_store_custom ,
179+ sample_documents ,
180+ mock_search_client ,
181+ mock_index_client ,
182+ ):
183+ """Test vector store customization with Azure AI Search."""
184+ # Setup mock responses
185+ mock_index_client .list_index_names .return_value = []
186+ mock_index_client .create_or_update_index = MagicMock ()
187+ mock_search_client .upload_documents = MagicMock ()
188+
189+ search_results = [
190+ {
191+ vector_store_custom .id_field : "doc1" ,
192+ vector_store_custom .text_field : "This is document 1" ,
193+ vector_store_custom .vector_field : [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ],
194+ vector_store_custom .attributes_field : '{"title": "Doc 1", "category": "test"}' ,
195+ "@search.score" : 0.9 ,
196+ },
197+ {
198+ vector_store_custom .id_field : "doc2" ,
199+ vector_store_custom .text_field : "This is document 2" ,
200+ vector_store_custom .vector_field : [0.2 , 0.3 , 0.4 , 0.5 , 0.6 ],
201+ vector_store_custom .attributes_field : '{"title": "Doc 2", "category": "test"}' ,
202+ "@search.score" : 0.8 ,
203+ },
204+ ]
205+ mock_search_client .search .return_value = search_results
206+
207+ mock_search_client .get_document .return_value = {
208+ vector_store_custom .id_field : "doc1" ,
209+ vector_store_custom .text_field : "This is document 1" ,
210+ vector_store_custom .vector_field : [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ],
211+ vector_store_custom .attributes_field : '{"title": "Doc 1", "category": "test"}' ,
212+ }
213+
214+ vector_store_custom .load_documents (sample_documents )
215+ assert mock_index_client .create_or_update_index .called
216+ assert mock_search_client .upload_documents .called
217+
218+ filter_query = vector_store_custom .filter_by_id (["doc1" , "doc2" ])
219+ assert (
220+ filter_query
221+ == f"search.in({ vector_store_custom .id_field } , 'doc1,doc2', ',')"
222+ )
223+
224+ vector_results = vector_store_custom .similarity_search_by_vector (
225+ [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ], k = 2
226+ )
227+ assert len (vector_results ) == 2
228+ assert vector_results [0 ].document .id == "doc1"
229+ assert vector_results [0 ].score == 0.9
230+
231+ # Define a simple text embedder function for testing
232+ def mock_embedder (text : str ) -> list [float ]:
233+ return [0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]
234+
235+ text_results = vector_store_custom .similarity_search_by_text (
236+ "test query" , mock_embedder , k = 2
237+ )
238+ assert len (text_results ) == 2
239+
240+ doc = vector_store_custom .search_by_id ("doc1" )
241+ assert doc .id == "doc1"
242+ assert doc .text == "This is document 1"
243+ assert doc .attributes ["title" ] == "Doc 1"
0 commit comments