ghitaben commited on
Commit
2cec50c
·
1 Parent(s): 85020ae

Add antibiotic guidelines Excel files and PDF documentation

Browse files
docs/{Antibiotic_guidelines → antibiotic_guidelines}/EML export-ACCESS group.xlsx RENAMED
File without changes
docs/{Antibiotic_guidelines → antibiotic_guidelines}/EML export-RESERVE group.xlsx RENAMED
File without changes
docs/{Antibiotic_guidelines → antibiotic_guidelines}/EML export-WATCH group.xlsx RENAMED
File without changes
docs/{Antibiotic_guidelines → antibiotic_guidelines}/ciae403.pdf RENAMED
File without changes
src/config.py CHANGED
@@ -7,7 +7,10 @@ from typing import Literal, Optional
7
  from dotenv import load_dotenv
8
  from pydantic import BaseModel, Field
9
 
10
- load_dotenv()
 
 
 
11
 
12
 
13
  class Settings(BaseModel):
 
7
  from dotenv import load_dotenv
8
  from pydantic import BaseModel, Field
9
 
10
+ # Explicitly load .env from the project root so it works regardless of CWD
11
+ # (e.g. when imported from a Kaggle notebook whose CWD is /kaggle/working/)
12
+ _PROJECT_ROOT = Path(__file__).resolve().parents[1]
13
+ load_dotenv(_PROJECT_ROOT / ".env")
14
 
15
 
16
  class Settings(BaseModel):
src/db/vector_store.py CHANGED
@@ -9,17 +9,18 @@ import hashlib
9
  from langchain_text_splitters import RecursiveCharacterTextSplitter
10
  from pypdf import PdfReader
11
 
 
 
12
  # Project paths
13
  PROJECT_ROOT = Path(__file__).parent.parent.parent
14
- DATA_DIR = PROJECT_ROOT / "data"
15
  DOCS_DIR = PROJECT_ROOT / "docs"
16
- CHROMA_DIR = DATA_DIR / "chroma"
17
 
18
 
19
  def get_chroma_client() -> chromadb.PersistentClient:
20
  """Get ChromaDB persistent client."""
21
- CHROMA_DIR.mkdir(parents=True, exist_ok=True)
22
- return chromadb.PersistentClient(path=str(CHROMA_DIR))
 
23
 
24
 
25
  def get_embedding_function():
 
9
  from langchain_text_splitters import RecursiveCharacterTextSplitter
10
  from pypdf import PdfReader
11
 
12
+ from ..config import get_settings
13
+
14
  # Project paths
15
  PROJECT_ROOT = Path(__file__).parent.parent.parent
 
16
  DOCS_DIR = PROJECT_ROOT / "docs"
 
17
 
18
 
19
  def get_chroma_client() -> chromadb.PersistentClient:
20
  """Get ChromaDB persistent client."""
21
+ chroma_dir = get_settings().chroma_db_dir
22
+ chroma_dir.mkdir(parents=True, exist_ok=True)
23
+ return chromadb.PersistentClient(path=str(chroma_dir))
24
 
25
 
26
  def get_embedding_function():
src/rag.py CHANGED
@@ -105,18 +105,31 @@ def search_drug_safety(
105
  n_results: int = 5,
106
  drug_name: Optional[str] = None,
107
  ) -> List[Dict[str, Any]]:
108
- """Search the drug safety collection (interactions, warnings, contraindications)."""
109
- collection = get_collection("drug_safety")
110
- if collection is None:
111
  return []
112
- enhanced_query = f"{drug_name} {query}" if drug_name else query
113
  try:
114
- results = collection.query(
115
- query_texts=[enhanced_query],
116
- n_results=n_results,
117
- include=["documents", "metadatas", "distances"],
 
 
 
 
118
  )
119
- return _format_results(results)
 
 
 
 
 
 
 
 
 
 
 
120
  except Exception as e:
121
  logger.error(f"Error querying drug safety: {e}")
122
  return []
 
105
  n_results: int = 5,
106
  drug_name: Optional[str] = None,
107
  ) -> List[Dict[str, Any]]:
108
+ """Search drug interactions from SQLite (drug_interactions table)."""
109
+ if not drug_name:
 
110
  return []
 
111
  try:
112
+ from .db.database import execute_query
113
+
114
+ rows = execute_query(
115
+ """SELECT drug_1, drug_2, interaction_description, severity
116
+ FROM drug_interactions
117
+ WHERE LOWER(drug_1) LIKE ? OR LOWER(drug_2) LIKE ?
118
+ LIMIT ?""",
119
+ (f"%{drug_name.lower()}%", f"%{drug_name.lower()}%", n_results),
120
  )
121
+ return [
122
+ {
123
+ "content": (
124
+ f"{r['drug_1']} + {r['drug_2']}: {r['interaction_description']}"
125
+ ),
126
+ "metadata": {"severity": r.get("severity", "unknown")},
127
+ "distance": None,
128
+ "source": "drug_interactions (SQLite)",
129
+ "relevance_score": 1.0,
130
+ }
131
+ for r in rows
132
+ ]
133
  except Exception as e:
134
  logger.error(f"Error querying drug safety: {e}")
135
  return []