Skip to content

Commit ca55d8c

Browse files
committed
fix(knowledge): hand a large bounded set's exhausted Tin windows to the GIN ranking
A narrow reader's page is left short by design once the widest window cannot fill it; a large bounded set's read was exhaustive before, so its widest window that still falls short now hands the page to the GIN ranking, which covers every match.
1 parent fd65d98 commit ca55d8c

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎apps/sim/lib/knowledge/search/queries.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,19 @@ describe('permitted-document planner', () => {
18321832
expect(JSON.stringify(ginStatements()[0])).not.toContain('doc-4999')
18331833
})
18341834

1835+
it('hands the page to the GIN ranking when the widest window cannot fill it', async () => {
1836+
tinPages = [
1837+
{ ranked: 2000, candidates: [] },
1838+
{ ranked: 20_000, candidates: [] },
1839+
]
1840+
queueTableRows(schemaMock.embedding, [{ ...hit('a', 'src-a'), content: 'release notes' }])
1841+
await keyword({ permitted: { kind: 'bounded', documents: large }, accessPlan })
1842+
expect(tinStatements()).toHaveLength(2)
1843+
/** Every match is covered again, by the ranking whose cost follows the term, not the set. */
1844+
expect(ginStatements()).toHaveLength(1)
1845+
expect(JSON.stringify(ginStatements()[0])).not.toContain('doc-4999')
1846+
})
1847+
18351848
it('keeps the bounded read for a set under the size', async () => {
18361849
mockResolveTinKeywordQuery.mockResolvedValue(null)
18371850
await keyword({ permitted: { kind: 'bounded', documents: large.slice(0, -1) }, accessPlan })

‎apps/sim/lib/knowledge/search/queries.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,7 +2154,9 @@ export async function executeKeywordSearch(params: KeywordSearchParams): Promise
21542154
/**
21552155
* A resolved scope decides readability on the ranked row. The windows widen while the page
21562156
* is short, a narrow reader's to a wide one sooner and no further, and what the widest
2157-
* cannot fill is left short rather than handed to a ranking over every match.
2157+
* cannot fill is left short rather than handed to a ranking over every match. A large
2158+
* bounded set is the exception: its bounded read was exhaustive, so the widest window that
2159+
* still falls short hands the page to the GIN ranking, which covers every match.
21582160
*/
21592161
const narrow =
21602162
accessPlan !== undefined &&
@@ -2219,7 +2221,7 @@ export async function executeKeywordSearch(params: KeywordSearchParams): Promise
22192221
if (
22202222
page.candidates.length >= limit ||
22212223
page.ranked < window ||
2222-
(accessPlan !== undefined && window === windows[windows.length - 1])
2224+
(accessPlan !== undefined && !largePermittedSet && window === windows[windows.length - 1])
22232225
) {
22242226
return { candidates: page.candidates, nextOffset: offset + page.candidates.length }
22252227
}

0 commit comments

Comments
 (0)