Return True if the stored metadata is compatible with the requested parameters.
(metadata: dict, model_path: str, content: Sequence[ContentType])
| 94 | |
| 95 | |
| 96 | def _metadata_matches(metadata: dict, model_path: str, content: Sequence[ContentType]) -> bool: |
| 97 | """Return True if the stored metadata is compatible with the requested parameters.""" |
| 98 | from semble.chunking.chunking import _DESIRED_CHUNK_LENGTH_CHARS # avoid circular import at module level |
| 99 | |
| 100 | try: |
| 101 | content_type = tuple(ContentType(s) for s in metadata["content_type"]) |
| 102 | # chunk_size is absent in indexes built before this field was added; treat None as mismatch |
| 103 | # so old caches are transparently rebuilt with the current chunk size. |
| 104 | chunk_size_ok = metadata.get("chunk_size") == _DESIRED_CHUNK_LENGTH_CHARS |
| 105 | return metadata["model_path"] == model_path and set(content_type) == set(content) and chunk_size_ok |
| 106 | except (KeyError, ValueError): |
| 107 | return False |
| 108 | |
| 109 | |
| 110 | def get_validated_cache(path: str, model_path: str | None, content: Sequence[ContentType]) -> Path | None: |
no test coverage detected