Commit
•
0bce68f
1
Parent(s):
69180e6
feat: Include codes with feedback, even if not most similar
Browse filesThis allows for weighting codes higher that may not have been included
in the original similarity query.
lib/medical_transcription/coding.ex
CHANGED
@@ -53,8 +53,11 @@ defmodule MedicalTranscription.Coding do
|
|
53 |
MedicalTranscription.Feedback.find_related_feedback(search_vector_for_db, opts)
|
54 |
|
55 |
code_vectors = find_similar(search_vector_for_db, k)
|
|
|
56 |
|
57 |
code_vectors
|
|
|
|
|
58 |
|> weight_code_vectors(past_feedbacks)
|
59 |
|> filter_below_threshold(similarity_threshold)
|
60 |
|> sort_by_similarity()
|
@@ -131,4 +134,22 @@ defmodule MedicalTranscription.Coding do
|
|
131 |
}
|
132 |
)
|
133 |
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
end
|
|
|
53 |
MedicalTranscription.Feedback.find_related_feedback(search_vector_for_db, opts)
|
54 |
|
55 |
code_vectors = find_similar(search_vector_for_db, k)
|
56 |
+
code_vectors_for_feedback = find_for_feedback(search_vector_for_db, past_feedbacks)
|
57 |
|
58 |
code_vectors
|
59 |
+
|> Enum.concat(code_vectors_for_feedback)
|
60 |
+
|> Enum.uniq_by(& &1.id)
|
61 |
|> weight_code_vectors(past_feedbacks)
|
62 |
|> filter_below_threshold(similarity_threshold)
|
63 |
|> sort_by_similarity()
|
|
|
134 |
}
|
135 |
)
|
136 |
end
|
137 |
+
|
138 |
+
# Retrieves code vectors referenced in past feedback for a given search text. This allows including additional codes
|
139 |
+
# for the weighting process outside of the closest 5 returned by `find_similar/2`.
|
140 |
+
defp find_for_feedback(search_vector, past_feedbacks) do
|
141 |
+
code_vector_ids_for_past_feedback = Enum.map(past_feedbacks, & &1.code_vector_id)
|
142 |
+
|
143 |
+
Repo.all(
|
144 |
+
from v in CodeVector,
|
145 |
+
order_by: cosine_distance(v.description_vector, ^search_vector),
|
146 |
+
where: v.id in ^code_vector_ids_for_past_feedback,
|
147 |
+
select: %CodeVectorMatch{
|
148 |
+
id: v.id,
|
149 |
+
code: v.code,
|
150 |
+
description: v.description,
|
151 |
+
cosine_similarity: 1 - cosine_distance(v.description_vector, ^search_vector)
|
152 |
+
}
|
153 |
+
)
|
154 |
+
end
|
155 |
end
|