From 0650b1cec1b5fcb6a96482edf06ecae5fe535a40 Mon Sep 17 00:00:00 2001 From: Himanshu Garode Date: Mon, 24 Aug 2026 01:23:13 +0530 Subject: [PATCH] docs(biome): document curated knowledge workflow --- packages/hphbiome-hiperhealth/README.md | 25 ++++++ packages/hphbiome/README.md | 115 +++++++++++++++++++++++- 2 files changed, 139 insertions(+), 1 deletion(-) diff --git a/packages/hphbiome-hiperhealth/README.md b/packages/hphbiome-hiperhealth/README.md index 3a4442b..03ee581 100644 --- a/packages/hphbiome-hiperhealth/README.md +++ b/packages/hphbiome-hiperhealth/README.md @@ -5,3 +5,28 @@ HiperHealth skill adapter for the reusable `hphbiome` library. This package provides the `HPHBiomeSkill` class and a `hiperhealth.skills` entry point. It intentionally keeps HPH Biome logic in the standalone `hphbiome` package and only adapts it to HiperHealth's skill API. + +## Explicit curated-knowledge queries + +The complete standalone workflow is documented in the +[`hphbiome` package README](../hphbiome/README.md#curated-knowledge-backend-workflow). +Create or load the `KnowledgeCollection` with that package, then pass it to +`HPHBiomeSkill(collection=collection)`. + +Retrieval runs only when the HiperHealth stage call explicitly supplies both +`hphbiome_query` and `hphbiome_allowed_review_statuses`. The optional +`hphbiome_limit` is applied after deterministic filtering and ranking. The +adapter exposes result dictionaries, structured context, and text context at: + +```text +ctx.results[stage]['hphbiome']['curated_knowledge'] +``` + +The adapter never derives a query from patient context and does not add +retrieved content to prompt fragments automatically. It delegates model +validation, persistence, retrieval, filtering, and context generation to the +standalone package, preserving record and scientific-reference provenance. + +Neither package generates diagnoses or treatment recommendations, and neither +replaces professional judgment. Callers remain responsible for the safety, +quality, review status, licensing, and privacy of supplied content. diff --git a/packages/hphbiome/README.md b/packages/hphbiome/README.md index 7decd34..cd3910d 100644 --- a/packages/hphbiome/README.md +++ b/packages/hphbiome/README.md @@ -6,7 +6,7 @@ This package is intentionally independent from HiperHealth so it can be used by other Python projects. The HiperHealth skill adapter lives in the sibling `hphbiome-hiperhealth` package. -## Usage +## Patient-context utilities The example below uses fictional, non-sensitive data: @@ -39,3 +39,116 @@ print(prompt_fragment) These utilities organize supplied context only. They do not validate medical claims, provide a diagnosis, recommend treatment, or replace professional medical judgment. + +## Curated-knowledge backend workflow + +The following standalone example mirrors the repository's end-to-end backend +integration test. It uses only public `hphbiome` APIs, Python's standard +library, and obviously fictional data. HiperHealth is not required. + +```python +from pathlib import Path +from pprint import pprint +from tempfile import TemporaryDirectory + +from hphbiome import ( + CuratedKnowledgeRecord, + KnowledgeCollection, + ScientificReference, + build_structured_knowledge_context, + build_text_knowledge_context, + load_knowledge_collection_json, + retrieve_knowledge, + save_knowledge_collection_json, +) + +alpha_reference = ScientificReference( + title='Fictional amber source', + authors=['Example Author Alpha'], + source='Imaginary Research Review', + identifier='fictional-id:alpha', + canonical_url='https://example.test/sources/alpha', +) +beta_reference = ScientificReference( + title='Fictional comet source', + authors=['Example Author Beta', 'Example Author Gamma'], + source='Imaginary Research Review', + identifier='fictional-id:beta', + canonical_url='https://example.test/sources/beta', +) + +visible_record = CuratedKnowledgeRecord( + id='fictional-record-visible', + title='Fictional amber comet observation', + synthesis='A fictional synthesis preserving its supplied wording.', + references=[ + beta_reference.canonical_url, + alpha_reference.identifier, + ], + review_status='fictional-visible', +) +hidden_record = CuratedKnowledgeRecord( + id='fictional-record-hidden', + title='Fictional amber comet hidden observation', + synthesis='A fictional result excluded by caller-defined status.', + references=[beta_reference.identifier], + review_status='fictional-hidden', +) + +collection = KnowledgeCollection( + records=[visible_record, hidden_record], + references=[alpha_reference, beta_reference], +) + +with TemporaryDirectory() as directory: + collection_path = Path(directory) / 'fictional-knowledge.json' + save_knowledge_collection_json(collection, collection_path) + loaded_collection = load_knowledge_collection_json(collection_path) + + assert loaded_collection == collection + + results = retrieve_knowledge( + loaded_collection, + 'amber comet', + allowed_review_statuses=['fictional-visible'], + limit=2, + ) + structured_context = build_structured_knowledge_context(results) + text_context = build_text_knowledge_context(results) + + for result in results: + print(result.record.id, result.score) + for reference in result.references: + print(' ', reference.identifier, reference.canonical_url) + + pprint(structured_context) + print(text_context) +``` + +The output contains only `fictional-record-visible`, with a relevance score of +`1.0`. Its two references remain in the order declared on the record: beta, then +alpha. Both the structured and text context include the record ID, review +status, score, reference identifiers, and canonical URLs. + +`save_knowledge_collection_json` writes deterministic UTF-8 JSON, and +`load_knowledge_collection_json` reconstructs and validates the collection. +Record reference strings resolve against either a scientific-reference +identifier or canonical URL. Review statuses are caller-defined and matched +exactly; the library does not define or advance a review workflow. + +`retrieve_knowledge` searches only curated record titles and syntheses. Context +generation preserves the supplied synthesis and provenance without summarizing, +extending, or reinterpreting it. + +## Package boundary + +The models, validation, persistence, retrieval, and context functions above +belong to the standalone `hphbiome` package. The optional `hphbiome-hiperhealth` +package accepts the same `KnowledgeCollection` and delegates explicit queries to +these APIs; it does not reimplement the backend. + +Curated knowledge is informational input. HPH Biome does not diagnose, recommend +treatment, validate scientific or medical claims, or replace professional +judgment. Applications must protect patient information and must not treat +supplied content as automatically reviewed, complete, or clinically +authoritative.