Getting Started

Installation

using Pkg
Pkg.add(url="https://github.com/JuliaHealth/HealthLLM.jl")

Quick start

using HealthLLM

files = collect_files_with_extensions("data", [".md", ".jl"])
corpus = write_combined_file(files, "combined.txt")

register_models("llama3.2", "nomic-embed-text")
index = build_index_rag(RAGTools.SimpleIndexer(), files)

answer = generate_funsql_query(
    index,
    "nomic-embed-text",
    "llama3.2",
    "Context: {input_query}. Answer concisely.",
    "What is the FunSQL query to query for patients with Hypertension?"
)

Full workflow

1. Collect source files and build a corpus

Use collect_files_with_extensions to recursively gather files by extension, then concatenate them with write_combined_file:

using HealthLLM

files = collect_files_with_extensions("data", [".jl", ".md"])
corpus = write_combined_file(files, "corpus.txt")

2. Register models

Register chat and embedding models for use with PromptingTools. Model names prefixed with hf: are routed to HuggingFace via HuggingFaceOpenAISchema (set a token with set_huggingface_api_key! or HF_TOKEN); everything else defaults to Ollama. See Building Embeddings for the details:

register_models("llama3.2", "nomic-embed-text")
register_models("hf:facebook/opt-350m", "hf:sentence-transformers/all-mpnet-base-v2")

3. Build a RAG index

index = build_index_rag(RAGTools.SimpleIndexer(), files)

4. Validate embeddings

embedding_dim = 384
num_chunks = length(files)
embeddings = rand(embedding_dim, num_chunks)

validate_embeddings_inputs(embeddings, files, embedding_dim)

5. Store embeddings in PostgreSQL

using LibPQ

conn = LibPQ.Connection("postgresql://user:pass@localhost:5432/healthdb")
store_embeddings_pgvector(conn, embeddings, files, embedding_dim)

6. Query the RAG system

answer = generate_funsql_query(
    index,
    "nomic-embed-text",
    "llama3.2",
    "Context: {input_query}. Answer concisely.",
    "What is the recommended treatment for hypertension?"
)

Testing

Default test runs execute the offline unit tests:

using Pkg
Pkg.test()

Integration-style tests that depend on network or large datasets are opt-in:

RUN_HEAVY_TESTS=1 julia --project=. -e 'using Pkg; Pkg.test()'

Next steps

End-to-End Example takes one question from natural language to a result table: retrieval over the grounding docs, a grounded prompt, FunSQL generation, a schema check, and execution on an OMOP database.

Environment notes

  • Keep secrets out of git-tracked files.
  • Configure provider keys in your environment before running model-backed workflows, e.g. HF_TOKEN for HuggingFace models.