@@ -146,13 +146,30 @@ def test_add_texts_edge_cases(self, engine, vs):
146146 assert len (results ) == 3
147147 engine ._execute (f"TRUNCATE TABLE `{ DEFAULT_TABLE } `" )
148148
149+ def test_add_docs (self , engine , vs ):
150+ ids = [str (uuid .uuid4 ()) for i in range (len (texts ))]
151+ vs .add_documents (docs , ids = ids )
152+ results = engine ._fetch (f"SELECT * FROM `{ DEFAULT_TABLE } `" )
153+ assert len (results ) == 3
154+ engine ._execute (f"TRUNCATE TABLE `{ DEFAULT_TABLE } `" )
155+
149156 def test_add_embedding (self , engine , vs ):
150157 ids = [str (uuid .uuid4 ()) for _ in range (len (texts ))]
151158 vs ._add_embeddings (texts , embeddings , metadatas , ids )
152159 results = engine ._fetch (f"SELECT * FROM `{ DEFAULT_TABLE } `" )
153160 assert len (results ) == 3
154161 engine ._execute (f"TRUNCATE TABLE `{ DEFAULT_TABLE } `" )
155162
163+ def test_delete (self , engine , vs ):
164+ ids = [str (uuid .uuid4 ()) for _ in range (len (texts ))]
165+ vs .add_texts (texts , ids = ids )
166+ results = engine ._fetch (f"SELECT * FROM `{ DEFAULT_TABLE } `" )
167+ assert len (results ) == 3
168+ # delete an ID
169+ vs .delete ([ids [0 ]])
170+ results = engine ._fetch (f"SELECT * FROM `{ DEFAULT_TABLE } `" )
171+ assert len (results ) == 2
172+
156173 def test_add_texts_custom (self , engine , vs_custom ):
157174 ids = [str (uuid .uuid4 ()) for _ in range (len (texts ))]
158175 vs_custom .add_texts (texts , ids = ids )
@@ -172,11 +189,50 @@ def test_add_texts_custom(self, engine, vs_custom):
172189 assert len (results ) == 6
173190 engine ._execute (f"TRUNCATE TABLE `{ CUSTOM_TABLE } `" )
174191
192+ def test_add_docs_custom (self , engine , vs_custom ):
193+ ids = [str (uuid .uuid4 ()) for i in range (len (texts ))]
194+ docs = [
195+ Document (
196+ page_content = texts [i ],
197+ metadata = {"page" : str (i ), "source" : "google.com" },
198+ )
199+ for i in range (len (texts ))
200+ ]
201+ vs_custom .add_documents (docs , ids = ids )
202+
203+ results = engine ._fetch (f"SELECT * FROM `{ CUSTOM_TABLE } `" )
204+ content = [result ["mycontent" ] for result in results ]
205+ assert len (results ) == 3
206+ assert "foo" in content
207+ assert "bar" in content
208+ assert "baz" in content
209+ assert results [0 ]["myembedding" ]
210+ pages = [result ["page" ] for result in results ]
211+ assert "0" in pages
212+ assert "1" in pages
213+ assert "2" in pages
214+ assert results [0 ]["source" ] == "google.com"
215+ engine ._execute (f"TRUNCATE TABLE `{ CUSTOM_TABLE } `" )
216+
175217 def test_add_embedding_custom (self , engine , vs_custom ):
176218 ids = [str (uuid .uuid4 ()) for _ in range (len (texts ))]
177219 vs_custom ._add_embeddings (texts , embeddings , metadatas , ids )
178220 results = engine ._fetch (f"SELECT * FROM `{ CUSTOM_TABLE } `" )
179221 assert len (results ) == 3
180222 engine ._execute (f"TRUNCATE TABLE `{ CUSTOM_TABLE } `" )
181223
224+ def test_delete_custom (self , engine , vs_custom ):
225+ ids = [str (uuid .uuid4 ()) for _ in range (len (texts ))]
226+ vs_custom .add_texts (texts , ids = ids )
227+ results = engine ._fetch (f"SELECT * FROM `{ CUSTOM_TABLE } `" )
228+ content = [result ["mycontent" ] for result in results ]
229+ assert len (results ) == 3
230+ assert "foo" in content
231+ # delete an ID
232+ vs_custom .delete ([ids [0 ]])
233+ results = engine ._fetch (f"SELECT * FROM `{ CUSTOM_TABLE } `" )
234+ content = [result ["mycontent" ] for result in results ]
235+ assert len (results ) == 2
236+ assert "foo" not in content
237+
182238 # Need tests for store metadata=False
0 commit comments