@@ -172,9 +172,9 @@ def test__cosine_similarity(n_test_embeddings):
172
172
result = builder ._block_cosine_similarity (embeddings , embeddings )
173
173
174
174
assert result .shape == expected .shape , "Result shape does not match expected shape"
175
- assert np .allclose (
176
- result , expected , atol = 1e-5
177
- ), "Cosine similarity does not match expected values"
175
+ assert np .allclose (result , expected , atol = 1e-5 ), (
176
+ "Cosine similarity does not match expected values"
177
+ )
178
178
179
179
180
180
# Test for the internal _find_similar_embedding_pairs method
@@ -212,14 +212,14 @@ def test__find_similar_embedding_pairs(n_test_embeddings, threshold, block_size)
212
212
213
213
for i , j , similarity_float in result :
214
214
assert i < j , "Pairs should be ordered (i < j)"
215
- assert (
216
- similarity_float >= threshold
217
- ), f"Similarity { similarity_float } should be >= { threshold } "
215
+ assert similarity_float >= threshold , (
216
+ f"Similarity { similarity_float } should be >= { threshold } "
217
+ )
218
218
for x , y , expected_similarity in expected :
219
219
if i == x and j == y :
220
- assert similarity_float == pytest .approx (
221
- expected_similarity
222
- ), "Cosine similarity does not match expected value"
220
+ assert similarity_float == pytest .approx (expected_similarity ), (
221
+ "Cosine similarity does not match expected value"
222
+ )
223
223
224
224
break
225
225
@@ -230,9 +230,9 @@ async def test_no_self_similarity_relationships(self, simple_kg):
230
230
builder = CosineSimilarityBuilder (property_name = "embedding" , threshold = 0.1 )
231
231
relationships = await builder .transform (copy .deepcopy (simple_kg ))
232
232
for r in relationships :
233
- assert (
234
- r . source . id != r . target . id
235
- ), "Self-relationships should not be created"
233
+ assert r . source . id != r . target . id , (
234
+ "Self-relationships should not be created"
235
+ )
236
236
237
237
@pytest .mark .asyncio
238
238
async def test_no_duplicate_relationships (self , simple_kg ):
@@ -260,9 +260,9 @@ async def test_all_below_threshold(self):
260
260
kg = KnowledgeGraph (nodes = [node1 , node2 ])
261
261
builder = CosineSimilarityBuilder (property_name = "embedding" , threshold = 0.5 )
262
262
relationships = await builder .transform (kg )
263
- assert (
264
- len ( relationships ) == 0
265
- ), "No relationships should be created below threshold"
263
+ assert len ( relationships ) == 0 , (
264
+ "No relationships should be created below threshold"
265
+ )
266
266
267
267
@pytest .mark .asyncio
268
268
async def test_all_above_threshold (self ):
@@ -287,7 +287,7 @@ async def test_malformed_embedding_raises(self):
287
287
async def test_cosine_similarity_builder_empty_graph (self ):
288
288
kg = KnowledgeGraph (nodes = [])
289
289
builder = CosineSimilarityBuilder (property_name = "embedding" )
290
- with pytest .raises (ValueError , match = "No nodes have a valid embedding" ):
290
+ with pytest .raises (ValueError ):
291
291
await builder .transform (kg )
292
292
293
293
@pytest .mark .asyncio
@@ -351,9 +351,9 @@ async def test_apply_transforms_cosine_similarity_builder(self, simple_kg):
351
351
# Should mutate kg in-place
352
352
apply_transforms (kg , builder , run_config = RunConfig (max_workers = 2 ))
353
353
# Check that relationships were added
354
- assert any (
355
- r . type == " cosine_similarity" for r in kg . relationships
356
- ), "No cosine_similarity relationships found after apply_transforms"
354
+ assert any (r . type == "cosine_similarity" for r in kg . relationships ), (
355
+ "No cosine_similarity relationships found after apply_transforms"
356
+ )
357
357
# Check that expected relationship exists
358
358
assert any (
359
359
str (r .source .id ) == "f353e5c2-e432-4d1e-84a8-d750c93d4edf"
@@ -419,9 +419,9 @@ async def test_apply_transforms_summary_cosine_similarity_builder(simple_kg):
419
419
)
420
420
kg = simple_kg
421
421
apply_transforms (kg , builder , run_config = RunConfig (max_workers = 2 ))
422
- assert any (
423
- r . type == " summary_cosine_similarity" for r in kg . relationships
424
- ), "No summary_cosine_similarity relationships found after apply_transforms"
422
+ assert any (r . type == "summary_cosine_similarity" for r in kg . relationships ), (
423
+ "No summary_cosine_similarity relationships found after apply_transforms"
424
+ )
425
425
assert any (
426
426
str (r .source .id ) == "f353e5c2-e432-4d1e-84a8-d750c93d4edf"
427
427
and str (r .target .id ) == "437c8c08-cef6-4ebf-a35f-93d6168b61a4"
0 commit comments