phamluan commited on
Commit
0a6e343
·
verified ·
1 Parent(s): bc74524

Deploy RAG Tourism API

Browse files
Files changed (1) hide show
  1. app/main.py +8 -0
app/main.py CHANGED
@@ -813,6 +813,11 @@ async def search_locations(query: TourismQuery, background_tasks: BackgroundTask
813
  # Boost PhoBERT confidence for primary usage
814
  # Convert numpy.float32 to Python float to fix Pydantic serialization
815
  similarity_score = float(loc.get('similarity_score', 0.5))
 
 
 
 
 
816
  boosted_confidence = float(min(0.95, similarity_score + 0.1))
817
  results.append(LocationResponse(
818
  name=loc['name'],
@@ -836,6 +841,9 @@ async def search_locations(query: TourismQuery, background_tasks: BackgroundTask
836
  existing_names = {r.name.lower() for r in results}
837
  for loc in vector_results: # ChromaDB already limits results
838
  if loc['name'] and loc['name'].lower() not in existing_names:
 
 
 
839
  # Convert numpy types to Python types for Pydantic serialization
840
  results.append(LocationResponse(
841
  name=loc['name'],
 
813
  # Boost PhoBERT confidence for primary usage
814
  # Convert numpy.float32 to Python float to fix Pydantic serialization
815
  similarity_score = float(loc.get('similarity_score', 0.5))
816
+ # Ngưỡng liên quan: loại kết quả vector quá xa nghĩa
817
+ # (tránh trưng card 35% lạc tỉnh). Chỉnh qua env
818
+ # MIN_VECTOR_SIMILARITY (mặc định 0.35 ~ confidence 45%).
819
+ if similarity_score < float(_os.getenv("MIN_VECTOR_SIMILARITY", "0.35")):
820
+ continue
821
  boosted_confidence = float(min(0.95, similarity_score + 0.1))
822
  results.append(LocationResponse(
823
  name=loc['name'],
 
841
  existing_names = {r.name.lower() for r in results}
842
  for loc in vector_results: # ChromaDB already limits results
843
  if loc['name'] and loc['name'].lower() not in existing_names:
844
+ # Ngưỡng liên quan (đồng bộ với nhánh PhoBERT)
845
+ if float(loc.get('similarity_score', 0.5)) < float(_os.getenv("MIN_VECTOR_SIMILARITY", "0.35")):
846
+ continue
847
  # Convert numpy types to Python types for Pydantic serialization
848
  results.append(LocationResponse(
849
  name=loc['name'],