Skip to content

Commit

Permalink
Fixed insert of matches
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-lperezra committed Dec 23, 2024
1 parent 00db0d1 commit 16c6f1b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/ENCODER/BP/AnalyzeTextProcess.cls
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ Method AnalyzeText(text As %String, analysisId As %String, language As %String)
sqlsentence = ""
# iris.cls("Ens.Util.Log").LogInfo("ENCODER.BP.AnalyzeTextProcess", "AnalyzeText", "Starting process")
for phraseToAnalyze in phrases :
iris.cls("Ens.Util.Log").LogInfo("ENCODER.BP.AnalyzeTextProcess", "AnalyzeText", phraseToAnalyze)
if phraseToAnalyze != "":
embedding = model.encode(phraseToAnalyze, normalize_embeddings=True).tolist()
sqlsentence = "INSERT INTO ENCODER_Object.TextMatches (CodeId, Description, Similarity, AnalysisId, RawText) SELECT TOP 50 * FROM (SELECT CodeId, Description, VECTOR_DOT_PRODUCT(VectorDescription, TO_VECTOR('"+str(embedding)+"', DECIMAL)) AS Similarity, '"+analysisId+"', '"+phraseToAnalyze+"' FROM ENCODER_Object.Codes) ORDER BY Similarity DESC"
iris.cls("ENCODER.Utils.Manager").ExecuteInsertQuery(sqlsentence)
stmt = iris.sql.prepare("INSERT INTO ENCODER_Object.TextMatches (CodeId, Description, Similarity, AnalysisId, RawText) SELECT TOP 50 * FROM (SELECT CodeId, Description, VECTOR_DOT_PRODUCT(VectorDescription, TO_VECTOR(?, DECIMAL)) AS Similarity, ?, ? FROM ENCODER_Object.Codes) ORDER BY Similarity DESC")
rs = stmt.execute(str(embedding), analysisId, phraseToAnalyze)
except Exception as err:
iris.cls("Ens.Util.Log").LogInfo("ENCODER.BP.AnalyzeTextProcess", "AnalyzeText", repr(err))
return repr(err)
Expand Down
2 changes: 1 addition & 1 deletion src/ENCODER/Object/TextMatches.cls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class ENCODER.Object.TextMatches Extends (%Persistent, %JSON.Adaptor)
{

Property RawText As %String;
Property RawText As %String(MAXLEN = 256);

Property CodeId As %String;

Expand Down
19 changes: 0 additions & 19 deletions src/ENCODER/Utils/Manager.cls
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
Class ENCODER.Utils.Manager Extends %RegisteredObject
{

/// Description
ClassMethod ExecuteInsertQuery(sqlQuery As %String) As %String
{
Try {
set statement = ##class(%SQL.Statement).%New()
set status = statement.%Prepare(sqlQuery)
if ($$$ISOK(status)) {
set result = statement.%Execute()
return result.%SQLCODE
}
else {
return "0"
}
}
Catch (ex) {
return "0"
}
}

ClassMethod GetEncoding(sentence As %String) As %String [ Language = python ]
{
import sentence_transformers
Expand Down

0 comments on commit 16c6f1b

Please sign in to comment.