Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def get_access_token():
def preprocess(self, **kwargs):
print("BaseModel preprocess")
# input('stop here preprocess')
self.rag = GovernmentRAG(model_name="/home/icyfeather/models/bge-m3", device="cuda", persist_directory="./chroma_db")
self.rag = GovernmentRAG(base_path=Context.get_parameters("base_path"), model_name=Context.get_parameters("model_name", "BAAI/bge-large-zh-v1.5"), device="cuda", persist_directory="./chroma_db")
LOGGER.info("RAG initialized")

def train(self, train_data, valid_data=None, **kwargs):
Expand All @@ -174,16 +174,18 @@ def process_query(self, query: str, ground_truth: str, location: str, rag_type:
response = self.get_model_response(query)
else:
with self.gpu_lock:
base_path = Context.get_parameters("base_path")
model_name = Context.get_parameters("model_name", "BAAI/bge-large-zh-v1.5")

if rag_type == "[global]":
if self.rag is None:
self.rag = GovernmentRAG(model_name="/home/icyfeather/models/bge-m3", device="cuda", persist_directory="./chroma_db")
rag = GovernmentRAG(base_path=base_path, model_name=model_name, device="cuda", persist_directory="./chroma_db")
elif rag_type == "[local]":
self.rag = GovernmentRAG(model_name="/home/icyfeather/models/bge-m3", device="cuda", persist_directory="./chroma_db", provinces=[location])
rag = GovernmentRAG(base_path=base_path, model_name=model_name, device="cuda", persist_directory="./chroma_db", provinces=[location])
else: # [other]
all_locations = set(self.all_locations)
self.rag = GovernmentRAG(model_name="/home/icyfeather/models/bge-m3", device="cuda", persist_directory="./chroma_db", provinces=list(all_locations - set([location])))
all_locations = set(getattr(self, "all_locations", []))
rag = GovernmentRAG(base_path=base_path, model_name=model_name, device="cuda", persist_directory="./chroma_db", provinces=list(all_locations - set([location])))

relevant_docs = self.rag.query(query, k=1)
relevant_docs = rag.query(query, k=1)

# Clear GPU cache after query
if torch.cuda.is_available():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class GovernmentRAG:
def __init__(
self,
base_path: str = "/path/ianvs/dataset/gov_rag",
base_path: Optional[str] = None,
provinces: Optional[Union[str, List[str]]] = None,
model_name: str = "BAAI/bge-large-zh-v1.5",
device: str = "cuda" if torch.cuda.is_available() else "cpu",
Expand All @@ -29,6 +29,8 @@ def __init__(
device: Device to run the model on
persist_directory: Directory to persist the vector database
"""
if base_path is None:
raise ValueError("base_path must be explicitly provided")
self.base_path = base_path
self.provinces = self._validate_provinces(provinces)
self.persist_directory = persist_directory
Expand Down