Embedding¶
embed_for_matching is the notebook layer: DataFrame in, DataFrame out, for
interactive analysis. embed_texts is the service layer it's built on: plain text
list in, vectors plus metadata out, for callers already working in their own data
types (e.g. a live matching service).
matchminer_ai.embedding.embed ¶
Embedding step for trial/patient matching.
embed_for_matching ¶
embed_for_matching(df: DataFrame, *, entity_type: Literal['patient', 'trial'], config: MMAIConfig | None = None, return_metadata: bool = False) -> pd.DataFrame | tuple[pd.DataFrame, dict]
Convert trial or patient summaries into embedding vectors for semantic matching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input summaries to embed. For entity_type="patient" One row per patient. For entity_type="trial" One row per clinical space. |
required |
entity_type
|
('patient', 'trial')
|
Controls which summary column is used as the text to embed. |
"patient"
|
config
|
MMAIConfig
|
MMAI configuration containing embedding settings (model_path, device, prompt_file/query_prompt). Uses default preset when omitted. |
None
|
return_metadata
|
bool
|
When True, also return a metadata dict containing the config snapshot and model metadata for this run. |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the embedding plus identifier columns for matching. Columns¶For entity_type="patient" patient_id : str embedding : array-like Vector representation of the summary text in a shared semantic space. For entity_type="trial" space_trial_id : str embedding : array-like Vector representation of the summary text in a shared semantic space. |
tuple[DataFrame, dict]
|
When return_metadata is True, returns the DataFrame plus a metadata dict. |
Source code in src/matchminer_ai/embedding/embed.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
embed_texts ¶
embed_texts(texts: list[str], *, config: MMAIConfig | None = None) -> tuple[list[list[float]], dict]
Embed summary strings in input order and return vectors plus model metadata.
Accepts patient or trial text without identifiers or DataFrames. Uses the default preset when config is omitted and reuses the cached inference model. Model metadata includes model_name and model_sha.
Source code in src/matchminer_ai/embedding/embed.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |