Repository navigation
Commit 6904e58
authored
improvement(knowledge): match keyword chunks before authorizing them (#7973)
The org-scoped keyword leg built its candidate set in the order
visibility -> match -> rank. The visibility predicate carries a
correlated subquery per connector plus a search-integration check, so
evaluating it across the base before the query terms were consulted
priced every search by how many documents the base holds rather than by
how many the query matched.
Reorder to match -> authorize -> rank. The match stage carries chunk
identifiers only, the identical visibility predicate then runs over just
the documents that matched, and ts_rank_cd is computed for the matches
that survive it. Same predicate, same ordering, same page contract.
Two details keep the reorder from paying the saving back. Restricting
the predicate with `document.id = ANY (...)` rather than a subquery
keeps the narrowed lookup on a bitmap scan, which prefetches, where a
plain `IN (SELECT ...)` plans as an index walk that does not. And
ranking in the match stage rather than after authorization would detoast
one text-search vector per match, which on a mid-frequency term costs
more than the pass it replaces.1 parent 5d520ba commit 6904e58
3 files changed
Lines changed: 55 additions & 23 deletions
File tree
- apps/sim/lib/knowledge
- __integration__
- search
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
477 | 477 | | |
478 | 478 | | |
479 | 479 | | |
480 | | - | |
| 480 | + | |
481 | 481 | | |
482 | 482 | | |
483 | 483 | | |
| |||
550 | 550 | | |
551 | 551 | | |
552 | 552 | | |
553 | | - | |
| 553 | + | |
554 | 554 | | |
555 | 555 | | |
556 | 556 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
884 | 884 | | |
885 | 885 | | |
886 | 886 | | |
887 | | - | |
| 887 | + | |
888 | 888 | | |
889 | 889 | | |
890 | 890 | | |
| |||
1102 | 1102 | | |
1103 | 1103 | | |
1104 | 1104 | | |
1105 | | - | |
1106 | | - | |
| 1105 | + | |
| 1106 | + | |
1107 | 1107 | | |
1108 | 1108 | | |
1109 | 1109 | | |
| |||
1240 | 1240 | | |
1241 | 1241 | | |
1242 | 1242 | | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
1243 | 1259 | | |
1244 | 1260 | | |
1245 | 1261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1100 | 1100 | | |
1101 | 1101 | | |
1102 | 1102 | | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
1103 | 1116 | | |
1104 | 1117 | | |
1105 | 1118 | | |
| |||
1133 | 1146 | | |
1134 | 1147 | | |
1135 | 1148 | | |
1136 | | - | |
1137 | | - | |
1138 | | - | |
1139 | | - | |
1140 | | - | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
1144 | | - | |
1145 | | - | |
1146 | | - | |
1147 | | - | |
| 1149 | + | |
1148 | 1150 | | |
1149 | | - | |
1150 | | - | |
| 1151 | + | |
1151 | 1152 | | |
1152 | 1153 | | |
1153 | 1154 | | |
1154 | 1155 | | |
1155 | 1156 | | |
1156 | | - | |
1157 | | - | |
1158 | 1157 | | |
1159 | 1158 | | |
1160 | 1159 | | |
1161 | 1160 | | |
1162 | 1161 | | |
1163 | 1162 | | |
1164 | 1163 | | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
1165 | 1176 | | |
1166 | | - | |
1167 | | - | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
1168 | 1184 | | |
1169 | 1185 | | |
1170 | 1186 | | |
| |||
0 commit comments