RAG-HPO 0.1.0__tar.gz
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.
- rag_hpo-0.1.0/.github/actions/install_package/action.yaml +25 -0
- rag_hpo-0.1.0/.github/actions/python_from_pyproject/action.yaml +22 -0
- rag_hpo-0.1.0/.github/actions/setup_env/action.yaml +31 -0
- rag_hpo-0.1.0/.github/workflows/cd.yaml +36 -0
- rag_hpo-0.1.0/.github/workflows/ci.yaml +44 -0
- rag_hpo-0.1.0/.github/workflows/master_cache.yaml +30 -0
- rag_hpo-0.1.0/.gitignore +218 -0
- rag_hpo-0.1.0/.idea/.gitignore +5 -0
- rag_hpo-0.1.0/LICENSE +21 -0
- rag_hpo-0.1.0/PKG-INFO +197 -0
- rag_hpo-0.1.0/README.md +148 -0
- rag_hpo-0.1.0/pyproject.toml +48 -0
- rag_hpo-0.1.0/ruff.toml +134 -0
- rag_hpo-0.1.0/setup.cfg +4 -0
- rag_hpo-0.1.0/src/RAG_HPO.egg-info/PKG-INFO +197 -0
- rag_hpo-0.1.0/src/RAG_HPO.egg-info/SOURCES.txt +34 -0
- rag_hpo-0.1.0/src/RAG_HPO.egg-info/dependency_links.txt +1 -0
- rag_hpo-0.1.0/src/RAG_HPO.egg-info/requires.txt +14 -0
- rag_hpo-0.1.0/src/RAG_HPO.egg-info/top_level.txt +1 -0
- rag_hpo-0.1.0/src/rag_hpo/__init__.py +0 -0
- rag_hpo-0.1.0/src/rag_hpo/_hpo_df_builder.py +108 -0
- rag_hpo-0.1.0/src/rag_hpo/_version.py +21 -0
- rag_hpo-0.1.0/src/rag_hpo/checkpoint_store.py +96 -0
- rag_hpo-0.1.0/src/rag_hpo/constants.py +21 -0
- rag_hpo-0.1.0/src/rag_hpo/data/__init__.py +0 -0
- rag_hpo-0.1.0/src/rag_hpo/data/test_cases.csv +117 -0
- rag_hpo-0.1.0/src/rag_hpo/data/test_data.py +13 -0
- rag_hpo-0.1.0/src/rag_hpo/embedder.py +117 -0
- rag_hpo-0.1.0/src/rag_hpo/embedding_model.py +134 -0
- rag_hpo-0.1.0/src/rag_hpo/hit.py +8 -0
- rag_hpo-0.1.0/src/rag_hpo/hpo_doc.py +17 -0
- rag_hpo-0.1.0/src/rag_hpo/llm_client.py +134 -0
- rag_hpo-0.1.0/src/rag_hpo/ontology.py +82 -0
- rag_hpo-0.1.0/src/rag_hpo/rag_hpo.py +909 -0
- rag_hpo-0.1.0/src/rag_hpo/utils.py +14 -0
- rag_hpo-0.1.0/tests/test_pipeline.py +39 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: Install a Python Package
|
|
2
|
+
description: 'Installs a specified Python package from a requirements file, allowing for flexible package management.'
|
|
3
|
+
|
|
4
|
+
inputs:
|
|
5
|
+
requirements-path:
|
|
6
|
+
required: true
|
|
7
|
+
description: Path to the requirements file
|
|
8
|
+
package:
|
|
9
|
+
required: true
|
|
10
|
+
description: Package you would like to install from the requirements file
|
|
11
|
+
|
|
12
|
+
runs:
|
|
13
|
+
using: composite
|
|
14
|
+
steps:
|
|
15
|
+
- name: Extract Package Version
|
|
16
|
+
id: extract_package_version
|
|
17
|
+
shell: bash
|
|
18
|
+
run: |
|
|
19
|
+
echo "PACKAGE_LINE=$(grep -w "^${{ inputs.package }}" ${{ inputs.requirements-path }} || echo "${{ inputs.package }}")" >> $GITHUB_OUTPUT
|
|
20
|
+
|
|
21
|
+
- name: Install Package
|
|
22
|
+
shell: bash
|
|
23
|
+
run: |
|
|
24
|
+
python -m pip install --upgrade pip
|
|
25
|
+
pip install "${{ steps.extract_package_version.outputs.PACKAGE_LINE }}"
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: Install python from pyproject.toml
|
|
2
|
+
description: 'Installs Python from the version found in the pyproject.toml'
|
|
3
|
+
|
|
4
|
+
inputs:
|
|
5
|
+
pyproject-file-path:
|
|
6
|
+
required: False
|
|
7
|
+
description: "Path to the pyproject.toml including filename"
|
|
8
|
+
default: "./pyproject.toml"
|
|
9
|
+
|
|
10
|
+
runs:
|
|
11
|
+
using: composite
|
|
12
|
+
steps:
|
|
13
|
+
- name: Get project version with yq
|
|
14
|
+
id: get_python_version
|
|
15
|
+
uses: mikefarah/yq@v4.46.1
|
|
16
|
+
with:
|
|
17
|
+
cmd: yq '.project.requires-python' ${{ inputs.pyproject-file-path }}
|
|
18
|
+
|
|
19
|
+
- name: Set up Python
|
|
20
|
+
uses: actions/setup-python@v5.6.0
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ steps.get_python_version.outputs.result }}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Setup/Cache Env
|
|
2
|
+
description: 'Sets up and caches a python env. Will only install dependencies if no cache was hit.'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
inputs:
|
|
6
|
+
pyproject-file-path:
|
|
7
|
+
required: False
|
|
8
|
+
description: "Path to the pyproject.toml including filename"
|
|
9
|
+
default: "./pyproject.toml"
|
|
10
|
+
runs:
|
|
11
|
+
using: composite
|
|
12
|
+
steps:
|
|
13
|
+
- name: Setup Python from pyproject.toml
|
|
14
|
+
uses: ./.github/actions/python_from_pyproject
|
|
15
|
+
with:
|
|
16
|
+
pyproject-file-path: ${{ inputs.pyproject-file-path }}
|
|
17
|
+
|
|
18
|
+
- name: Cache Env
|
|
19
|
+
uses: actions/cache@v4.2.3
|
|
20
|
+
id: env-cache
|
|
21
|
+
with:
|
|
22
|
+
path: ${{ env.pythonLocation }}
|
|
23
|
+
key: ${{ hashFiles('./requirements/requirements.txt') }}-${{ hashFiles('./requirements/requirements_test.txt') }}
|
|
24
|
+
|
|
25
|
+
- name: Install Dependencies
|
|
26
|
+
if: ${{ steps.env-cache.outputs.cache-hit != 'true' }}
|
|
27
|
+
run: |
|
|
28
|
+
python -m pip install --upgrade pip
|
|
29
|
+
pip install -r requirements/requirements.txt
|
|
30
|
+
pip install -r requirements/requirements_test.txt
|
|
31
|
+
shell: bash
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: CD
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish-to-pypi:
|
|
9
|
+
name: Build distribution 📦
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
permissions:
|
|
12
|
+
id-token: write
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- name: Check out Repo
|
|
16
|
+
uses: actions/checkout@v4
|
|
17
|
+
with:
|
|
18
|
+
persist-credentials: false
|
|
19
|
+
fetch-depth: 0
|
|
20
|
+
|
|
21
|
+
- name: Setup Python from pyproject.toml
|
|
22
|
+
uses: ./.github/actions/python_from_pyproject
|
|
23
|
+
|
|
24
|
+
- name: Install build
|
|
25
|
+
run: >-
|
|
26
|
+
pip install build==1.2.2.post1
|
|
27
|
+
|
|
28
|
+
- name: Build a binary wheel and a source tarball
|
|
29
|
+
run: python3 -m build
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
- name: Publish distribution 📦 to PyPI
|
|
33
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
34
|
+
with:
|
|
35
|
+
packages-dir: dist/
|
|
36
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
|
|
6
|
+
permissions:
|
|
7
|
+
id-token: write
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
env:
|
|
11
|
+
PYTEST_ADDOPTS: "--color=yes"
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
formatting:
|
|
15
|
+
name: Formatting
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
timeout-minutes: 15
|
|
18
|
+
steps:
|
|
19
|
+
- name: Check out Repo
|
|
20
|
+
uses: actions/checkout@v4
|
|
21
|
+
with:
|
|
22
|
+
fetch-depth: 0
|
|
23
|
+
|
|
24
|
+
- name: Ruff Formatting
|
|
25
|
+
uses: astral-sh/ruff-action@v3.5.0
|
|
26
|
+
with:
|
|
27
|
+
version-file: "pyproject.toml"
|
|
28
|
+
args: "format --check"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
linting:
|
|
32
|
+
name: Linting
|
|
33
|
+
runs-on: ubuntu-latest
|
|
34
|
+
timeout-minutes: 15
|
|
35
|
+
steps:
|
|
36
|
+
- name: Check out Repo
|
|
37
|
+
uses: actions/checkout@v4
|
|
38
|
+
with:
|
|
39
|
+
fetch-depth: 0
|
|
40
|
+
|
|
41
|
+
- name: Ruff Linting
|
|
42
|
+
uses: astral-sh/ruff-action@v3.5.0
|
|
43
|
+
with:
|
|
44
|
+
version-file: "pyproject.toml"
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Create Master Cache
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [closed]
|
|
6
|
+
branches:
|
|
7
|
+
- main
|
|
8
|
+
- master
|
|
9
|
+
|
|
10
|
+
permissions:
|
|
11
|
+
id-token: write
|
|
12
|
+
contents: read
|
|
13
|
+
|
|
14
|
+
env:
|
|
15
|
+
PYTEST_ADDOPTS: "--color=yes"
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
create_master_cache:
|
|
19
|
+
name: Caching
|
|
20
|
+
timeout-minutes: 15
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
steps:
|
|
23
|
+
|
|
24
|
+
- name: Check out Repo
|
|
25
|
+
uses: actions/checkout@v4
|
|
26
|
+
with:
|
|
27
|
+
fetch-depth: 0
|
|
28
|
+
|
|
29
|
+
- name: Setup Env
|
|
30
|
+
uses: ./.github/actions/setup_env
|
rag_hpo-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
# Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
# poetry.lock
|
|
109
|
+
# poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
# pdm.lock
|
|
116
|
+
# pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
# pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# Redis
|
|
135
|
+
*.rdb
|
|
136
|
+
*.aof
|
|
137
|
+
*.pid
|
|
138
|
+
|
|
139
|
+
# RabbitMQ
|
|
140
|
+
mnesia/
|
|
141
|
+
rabbitmq/
|
|
142
|
+
rabbitmq-data/
|
|
143
|
+
|
|
144
|
+
# ActiveMQ
|
|
145
|
+
activemq-data/
|
|
146
|
+
|
|
147
|
+
# SageMath parsed files
|
|
148
|
+
*.sage.py
|
|
149
|
+
|
|
150
|
+
# Environments
|
|
151
|
+
.env
|
|
152
|
+
.envrc
|
|
153
|
+
.venv
|
|
154
|
+
env/
|
|
155
|
+
venv/
|
|
156
|
+
ENV/
|
|
157
|
+
env.bak/
|
|
158
|
+
venv.bak/
|
|
159
|
+
|
|
160
|
+
# Spyder project settings
|
|
161
|
+
.spyderproject
|
|
162
|
+
.spyproject
|
|
163
|
+
|
|
164
|
+
# Rope project settings
|
|
165
|
+
.ropeproject
|
|
166
|
+
|
|
167
|
+
# mkdocs documentation
|
|
168
|
+
/site
|
|
169
|
+
|
|
170
|
+
# mypy
|
|
171
|
+
.mypy_cache/
|
|
172
|
+
.dmypy.json
|
|
173
|
+
dmypy.json
|
|
174
|
+
|
|
175
|
+
# Pyre type checker
|
|
176
|
+
.pyre/
|
|
177
|
+
|
|
178
|
+
# pytype static type analyzer
|
|
179
|
+
.pytype/
|
|
180
|
+
|
|
181
|
+
# Cython debug symbols
|
|
182
|
+
cython_debug/
|
|
183
|
+
|
|
184
|
+
# PyCharm
|
|
185
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
186
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
188
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
189
|
+
# .idea/
|
|
190
|
+
|
|
191
|
+
# Abstra
|
|
192
|
+
# Abstra is an AI-powered process automation framework.
|
|
193
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
194
|
+
# Learn more at https://abstra.io/docs
|
|
195
|
+
.abstra/
|
|
196
|
+
|
|
197
|
+
# Visual Studio Code
|
|
198
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
199
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
200
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
201
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
202
|
+
# .vscode/
|
|
203
|
+
|
|
204
|
+
# Ruff stuff:
|
|
205
|
+
.ruff_cache/
|
|
206
|
+
|
|
207
|
+
# PyPI configuration file
|
|
208
|
+
.pypirc
|
|
209
|
+
|
|
210
|
+
# Marimo
|
|
211
|
+
marimo/_static/
|
|
212
|
+
marimo/_lsp/
|
|
213
|
+
__marimo__/
|
|
214
|
+
|
|
215
|
+
# Streamlit
|
|
216
|
+
.streamlit/secrets.toml
|
|
217
|
+
|
|
218
|
+
examples/figures
|
rag_hpo-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Jennifer Posey Lab @ Baylor College of Medicine
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
rag_hpo-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: RAG-HPO
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: HPO RAG as implemented by Brandon T. Garcia 2025.
|
|
5
|
+
Author: Rouven Reuter
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 Jennifer Posey Lab @ Baylor College of Medicine
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: homepage, https://www.smart-monkey.blog/
|
|
29
|
+
Project-URL: repository, https://github.com/P2GX/RAG-HPO
|
|
30
|
+
Project-URL: documentation, https://github.com/P2GX/RAG-HPO
|
|
31
|
+
Project-URL: bugtracker, https://github.com/P2GX/RAG-HPO/issues
|
|
32
|
+
Requires-Python: >=3.10
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
License-File: LICENSE
|
|
35
|
+
Requires-Dist: numpy<3,>=2.5.4
|
|
36
|
+
Requires-Dist: pandas<4,>=3.1.0
|
|
37
|
+
Requires-Dist: pronto<3,>=2.7.4
|
|
38
|
+
Requires-Dist: faiss-cpu<2,>=1.15.1
|
|
39
|
+
Requires-Dist: sentence-transformers<7,>=6.2.0
|
|
40
|
+
Requires-Dist: fastembed<1,>=0.9.1
|
|
41
|
+
Requires-Dist: tiktoken<1,>=0.14.0
|
|
42
|
+
Requires-Dist: rapidfuzz<4,>=3.14.6
|
|
43
|
+
Requires-Dist: tabulate<1,>=0.10.0
|
|
44
|
+
Requires-Dist: requests<3,>=2.34.2
|
|
45
|
+
Provides-Extra: dev
|
|
46
|
+
Requires-Dist: ruff<0.18,>=0.17.2; extra == "dev"
|
|
47
|
+
Requires-Dist: pytest==9.1.1; extra == "dev"
|
|
48
|
+
Dynamic: license-file
|
|
49
|
+
|
|
50
|
+
# RAG-HPO
|
|
51
|
+
|
|
52
|
+
**Extract Human Phenotype Ontology (HPO) terms from clinical notes with a large language model and retrieval-augmented generation.**
|
|
53
|
+
|
|
54
|
+
`rag_hpo` is a pip-installable Python package version of
|
|
55
|
+
[RAG-HPO](https://www.medrxiv.org/content/10.1101/2024.12.01.24318253v1), the method by
|
|
56
|
+
Brandon T. Garcia and colleagues (Posey Lab, Baylor College of Medicine). The original
|
|
57
|
+
was a Jupyter notebook. This package turns it into a library you can import and call
|
|
58
|
+
from scripts or pipelines. It adds a pluggable embedding backend, an LLM client for any
|
|
59
|
+
OpenAI-compatible endpoint, and checkpointing so long runs can resume.
|
|
60
|
+
|
|
61
|
+
RAG-HPO is not an LLM itself. It drives an LLM that you provide (local or hosted). The
|
|
62
|
+
model finds phenotype phrases in free text, and a vector index of the HPO grounds each
|
|
63
|
+
phrase to a real HPO ID.
|
|
64
|
+
|
|
65
|
+
> [!WARNING]
|
|
66
|
+
> **Protecting patient information is your responsibility.** Notes are sent to whatever
|
|
67
|
+
> LLM endpoint you configure. Always de-identify data before processing it, and only use
|
|
68
|
+
> hosted APIs that your institution allows for the data in question (HIPAA, GDPR, IRB
|
|
69
|
+
> requirements). Checkpoint files contain note text and must be protected the same way.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## How it works
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
clinical note ──► LLM: extract phrases ──► keep "Abnormal" ──► FAISS: top-15 HPO candidates
|
|
77
|
+
│
|
|
78
|
+
┌────────────── local match? (bag-of-words / exact / fuzzy ≥ 80)
|
|
79
|
+
│ yes │ no
|
|
80
|
+
▼ ▼
|
|
81
|
+
HPO ID ◄────────────────────────────── LLM: pick one candidate
|
|
82
|
+
(local fallback if it fails)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
1. **Extract**: the LLM reads each note and returns phenotype phrases, each tagged
|
|
86
|
+
`Abnormal`, `Normal`, `Family History`, `Other` or `Suspected`. Only `Abnormal`
|
|
87
|
+
phrases go on to the next steps.
|
|
88
|
+
2. **Retrieve**: each phrase is embedded and matched against a FAISS index of every HPO
|
|
89
|
+
label and synonym. The 15 most similar distinct terms become its candidates.
|
|
90
|
+
3. **Match locally**: phrases that match a candidate closely enough get an HPO ID
|
|
91
|
+
without another LLM call.
|
|
92
|
+
4. **Map with the LLM**: for the remaining phrases, the LLM picks the best candidate,
|
|
93
|
+
using the sentence the phrase came from as context.
|
|
94
|
+
5. **Compile**: results are grouped per patient.
|
|
95
|
+
|
|
96
|
+
## You need
|
|
97
|
+
- **The HPO ontology** in OBO format (`hp.obo`), from the
|
|
98
|
+
[HPO release page](https://hpo.jax.org/data/ontology) or
|
|
99
|
+
`https://purl.obolibrary.org/obo/hp.obo`.
|
|
100
|
+
- **An LLM endpoint** that speaks the OpenAI chat-completions API. The default is a local
|
|
101
|
+
[Ollama](https://ollama.com) server. Groq, OpenAI, vLLM and LM Studio also work.
|
|
102
|
+
|
|
103
|
+
## Quickstart
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from pathlib import Path
|
|
107
|
+
|
|
108
|
+
import pronto
|
|
109
|
+
|
|
110
|
+
from rag_hpo.embedding_model import SentenceTransformerModel
|
|
111
|
+
from rag_hpo.llm_client import LLMClient
|
|
112
|
+
from rag_hpo.ontology import Ontology
|
|
113
|
+
from rag_hpo.rag_hpo import RAGHPO
|
|
114
|
+
from rag_hpo.hit import Hit
|
|
115
|
+
|
|
116
|
+
embedding_model = SentenceTransformerModel() # SapBERT-based biomedical model
|
|
117
|
+
llm = LLMClient() # Ollama at localhost:11434, model qwen3.5:4b
|
|
118
|
+
|
|
119
|
+
# One-time: build the HPO vector database (repeat when HPO releases a new version)
|
|
120
|
+
ontology = pronto.Ontology("hp.obo")
|
|
121
|
+
rag = RAGHPO.inti_and_create_embeddings(
|
|
122
|
+
ontology,
|
|
123
|
+
embedding_model,
|
|
124
|
+
llm,
|
|
125
|
+
hp_meta_file=Path("hpo_meta.json"),
|
|
126
|
+
emb_file=Path("hpo_embedded.npz"),
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
# Later runs: load the existing database
|
|
130
|
+
rag = RAGHPO(embedding_model, llm, "hpo_meta.json", "hpo_embedded.npz")
|
|
131
|
+
|
|
132
|
+
results: dict[str, list[Hit]] = rag.extract(
|
|
133
|
+
[
|
|
134
|
+
"The patient has recurrent seizures and global developmental delay. Hearing is normal."
|
|
135
|
+
]
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
print(results["0"].hpo_id)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
To process a CSV of notes, pass a DataFrame with a `clinical_note` column and,
|
|
142
|
+
optionally, a `patient_id` column:
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
import pandas as pd
|
|
146
|
+
|
|
147
|
+
notes = pd.read_csv("notes.csv") # columns: patient_id, clinical_note
|
|
148
|
+
results = rag.extract(notes, checkpoint_dir="checkpoints")
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Using a hosted LLM (Groq)
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
import os
|
|
155
|
+
|
|
156
|
+
llm = LLMClient.groq(api_key=os.environ["GROQ_API_KEY"]) # llama-3.3-70b-versatile
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`LLMClient.groq()` applies Groq's free-tier limits: 30 requests per minute and 500,000
|
|
160
|
+
tokens per day.
|
|
161
|
+
|
|
162
|
+
## Output
|
|
163
|
+
|
|
164
|
+
`extract()` returns a `dict[str, list[Hit]]` where the key represents a patient.
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"1": [
|
|
169
|
+
{
|
|
170
|
+
"phrase": "poor eye contact",
|
|
171
|
+
"category": "Abnormal",
|
|
172
|
+
"hpo_id": "HP:0000817"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"phrase": "marked autistic behaviors",
|
|
176
|
+
"category": "Abnormal",
|
|
177
|
+
"hpo_id": "No Candidate Fit"
|
|
178
|
+
}
|
|
179
|
+
]
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
`hpo_id` is an HPO ID such as `HP:0001250`, or the string `"No Candidate Fit"` if
|
|
184
|
+
nothing could be mapped. Patients with no abnormal findings are left out.
|
|
185
|
+
|
|
186
|
+
## Citation
|
|
187
|
+
|
|
188
|
+
If you use RAG-HPO in your work, please cite the original publication:
|
|
189
|
+
|
|
190
|
+
> Garcia BT, et al. *Improving Automated Deep Phenotyping Through Large Language Models
|
|
191
|
+
> Using Retrieval-Augmented Generation.* Genome Medicine (2025).
|
|
192
|
+
> [doi:10.1186/s13073-025-01521-w](https://doi.org/10.1186/s13073-025-01521-w)
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
|
|
196
|
+
MIT. See [LICENSE](LICENSE). The original RAG-HPO is © 2024 Jennifer Posey Lab, Baylor
|
|
197
|
+
College of Medicine.
|