@@ -146,13 +146,30 @@ def test_add_texts_edge_cases(self, engine, vs):
146
146
assert len (results ) == 3
147
147
engine ._execute (f"TRUNCATE TABLE `{ DEFAULT_TABLE } `" )
148
148
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
+
149
156
def test_add_embedding (self , engine , vs ):
150
157
ids = [str (uuid .uuid4 ()) for _ in range (len (texts ))]
151
158
vs ._add_embeddings (texts , embeddings , metadatas , ids )
152
159
results = engine ._fetch (f"SELECT * FROM `{ DEFAULT_TABLE } `" )
153
160
assert len (results ) == 3
154
161
engine ._execute (f"TRUNCATE TABLE `{ DEFAULT_TABLE } `" )
155
162
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
+
156
173
def test_add_texts_custom (self , engine , vs_custom ):
157
174
ids = [str (uuid .uuid4 ()) for _ in range (len (texts ))]
158
175
vs_custom .add_texts (texts , ids = ids )
@@ -172,11 +189,50 @@ def test_add_texts_custom(self, engine, vs_custom):
172
189
assert len (results ) == 6
173
190
engine ._execute (f"TRUNCATE TABLE `{ CUSTOM_TABLE } `" )
174
191
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
+
175
217
def test_add_embedding_custom (self , engine , vs_custom ):
176
218
ids = [str (uuid .uuid4 ()) for _ in range (len (texts ))]
177
219
vs_custom ._add_embeddings (texts , embeddings , metadatas , ids )
178
220
results = engine ._fetch (f"SELECT * FROM `{ CUSTOM_TABLE } `" )
179
221
assert len (results ) == 3
180
222
engine ._execute (f"TRUNCATE TABLE `{ CUSTOM_TABLE } `" )
181
223
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
+
182
238
# Need tests for store metadata=False
0 commit comments