Skip to content

[Attach] Allow semantic searching content node documents #11516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions front/lib/actions/conversation/list_files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type ConversationFileType = BaseConversationAttachmentType & {

export type ConversationContentNodeType = BaseConversationAttachmentType & {
contentFragmentId: string;
contentNodeId: string;
nodeDataSourceViewId: string;
};

Expand Down
61 changes: 38 additions & 23 deletions front/lib/api/assistant/jit_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import {
DEFAULT_CONVERSATION_SEARCH_ACTION_NAME,
} from "@app/lib/actions/constants";
import { makeConversationIncludeFileConfiguration } from "@app/lib/actions/conversation/include_file";
import type { ConversationAttachmentType } from "@app/lib/actions/conversation/list_files";
import type {
ConversationAttachmentType,
ConversationContentNodeType,
} from "@app/lib/actions/conversation/list_files";
import {
isConversationContentNodeType,
isConversationFileType,
makeConversationListFilesAction,
} from "@app/lib/actions/conversation/list_files";
import type { RetrievalConfigurationType } from "@app/lib/actions/retrieval";
import type {
DataSourceConfiguration,
RetrievalConfigurationType,
} from "@app/lib/actions/retrieval";
import { getRunnerForActionConfiguration } from "@app/lib/actions/runners";
import type { TablesQueryConfigurationType } from "@app/lib/actions/tables_query";
import type { ActionConfigurationType } from "@app/lib/actions/types/agent";
Expand Down Expand Up @@ -66,10 +72,8 @@ async function getJITActions(
filesUsableAsRetrievalQuery.length > 0
) {
// Get the datasource view for the conversation.
const dataSourceView = await DataSourceViewResource.fetchByConversation(
auth,
conversation
);
const conversationDataSourceView =
await DataSourceViewResource.fetchByConversation(auth, conversation);

if (filesUsableAsTableQuery.length > 0) {
const action: TablesQueryConfigurationType = {
Expand All @@ -83,12 +87,12 @@ async function getJITActions(
tables: filesUsableAsTableQuery.flatMap((f) => {
if (isConversationFileType(f)) {
assert(
dataSourceView,
conversationDataSourceView,
"No conversation datasource view found for table when trying to get JIT actions"
);
return f.generatedTables.map((tableId) => ({
workspaceId: auth.getNonNullableWorkspace().sId,
dataSourceViewId: dataSourceView.sId,
dataSourceViewId: conversationDataSourceView.sId,
tableId,
}));
} else if (isConversationContentNodeType(f)) {
Expand All @@ -104,14 +108,31 @@ async function getJITActions(
actions.push(action);
}

if (
filesUsableAsRetrievalQuery.filter((f) => isConversationFileType(f))
.length > 0
) {
assert(
dataSourceView,
"No conversation datasource view found for retrieval when trying to get JIT actions"
);
if (filesUsableAsRetrievalQuery.length > 0) {
const dataSources: DataSourceConfiguration[] =
filesUsableAsRetrievalQuery
// For each searchable content node, we add its datasourceview with itself as parent filter.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could group by datasourceview here but not sure the gain (which seems ~0 to me) is worth the added LOCs and complexity

.filter((f) => isConversationContentNodeType(f))
.map((f) => ({
workspaceId: auth.getNonNullableWorkspace().sId,
// Cast ok here because of the filter above.
dataSourceViewId: (f as ConversationContentNodeType)
.nodeDataSourceViewId,
filter: {
parents: {
in: [(f as ConversationContentNodeType).contentNodeId],
not: [],
},
tags: null,
},
}));
if (conversationDataSourceView) {
dataSources.push({
workspaceId: auth.getNonNullableWorkspace().sId,
dataSourceViewId: conversationDataSourceView.sId,
filter: { parents: null, tags: null },
});
}
const action: RetrievalConfigurationType = {
description: DEFAULT_CONVERSATION_SEARCH_ACTION_DATA_DESCRIPTION,
type: "retrieval_configuration",
Expand All @@ -121,13 +142,7 @@ async function getJITActions(
topK: "auto",
query: "auto",
relativeTimeFrame: "auto",
dataSources: [
{
workspaceId: conversation.owner.sId,
dataSourceViewId: dataSourceView.sId,
filter: { parents: null, tags: null },
},
],
dataSources,
};
actions.push(action);
}
Expand Down
1 change: 1 addition & 0 deletions front/lib/api/assistant/jit_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export function listFiles(
...baseAttachment,
nodeDataSourceViewId: m.nodeDataSourceViewId,
contentFragmentId: m.contentFragmentId,
contentNodeId: m.nodeId,
});
}

Expand Down