|
1 | 1 | import shutil
|
2 | 2 | from pathlib import Path
|
| 3 | +import threading |
3 | 4 |
|
4 | 5 | import pytest
|
5 | 6 |
|
@@ -411,29 +412,30 @@ def get_test_vectors(shape):
|
411 | 412 | 'IVF-Cos-SQ8', 'IVF-Cos', 'IVF-Jaccard-Binary', 'IVF-Hamming-Binary',
|
412 | 413 | 'Flat-IP-SQ8', 'Flat-IP', 'Flat-L2sq-SQ8', 'Flat-L2sq', 'Flat-Cos-SQ8', 'Flat-Cos',
|
413 | 414 | 'Flat-Jaccard-Binary', 'Flat-Hamming-Binary']:
|
414 |
| - db = ExclusiveDB(dim=1024, database_path='test_local_db', |
415 |
| - chunk_size=10000) |
416 |
| - |
417 |
| - # You can perform this operation multiple times, and the data will be appended to the database. |
418 |
| - with db.insert_session(): |
419 |
| - # Define the initial ID. |
420 |
| - id = 0 |
421 |
| - vectors = [] |
422 |
| - for t in get_test_vectors((100000, 1024)): |
423 |
| - if id == 0: |
424 |
| - query = t |
425 |
| - vectors.append((t, id)) |
426 |
| - id += 1 |
427 |
| - |
428 |
| - # Here, normalization can be directly specified, achieving the same effect as `t = t / np.linalg.norm(t) `. |
429 |
| - db.bulk_add_items(vectors) |
430 |
| - |
431 |
| - db.build_index(index_mode=index_mode) |
432 |
| - index, score, field = db.search(query, k=10) |
433 |
| - |
434 |
| - assert len(index) == len(score) == 10 |
435 |
| - |
436 |
| - db.delete() |
| 415 | + with threading.RLock(): |
| 416 | + db = ExclusiveDB(dim=10, database_path='test_local_db', |
| 417 | + chunk_size=10000) |
| 418 | + |
| 419 | + # You can perform this operation multiple times, and the data will be appended to the database. |
| 420 | + with db.insert_session(): |
| 421 | + # Define the initial ID. |
| 422 | + id = 0 |
| 423 | + vectors = [] |
| 424 | + for t in get_test_vectors((100000, 10)): |
| 425 | + if id == 0: |
| 426 | + query = t |
| 427 | + vectors.append((t, id)) |
| 428 | + id += 1 |
| 429 | + |
| 430 | + # Here, normalization can be directly specified, achieving the same effect as `t = t / np.linalg.norm(t) `. |
| 431 | + db.bulk_add_items(vectors) |
| 432 | + |
| 433 | + db.build_index(index_mode=index_mode) |
| 434 | + index, score, field = db.search(query, k=10) |
| 435 | + |
| 436 | + assert len(index) == len(score) == 10 |
| 437 | + |
| 438 | + db.delete() |
437 | 439 |
|
438 | 440 |
|
439 | 441 | def test_transactions():
|
|
0 commit comments