Skip to content

Commit 809c37c

Browse files
[Attach] Allow semantic searching content node documents (#11516)
* [Attach] Allow semantic searching content node documents Fixes #2404 Description --- As per title and issue. Extracted from #11489 (cf comments) Risks --- standard Deploy --- front * review * com * types
1 parent f03c150 commit 809c37c

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

front/lib/actions/conversation/list_files.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export type ConversationFileType = BaseConversationAttachmentType & {
3434

3535
export type ConversationContentNodeType = BaseConversationAttachmentType & {
3636
contentFragmentId: string;
37+
contentNodeId: string;
3738
nodeDataSourceViewId: string;
3839
};
3940

front/lib/api/assistant/jit_actions.ts

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ import {
77
DEFAULT_CONVERSATION_SEARCH_ACTION_NAME,
88
} from "@app/lib/actions/constants";
99
import { makeConversationIncludeFileConfiguration } from "@app/lib/actions/conversation/include_file";
10-
import type { ConversationAttachmentType } from "@app/lib/actions/conversation/list_files";
10+
import type {
11+
ConversationAttachmentType,
12+
ConversationContentNodeType,
13+
} from "@app/lib/actions/conversation/list_files";
1114
import {
1215
isConversationContentNodeType,
1316
isConversationFileType,
1417
makeConversationListFilesAction,
1518
} from "@app/lib/actions/conversation/list_files";
16-
import type { RetrievalConfigurationType } from "@app/lib/actions/retrieval";
19+
import type {
20+
DataSourceConfiguration,
21+
RetrievalConfigurationType,
22+
} from "@app/lib/actions/retrieval";
1723
import { getRunnerForActionConfiguration } from "@app/lib/actions/runners";
1824
import type { TablesQueryConfigurationType } from "@app/lib/actions/tables_query";
1925
import type { ActionConfigurationType } from "@app/lib/actions/types/agent";
@@ -66,10 +72,8 @@ async function getJITActions(
6672
filesUsableAsRetrievalQuery.length > 0
6773
) {
6874
// Get the datasource view for the conversation.
69-
const dataSourceView = await DataSourceViewResource.fetchByConversation(
70-
auth,
71-
conversation
72-
);
75+
const conversationDataSourceView =
76+
await DataSourceViewResource.fetchByConversation(auth, conversation);
7377

7478
if (filesUsableAsTableQuery.length > 0) {
7579
const action: TablesQueryConfigurationType = {
@@ -83,12 +87,12 @@ async function getJITActions(
8387
tables: filesUsableAsTableQuery.flatMap((f) => {
8488
if (isConversationFileType(f)) {
8589
assert(
86-
dataSourceView,
90+
conversationDataSourceView,
8791
"No conversation datasource view found for table when trying to get JIT actions"
8892
);
8993
return f.generatedTables.map((tableId) => ({
9094
workspaceId: auth.getNonNullableWorkspace().sId,
91-
dataSourceViewId: dataSourceView.sId,
95+
dataSourceViewId: conversationDataSourceView.sId,
9296
tableId,
9397
}));
9498
} else if (isConversationContentNodeType(f)) {
@@ -104,14 +108,31 @@ async function getJITActions(
104108
actions.push(action);
105109
}
106110

107-
if (
108-
filesUsableAsRetrievalQuery.filter((f) => isConversationFileType(f))
109-
.length > 0
110-
) {
111-
assert(
112-
dataSourceView,
113-
"No conversation datasource view found for retrieval when trying to get JIT actions"
114-
);
111+
if (filesUsableAsRetrievalQuery.length > 0) {
112+
const dataSources: DataSourceConfiguration[] =
113+
filesUsableAsRetrievalQuery
114+
// For each searchable content node, we add its datasourceview with itself as parent filter.
115+
.filter((f) => isConversationContentNodeType(f))
116+
.map((f) => ({
117+
workspaceId: auth.getNonNullableWorkspace().sId,
118+
// Cast ok here because of the filter above.
119+
dataSourceViewId: (f as ConversationContentNodeType)
120+
.nodeDataSourceViewId,
121+
filter: {
122+
parents: {
123+
in: [(f as ConversationContentNodeType).contentNodeId],
124+
not: [],
125+
},
126+
tags: null,
127+
},
128+
}));
129+
if (conversationDataSourceView) {
130+
dataSources.push({
131+
workspaceId: auth.getNonNullableWorkspace().sId,
132+
dataSourceViewId: conversationDataSourceView.sId,
133+
filter: { parents: null, tags: null },
134+
});
135+
}
115136
const action: RetrievalConfigurationType = {
116137
description: DEFAULT_CONVERSATION_SEARCH_ACTION_DATA_DESCRIPTION,
117138
type: "retrieval_configuration",
@@ -121,13 +142,7 @@ async function getJITActions(
121142
topK: "auto",
122143
query: "auto",
123144
relativeTimeFrame: "auto",
124-
dataSources: [
125-
{
126-
workspaceId: conversation.owner.sId,
127-
dataSourceViewId: dataSourceView.sId,
128-
filter: { parents: null, tags: null },
129-
},
130-
],
145+
dataSources,
131146
};
132147
actions.push(action);
133148
}

front/lib/api/assistant/jit_utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export function listFiles(
115115
...baseAttachment,
116116
nodeDataSourceViewId: m.nodeDataSourceViewId,
117117
contentFragmentId: m.contentFragmentId,
118+
contentNodeId: m.nodeId,
118119
});
119120
}
120121

0 commit comments

Comments
 (0)