2021-10-03 04:46:29 +02:00
|
|
|
# Standard Packages
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
# Internal Packages
|
|
|
|
from src.search_type import asymmetric, image_search
|
2022-01-15 02:54:38 +01:00
|
|
|
from src.utils.rawconfig import ContentConfig, TextContentConfig, ImageContentConfig, SearchConfig, SymmetricSearchConfig, AsymmetricSearchConfig, ImageSearchConfig
|
2021-10-03 04:46:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='session')
|
2022-01-15 02:13:14 +01:00
|
|
|
def search_config(tmp_path_factory):
|
2021-10-03 04:46:29 +02:00
|
|
|
model_dir = tmp_path_factory.mktemp('data')
|
|
|
|
|
2022-01-15 02:54:38 +01:00
|
|
|
search_config = SearchConfig()
|
2022-01-15 02:13:14 +01:00
|
|
|
|
2022-01-15 02:54:38 +01:00
|
|
|
search_config.asymmetric = SymmetricSearchConfig(
|
2022-01-15 02:13:14 +01:00
|
|
|
encoder = "sentence-transformers/paraphrase-MiniLM-L6-v2",
|
|
|
|
cross_encoder = "cross-encoder/ms-marco-MiniLM-L-6-v2",
|
|
|
|
model_directory = model_dir
|
|
|
|
)
|
|
|
|
|
2022-01-15 02:54:38 +01:00
|
|
|
search_config.asymmetric = AsymmetricSearchConfig(
|
2022-01-15 02:13:14 +01:00
|
|
|
encoder = "sentence-transformers/msmarco-MiniLM-L-6-v3",
|
|
|
|
cross_encoder = "cross-encoder/ms-marco-MiniLM-L-6-v2",
|
|
|
|
model_directory = model_dir
|
|
|
|
)
|
|
|
|
|
2022-01-15 02:54:38 +01:00
|
|
|
search_config.image = ImageSearchConfig(
|
2022-01-15 02:13:14 +01:00
|
|
|
encoder = "clip-ViT-B-32",
|
|
|
|
model_directory = model_dir
|
|
|
|
)
|
|
|
|
|
|
|
|
return search_config
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='session')
|
|
|
|
def model_dir(search_config):
|
|
|
|
model_dir = search_config.asymmetric.model_directory
|
|
|
|
|
2021-10-03 04:46:29 +02:00
|
|
|
# Generate Image Embeddings from Test Images
|
2022-01-15 02:54:38 +01:00
|
|
|
content_config = ContentConfig()
|
|
|
|
content_config.image = ImageContentConfig(
|
2022-01-29 07:57:08 +01:00
|
|
|
input_directory = 'tests/data/images',
|
|
|
|
embeddings_file = model_dir.joinpath('image_embeddings.pt'),
|
2021-10-03 04:46:29 +02:00
|
|
|
batch_size = 10,
|
2021-12-04 18:02:19 +01:00
|
|
|
use_xmp_metadata = False)
|
2021-10-03 04:46:29 +02:00
|
|
|
|
2022-01-15 02:13:14 +01:00
|
|
|
image_search.setup(content_config.image, search_config.image, regenerate=False, verbose=True)
|
2021-10-03 04:46:29 +02:00
|
|
|
|
|
|
|
# Generate Notes Embeddings from Test Notes
|
2022-01-15 02:54:38 +01:00
|
|
|
content_config.org = TextContentConfig(
|
2022-01-29 07:57:08 +01:00
|
|
|
input_files = None,
|
|
|
|
input_filter = 'tests/data/notes/*.org',
|
|
|
|
compressed_jsonl = model_dir.joinpath('notes.jsonl.gz'),
|
|
|
|
embeddings_file = model_dir.joinpath('note_embeddings.pt'))
|
2021-10-03 04:46:29 +02:00
|
|
|
|
2022-01-15 02:13:14 +01:00
|
|
|
asymmetric.setup(content_config.org, search_config.asymmetric, regenerate=False, verbose=True)
|
2021-10-03 04:46:29 +02:00
|
|
|
|
|
|
|
return model_dir
|
2021-10-03 05:28:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='session')
|
2022-01-15 02:13:14 +01:00
|
|
|
def content_config(model_dir):
|
2022-01-15 02:54:38 +01:00
|
|
|
content_config = ContentConfig()
|
|
|
|
content_config.org = TextContentConfig(
|
2022-01-29 07:57:08 +01:00
|
|
|
input_files = None,
|
|
|
|
input_filter = 'tests/data/notes/*.org',
|
|
|
|
compressed_jsonl = model_dir.joinpath('notes.jsonl.gz'),
|
|
|
|
embeddings_file = model_dir.joinpath('note_embeddings.pt'))
|
2021-10-03 05:28:33 +02:00
|
|
|
|
2022-01-15 02:54:38 +01:00
|
|
|
content_config.image = ImageContentConfig(
|
2022-01-29 07:57:08 +01:00
|
|
|
input_directory = 'tests/data/images',
|
|
|
|
embeddings_file = model_dir.joinpath('image_embeddings.pt'),
|
2021-10-03 05:28:33 +02:00
|
|
|
batch_size = 10,
|
2021-12-04 18:02:19 +01:00
|
|
|
use_xmp_metadata = False)
|
2021-10-03 05:28:33 +02:00
|
|
|
|
2022-01-29 07:57:08 +01:00
|
|
|
return content_config
|