wingbot 3.65.11 → 3.65.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/AiMatching.js +30 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wingbot",
3
- "version": "3.65.11",
3
+ "version": "3.65.12",
4
4
  "description": "Enterprise Messaging Bot Conversation Engine",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/AiMatching.js CHANGED
@@ -160,6 +160,13 @@ class AiMatching {
160
160
  */
161
161
  this.redundantEntityHandicap = 0.02;
162
162
 
163
+ /**
164
+ * Upper threshold for redundant entity handicaps
165
+ *
166
+ * @type {number}
167
+ */
168
+ this.redundantEntityClamp = 0.1;
169
+
163
170
  /**
164
171
  * When there is additional intent, the final score will be lowered by this value
165
172
  * (0.02 by default)
@@ -808,11 +815,31 @@ class AiMatching {
808
815
  ? 1
809
816
  : 0;
810
817
 
811
- handicap += (requestEntities.length + fromState - matched.length + coveringHandicap)
812
- * this.redundantEntityHandicap;
818
+ const matchingSame = requestEntities.reduce((cnt, e) => {
819
+ const inMatching = matched.some((me) => e.entity === me.entity);
820
+ return cnt + (inMatching ? 1 : 0);
821
+ }, 0);
822
+
823
+ // all of them can be in state
824
+ const distinctEntities = new Set(matched.map((m) => m.entity)).size;
825
+ const matchSameOver = matchingSame - matched.length;
826
+ const nonMatching = requestEntities.length - matchingSame;
827
+
828
+ const redundantCount = nonMatching
829
+ + (matchSameOver > distinctEntities ? matchSameOver * 0.5 : matchSameOver);
830
+
831
+ // eslint-disable-next-line max-len
832
+ // console.log({ distinctEntities, redundantCount, nonMatching, matchSameOver, mat: matched.length, req: requestEntities.length });
833
+
834
+ const redundantHandicap = Math.min(
835
+ this.redundantEntityHandicap * (redundantCount + fromState + coveringHandicap),
836
+ this.redundantEntityClamp
837
+ );
838
+
839
+ handicap += redundantHandicap;
813
840
 
814
841
  // eslint-disable-next-line max-len
815
- // console.log({ requestEntities, matched, handicap, coveringHandicap, otherEntitiesTextLen });
842
+ // console.log({ redundantHandicap, requestEntities, matched, handicap, coveringHandicap, otherEntitiesTextLen });
816
843
 
817
844
  }
818
845
  const score = matched.length === 0 ? 0 : sum / matched.length;