醫療預約助手的語義搜尋排序與檢索架構設計
Healthcare Appointment Ranking Signals: Retrieval Architecture for Semantic Search
醫療預約助手應先按專科、日期、地點及資格等硬性條件篩除不合資格結果,再以詞彙、語義、新鮮度及來源可信度訊號排序。檢索架構可用精簡詞彙索引處理篩選和精確詞項,並讓向量索引只儲存適合語義匹配的內容;描述資料與時段狀態則分開管理。文章建議保留來源版本、檢索時間及決策紀錄,並以違反約束率、過期結果率、引用覆蓋率和棄答準確度評估安全性。
Short answer: rank appointment content with a staged pipeline that applies hard clinical and time constraints first, then blends lexical, semantic, freshness, and provenance signals; keep the expensive index small enough to rebuild and every answer traceable to a source record.
An appointment assistant is not a general question-answering bot. A result that is semantically close but for the wrong clinic, insurance plan, or date can create a harmful booking. In a payment ledger I would never let a fuzzy match decide which account moves money; scheduling deserves the same exactly-once mindset for intent and evidence. The index-cost constraint changes the design: retrieve a cheap, broad candidate set, then spend compute only on candidates that survive policy checks.
What ranking signals should a healthcare appointment assistant use?
Start with a canonical appointment document rather than embedding raw web pages. Each record should carry specialty, location, accepted coverage, appointment type, clinician or resource, start and end times, language, and an effective timestamp. Keep PHI out of the searchable text unless the use case and retention policy explicitly allow it. A stable appointment_id and source_version give the answer an audit trail.
I use four signal families:
- Hard constraints: specialty, date window, location radius, eligibility, and accessibility requirements. A candidate that fails one is removed, regardless of its vector similarity.
- Lexical relevance: exact matches for terms such as “pediatric cardiology” or a clinic name. BM25-style scoring is useful for rare medical phrases and abbreviations.
- Semantic relevance: an embedding score for paraphrases such as “heart doctor for my child.” Treat this as recall support, not permission to relax a hard constraint.
- Operational trust: freshness, source authority, cancellation state, and a penalty for stale or duplicated records.
The final score can be a weighted blend after filtering, but the weights should be learned from labeled queries and reviewed by clinical and compliance owners. Do not let a popularity signal outrank a location or insurance requirement. Ranking is a policy boundary.
How can retrieval architecture control index cost and still preserve ranking quality?
Use two indexes with different economics. A compact lexical index handles filters and exact terms; a vector index stores embeddings only for content that benefits from semantic matching. At query time, apply structured filters before vector search when the engine supports it. Otherwise, retrieve a modest candidate pool, filter immediately, and rerank the survivors. Re-embedding every appointment description on each availability update is wasteful: keep descriptive content and volatile slot state in separate records, and join them by appointment_id at read time. When an embedding dependency responds with HTTP 429, the ingestion worker should retain the source version and retry with bounded backoff; it must not publish a half-updated document. That rule sounds mundane, but it is what keeps an index rebuild from becoming a silent data-integrity incident. I track embedding queue depth, rebuild duration, and the age of the oldest unapplied source version, because those signals expose cost pressure before users see stale results.
This separation also makes reconciliation possible. A slot update is an event with an idempotency key, not an in-place mystery mutation. The projection that feeds search records the source event ID, version, and observed timestamp; a replay must produce the same projection. When an upstream feed says a slot is gone, mark it unavailable before the assistant can cite it. The answer should include the source version and retrieval timestamp so an auditor can reconstruct what the system knew.
Here is a deliberately small Go shape for that boundary. It leaves the index implementation replaceable and makes filtering explicit.
package retrieval
import "context"
type Query struct {
Text string
Specialty string
Location string
StartAfter int64
EndBefore int64
}
type Candidate struct {
ID string
Lexical float64
Semantic float64
Freshness float64
SourceVersion string
Available bool
}
type Index interface {
Search(ctx context.Context, text string, limit int) ([]Candidate, error)
}
func Retrieve(ctx context.Context, idx Index, q Query) ([]Candidate, error) {
// The production implementation applies structured constraints before this call.
candidates, err := idx.Search(ctx, q.Text, 40)
if err != nil {
return nil, err
}
kept := candidates[:0]
for _, c := range candidates {
if c.Available && c.SourceVersion != "" {
kept = append(kept, c)
}
}
return kept, nil
}
The number 40 is a starting budget, not a universal benchmark. Measure recall at the candidate stage and p95 latency at the answer stage; your mileage may vary with corpus size, embedding dimension, and filter selectivity. A smaller pool lowers reranking cost but can hide a correct appointment behind near-duplicate text.
Keep it auditable.
| Retrieval approach | Best fit | Main trade-off |
|---|---|---|
| Lexical inverted index | Controlled terminology and strict filters | Misses paraphrases and spelling variation |
| Approximate vector index | Large descriptive corpora and semantic queries | Embedding refresh cost and weaker exact-match behavior |
| Hybrid lexical plus vector | Mixed clinical language with hard eligibility rules | More moving parts and calibration work |
That distinction matters.
Where do ranking systems fail in real scheduling data?
The worst failures are plausible. “Annual physical” can match a “new patient physical” while violating a payer rule. A stale cancellation can look more relevant than a current slot because its description is richer. Duplicate records can crowd out a less polished rural clinic. These are data and policy failures, not reasons to increase vector dimensions.
I would test with a table of adversarial queries, each labeled for eligibility, temporal validity, and citation correctness. Include misspellings, multilingual requests, impossible date ranges, and a patient asking for a clinician by name. The metric is not just recall: report constraint-violation rate, stale-result rate, citation coverage, and abstention accuracy. An assistant should say it cannot find a qualifying slot when the filtered set is empty.
Keep an append-only decision log containing query intent, filter values, candidate IDs, signal contributions, model version, and the source versions cited. Access to that log needs the same controls as other healthcare audit data. HIPAA's minimum-necessary principle is a useful design pressure: log enough to explain a decision, but do not copy a patient's free text into every downstream index.
Which implementation choice is unsuitable for this workflow?
A single giant vector index is not suitable when appointment state changes every few seconds or when eligibility filters are strict. Rebuilding embeddings for each slot mutation raises index cost and creates windows where the assistant can cite unavailable inventory. Use a hybrid index with a transactional availability store in those conditions.
Conversely, a lexical-only index is a poor fit when users describe needs in plain language and terminology varies across clinics. Stick with lexical search when the corpus is small, terminology is tightly controlled, and explainability matters more than paraphrase recall; it is easier to operate and cheaper to rebuild.
Do not select a reranker by a single offline score. A model that wins nDCG on generic medical text can lose on appointment constraints. Shadow traffic, replay the labeled query set after every index build, and gate deployment on safety metrics as well as latency and cost. The migration can be boring: dual-write source versions, compare ranked lists, then switch reads behind a feature flag and retain a rollback index.
The durable rule is simple: constraints decide eligibility, ranking signals order eligible evidence, and the audit trail explains both. That division keeps semantic search useful without pretending that similarity is clinical judgment.
References
- https://arxiv.org/abs/2005.11401
- https://www.hhs.gov/hipaa/for-professionals/privacy/laws-regulations/index.html
- https://www.hhs.gov/hipaa/for-professionals/privacy/guidance/minimum-necessary/index.html
- https://www.elastic.co/guide/en/elasticsearch/reference/current/knn-search.html
- https://opensearch.org/docs/latest/search-plugins/knn/index/
- https://www.pinecone.io/learn/vector-search/
來源:DEV Community · dev.to