brestok commited on
Commit
fc55356
·
1 Parent(s): 1003460

Optimize semantic entity filtering threshold

Browse files

Lowered the score threshold for filtering entities from 0.75 to

trauma/api/message/ai/engine.py CHANGED
@@ -75,6 +75,7 @@ async def search_entities(
75
  async def search_semantic_entities(
76
  search_request: str, entity_data: EntityData, entities_indexes: list[int]
77
  ) -> list[EntityModelExtended]:
 
78
  embedding = await convert_value_to_embeddings(search_request)
79
  query_embedding = np.array([embedding], dtype=np.float32)
80
  distances, indices = settings.SEMANTIC_INDEX.search(query_embedding, k=settings.SEMANTIC_INDEX.ntotal)
@@ -121,6 +122,6 @@ async def set_entities_score(entities: list[EntityModelExtended], search_request
121
  if score > 0.9:
122
  entity.topMatch = True
123
  entity.score = score
124
- if score > 0.75:
125
  final_entities.append(entity)
126
  return sorted(final_entities, key=lambda x: x.score, reverse=True)
 
75
  async def search_semantic_entities(
76
  search_request: str, entity_data: EntityData, entities_indexes: list[int]
77
  ) -> list[EntityModelExtended]:
78
+
79
  embedding = await convert_value_to_embeddings(search_request)
80
  query_embedding = np.array([embedding], dtype=np.float32)
81
  distances, indices = settings.SEMANTIC_INDEX.search(query_embedding, k=settings.SEMANTIC_INDEX.ntotal)
 
122
  if score > 0.9:
123
  entity.topMatch = True
124
  entity.score = score
125
+ if score > 0.72:
126
  final_entities.append(entity)
127
  return sorted(final_entities, key=lambda x: x.score, reverse=True)
trauma/api/message/ai/openai_request.py CHANGED
@@ -37,6 +37,7 @@ async def generate_next_question(instructions: str, message_history_str: str):
37
 
38
  @openai_wrapper(temperature=0.4)
39
  async def generate_search_request(user_messages_str: str, entity_data: dict):
 
40
  messages = [
41
  {
42
  "role": "system",
 
37
 
38
  @openai_wrapper(temperature=0.4)
39
  async def generate_search_request(user_messages_str: str, entity_data: dict):
40
+
41
  messages = [
42
  {
43
  "role": "system",