File size: 494 Bytes
1f22857
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# llama_index_utils.py
from llama_index import SimpleDirectoryReader, GPTVectorStoreIndex

_index = None

def build_index(data_path="data/icd10cm_tabular_2025"):
    global _index
    if _index is None:
        docs = SimpleDirectoryReader(data_path).load_data()
        _index = GPTVectorStoreIndex.from_documents(docs)
    return _index

def query_symptoms(prompt: str, top_k: int = 5):
    idx = build_index()
    qe = idx.as_query_engine(similarity_top_k=top_k)
    return qe.query(prompt)