Skip to content

Commit 574079f

Browse files
committed
fix(knowledge): read the document only for unfilled rows in the keyword source exclusion
1 parent d43d20a commit 574079f

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,14 +2175,13 @@ export async function executeKeywordSearch(params: KeywordSearchParams): Promise
21752175
? sql`EXISTS (SELECT 1 FROM ${document} WHERE ${and(sql`${document.id} = ranked_tin_chunks.document_id`, dateFilterCondition(params.filters))})`
21762176
: undefined,
21772177
/**
2178-
* The row's mirrored source decides it once the fill is complete; until then a row the
2179-
* fill has not reached carries no source, so its document is asked instead, as the
2180-
* vector leg does.
2178+
* A filled row's mirrored source decides it; a row the fill has not reached carries no
2179+
* source, so only its document is asked, as the vector leg does.
21812180
*/
21822181
excludedSources.length
21832182
? tinFilled
21842183
? sql`(ranked_tin_chunks.connector_id IS NULL OR NOT (ranked_tin_chunks.connector_id = ANY(${textArrayLiteral([...excludedSources])})))`
2185-
: sql`NOT EXISTS (SELECT 1 FROM ${document} WHERE ${document.id} = ranked_tin_chunks.document_id AND ${document.connectorId} = ANY(${textArrayLiteral([...excludedSources])}))`
2184+
: sql`((ranked_tin_chunks.acl IS NOT NULL AND (ranked_tin_chunks.connector_id IS NULL OR NOT (ranked_tin_chunks.connector_id = ANY(${textArrayLiteral([...excludedSources])})))) OR (ranked_tin_chunks.acl IS NULL AND NOT EXISTS (SELECT 1 FROM ${document} WHERE ${document.id} = ranked_tin_chunks.document_id AND ${document.connectorId} = ANY(${textArrayLiteral([...excludedSources])}))))`
21862185
: undefined
21872186
)
21882187
const documentConditions = (excludedSources: readonly string[]) =>

0 commit comments

Comments
 (0)