comparator-recommender 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- comparator_recommender/__init__.py +10 -0
- comparator_recommender/adapters.py +57 -0
- comparator_recommender/backends/__init__.py +6 -0
- comparator_recommender/backends/base.py +54 -0
- comparator_recommender/backends/postgresql.py +620 -0
- comparator_recommender/config.py +29 -0
- comparator_recommender/models.py +98 -0
- comparator_recommender/plugin.py +197 -0
- comparator_recommender/services.py +74 -0
- comparator_recommender/setup_cli.py +77 -0
- comparator_recommender/tools.py +47 -0
- comparator_recommender-0.1.1.dist-info/METADATA +94 -0
- comparator_recommender-0.1.1.dist-info/RECORD +15 -0
- comparator_recommender-0.1.1.dist-info/WHEEL +4 -0
- comparator_recommender-0.1.1.dist-info/entry_points.txt +5 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Comparator Recommender plugin configuration MWE."""
|
|
2
|
+
|
|
3
|
+
from comparator_recommender.config import ComparatorRecommenderConfig
|
|
4
|
+
from comparator_recommender.plugin import ComparatorRecommenderPlugin, plugin
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"ComparatorRecommenderConfig",
|
|
8
|
+
"ComparatorRecommenderPlugin",
|
|
9
|
+
"plugin",
|
|
10
|
+
]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Connections to the comparator catalogue and its embedding model."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
|
|
6
|
+
from groundworkers.plugins import PluginReadinessResult
|
|
7
|
+
from oa_configurator import ResolvedDatabase
|
|
8
|
+
from omop_llm import ModelBackend
|
|
9
|
+
|
|
10
|
+
from comparator_recommender.backends import (
|
|
11
|
+
ComparatorSelectorBackend,
|
|
12
|
+
PostgresComparatorSelectorBackend,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
|
+
class ComparatorDataAdapter:
|
|
18
|
+
"""Own the database-backed comparator operations."""
|
|
19
|
+
|
|
20
|
+
database: ResolvedDatabase
|
|
21
|
+
backend: ComparatorSelectorBackend
|
|
22
|
+
|
|
23
|
+
@classmethod
|
|
24
|
+
def build(
|
|
25
|
+
cls,
|
|
26
|
+
database: ResolvedDatabase,
|
|
27
|
+
model_backend_factory: Callable[[], ModelBackend] | None = None,
|
|
28
|
+
model_source: str | None = None,
|
|
29
|
+
) -> "ComparatorDataAdapter":
|
|
30
|
+
return cls(
|
|
31
|
+
database=database,
|
|
32
|
+
backend=PostgresComparatorSelectorBackend(
|
|
33
|
+
engine=database.create_engine(register_claims=False),
|
|
34
|
+
schema=database.schema_name or "public",
|
|
35
|
+
model_backend_factory=model_backend_factory,
|
|
36
|
+
model_source=model_source,
|
|
37
|
+
),
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
def find_target(self, name: str, top_n: int) -> list[tuple[int, str]]:
|
|
41
|
+
return self.backend.find_target(name, top_n)
|
|
42
|
+
|
|
43
|
+
def recommend_comparators(
|
|
44
|
+
self, target_id: int, top_n: int, min_databases: int
|
|
45
|
+
) -> list[tuple[float, str]]:
|
|
46
|
+
return self.backend.recommend_comparators(target_id, top_n, min_databases)
|
|
47
|
+
|
|
48
|
+
def insert_data(self, cohort_table_path: str, similarity_table_path: str) -> None:
|
|
49
|
+
self.backend.insert_data(cohort_table_path, similarity_table_path)
|
|
50
|
+
|
|
51
|
+
def create_embedding_vectors(self) -> None:
|
|
52
|
+
self.backend.create_embedding_vectors()
|
|
53
|
+
|
|
54
|
+
def verify_readiness(self) -> PluginReadinessResult:
|
|
55
|
+
"""Return the backend's read-only readiness report."""
|
|
56
|
+
|
|
57
|
+
return self.backend.verify_readiness()
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"""Backend implementations for comparator catalogue storage."""
|
|
2
|
+
|
|
3
|
+
from comparator_recommender.backends.base import ComparatorSelectorBackend
|
|
4
|
+
from comparator_recommender.backends.postgresql import PostgresComparatorSelectorBackend
|
|
5
|
+
|
|
6
|
+
__all__ = ["ComparatorSelectorBackend", "PostgresComparatorSelectorBackend"]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Storage-independent comparator backend contract."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from abc import ABC, abstractmethod
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
|
|
8
|
+
from groundworkers.plugins import PluginReadinessResult
|
|
9
|
+
from omop_llm import ModelBackend
|
|
10
|
+
from sqlalchemy import Engine
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ComparatorSelectorBackend(ABC):
|
|
14
|
+
"""Operations required by the comparator recommender service."""
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
engine: Engine,
|
|
19
|
+
schema: str,
|
|
20
|
+
model_backend_factory: Callable[[], ModelBackend] | None = None,
|
|
21
|
+
model_source: str | None = None,
|
|
22
|
+
) -> None:
|
|
23
|
+
if not schema.strip():
|
|
24
|
+
raise ValueError("schema must not be empty")
|
|
25
|
+
self.engine = engine
|
|
26
|
+
self.schema = schema
|
|
27
|
+
self.model_backend_factory = model_backend_factory
|
|
28
|
+
self.model_source = model_source
|
|
29
|
+
|
|
30
|
+
def pre_initialise_store(self) -> None:
|
|
31
|
+
"""Prepare mutating setup prerequisites; the default is a no-op.
|
|
32
|
+
|
|
33
|
+
Backend construction and readiness checks are deliberately read-only.
|
|
34
|
+
Mutating setup operations call this hook explicitly when needed.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
@abstractmethod
|
|
38
|
+
def find_target(self, name: str, top_n: int) -> list[tuple[int, str]]: ...
|
|
39
|
+
|
|
40
|
+
@abstractmethod
|
|
41
|
+
def recommend_comparators(
|
|
42
|
+
self, target_id: int, top_n: int, min_databases: int
|
|
43
|
+
) -> list[tuple[float, str]]: ...
|
|
44
|
+
|
|
45
|
+
@abstractmethod
|
|
46
|
+
def insert_data(
|
|
47
|
+
self, cohort_table_path: str, similarity_table_path: str
|
|
48
|
+
) -> None: ...
|
|
49
|
+
|
|
50
|
+
@abstractmethod
|
|
51
|
+
def create_embedding_vectors(self) -> None: ...
|
|
52
|
+
|
|
53
|
+
@abstractmethod
|
|
54
|
+
def verify_readiness(self) -> PluginReadinessResult: ...
|