11import pytest
2- from app .store .vector import (
3- get_vector_store ,
4- ExtendedPgVector ,
5- AsyncPgVector ,
6- AtlasMongoVector ,
7- )
2+ from app .store .vector import get_vector_store
83from langchain_core .embeddings import Embeddings
94
10-
11- # Dummy embeddings' implementation.
5+ # Dummy embeddings implementation.
126class DummyEmbeddings (Embeddings ):
137 def embed_query (self , query : str ):
148 return [0.1 , 0.2 , 0.3 ]
@@ -17,89 +11,44 @@ def embed_documents(self, texts: list[str]) -> list[list[float]]:
1711 return [self .embed_query (text ) for text in texts ]
1812
1913
20- # Patch the create_vector_extension method to do nothing for tests using SQLite.
21- @pytest .fixture (autouse = True )
22- def patch_vector_extension (monkeypatch ):
23- monkeypatch .setattr (ExtendedPgVector , "create_vector_extension" , lambda self : None )
24-
25-
26- def test_get_vector_store_sync ():
14+ def test_get_vector_store_dummy_sync ():
2715 vs = get_vector_store (
28- connection_string = "sqlite:///:memory: " ,
16+ connection_string = "dummy_conn " ,
2917 embeddings = DummyEmbeddings (),
3018 collection_name = "dummy_collection" ,
31- mode = "sync " ,
19+ mode = "dummy " ,
3220 )
33- # Ensure that we get an instance of ExtendedPgVector.
34- assert isinstance (vs , ExtendedPgVector )
21+ # In dummy mode, get_all_ids should return an empty list.
22+ assert vs .get_all_ids () == []
23+ # Similarly, get_documents_by_ids should return an empty list.
24+ assert vs .get_documents_by_ids (["id1" , "id2" ]) == []
25+ # delete should be callable without raising an error.
26+ vs .delete (ids = ["id1" , "id2" ], collection_only = True )
3527
3628
37- def test_get_vector_store_async ():
29+ @pytest .mark .asyncio
30+ async def test_get_vector_store_dummy_async ():
3831 vs = get_vector_store (
39- connection_string = "sqlite:///:memory: " ,
32+ connection_string = "dummy_conn " ,
4033 embeddings = DummyEmbeddings (),
4134 collection_name = "dummy_collection" ,
42- mode = "async " ,
35+ mode = "dummy " ,
4336 )
44- # Ensure that we get an instance of AsyncPgVector.
45- assert isinstance (vs , AsyncPgVector )
46-
47-
48- # --- Atlas Mongo Tests ---
49- # Create dummy classes to simulate a MongoDB connection.
50- def find (query ):
51- # Return a list of dummy document dictionaries.
52- return [
53- {
54- "text" : "dummy text" ,
55- "file_id" : "dummy_id1" ,
56- "user_id" : "public" ,
57- "digest" : "abc123" ,
58- "source" : "dummy_source" ,
59- "page" : 1 ,
60- }
61- ]
62-
63-
64- class DummyCollection :
65- def distinct (self , field ):
66- return ["dummy_id1" , "dummy_id2" ]
67-
68- def delete_many (self , query ):
69- pass
70-
71-
72- class DummyDatabase :
73- def __getitem__ (self , collection_name ):
74- return DummyCollection ()
75-
76-
77- class DummyMongoClient :
78- def __init__ (self , connection_string ):
79- self .connection_string = connection_string
80-
81- def get_database (self ):
82- return DummyDatabase ()
83-
84-
85- # Patch pymongo.MongoClient so that get_vector_store uses our dummy.
86- @pytest .fixture (autouse = True )
87- def patch_mongo_client (monkeypatch ):
88- monkeypatch .setattr ("pymongo.MongoClient" , DummyMongoClient )
37+ # Even for async, since dummy mode doesn't require async behavior,
38+ # the same interface applies.
39+ assert vs .get_all_ids () == []
40+ assert vs .get_documents_by_ids (["id1" , "id2" ]) == []
41+ vs .delete (ids = ["id1" , "id2" ], collection_only = True )
8942
9043
91- def test_get_vector_store_atlas_mongo ():
44+ # --- Atlas Mongo Tests in Dummy Mode ---
45+ def test_get_vector_store_dummy_atlas_mongo ():
9246 vs = get_vector_store (
9347 connection_string = "dummy_conn" ,
9448 embeddings = DummyEmbeddings (),
9549 collection_name = "dummy_collection" ,
96- mode = "atlas-mongo " ,
50+ mode = "dummy " ,
9751 search_index = "dummy_index" ,
9852 )
99- # Ensure that we get an instance of AtlasMongoVector.
100- assert isinstance (vs , AtlasMongoVector )
101- # Test that get_all_ids returns our dummy IDs.
102- ids = vs .get_all_ids ()
103- assert isinstance (ids , list )
104- assert "dummy_id1" in ids
105- assert "dummy_id2" in ids
53+ # In dummy mode, this should also return an empty list of IDs.
54+ assert vs .get_all_ids () == []
0 commit comments