Skip to content
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

Exhaustive retrieval builder page: filtering search / timeframe #1951

Merged
merged 3 commits into from
Oct 9, 2023
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
36 changes: 17 additions & 19 deletions front/components/assistant_builder/AssistantBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import DataSourceSelectionSection from "@app/components/assistant_builder/DataSo
import {
DROID_AVATAR_FILES,
DROID_AVATARS_BASE_PATH,
TimeFrameMode,
FilteringMode,
} from "@app/components/assistant_builder/shared";
import AppLayout from "@app/components/sparkle/AppLayout";
import {
Expand Down Expand Up @@ -84,7 +84,7 @@ type AssistantBuilderState = {
string,
AssistantBuilderDataSourceConfiguration
>;
timeFrameMode: TimeFrameMode;
filteringMode: FilteringMode;
timeFrame: {
value: number;
unit: TimeframeUnit;
Expand All @@ -108,7 +108,7 @@ export type AssistantBuilderInitialState = {
dataSourceConfigurations:
| AssistantBuilderState["dataSourceConfigurations"]
| null;
timeFrameMode: TimeFrameMode | null;
filteringMode: FilteringMode | null;
timeFrame: AssistantBuilderState["timeFrame"] | null;
handle: string;
description: string;
Expand All @@ -132,7 +132,7 @@ type AssistantBuilderProps = {
const DEFAULT_ASSISTANT_STATE: AssistantBuilderState = {
dataSourceMode: "GENERIC",
dataSourceConfigurations: {},
timeFrameMode: "AUTO",
filteringMode: "SEARCH",
timeFrame: {
value: 1,
unit: "month",
Expand Down Expand Up @@ -241,9 +241,9 @@ export default function AssistantBuilder({
initialBuilderState.dataSourceConfigurations ?? {
...DEFAULT_ASSISTANT_STATE.dataSourceConfigurations,
},
timeFrameMode:
initialBuilderState.timeFrameMode ??
DEFAULT_ASSISTANT_STATE.timeFrameMode,
filteringMode:
initialBuilderState.filteringMode ??
DEFAULT_ASSISTANT_STATE.filteringMode,
timeFrame: initialBuilderState.timeFrame ?? {
...DEFAULT_ASSISTANT_STATE.timeFrame,
},
Expand Down Expand Up @@ -316,7 +316,7 @@ export default function AssistantBuilder({
}
}

if (builderState.timeFrameMode === "CUSTOM") {
if (builderState.filteringMode === "TIMEFRAME") {
if (!builderState.timeFrame.value) {
valid = false;
setTimeFrameError("Timeframe must be a number");
Expand All @@ -332,7 +332,7 @@ export default function AssistantBuilder({
builderState.instructions,
builderState.dataSourceMode,
configuredDataSourceCount,
builderState.timeFrameMode,
builderState.filteringMode,
builderState.timeFrame.value,
assistantHandleIsAvailable,
assistantHandleIsValid,
Expand Down Expand Up @@ -377,12 +377,10 @@ export default function AssistantBuilder({
break;
case "SELECTED":
const tfParam = (() => {
switch (builderState.timeFrameMode) {
case "AUTO":
switch (builderState.filteringMode) {
case "SEARCH":
return "auto";
case "ALL_TIME":
return "none";
case "CUSTOM":
case "TIMEFRAME":
if (!builderState.timeFrame.value) {
// unreachable
// we keep this for TS
Expand All @@ -395,13 +393,13 @@ export default function AssistantBuilder({
default:
((x: never) => {
throw new Error(`Unknown time frame mode ${x}`);
})(builderState.timeFrameMode);
})(builderState.filteringMode);
}
})();

actionParam = {
type: "retrieval_configuration",
query: "auto", // TODO ?
query: builderState.filteringMode === "SEARCH" ? "auto" : "none",
timeframe: tfParam,
topK: "auto",
dataSources: Object.values(builderState.dataSourceConfigurations).map(
Expand Down Expand Up @@ -778,12 +776,12 @@ export default function AssistantBuilder({
setShowDataSourcesModal(true);
}}
onDelete={deleteDataSource}
timeFrameMode={builderState.timeFrameMode}
setTimeFrameMode={(timeFrameMode: TimeFrameMode) => {
filteringMode={builderState.filteringMode}
setFilteringMode={(filteringMode: FilteringMode) => {
setEdited(true);
setBuilderState((state) => ({
...state,
timeFrameMode,
filteringMode,
}));
}}
timeFrame={builderState.timeFrame}
Expand Down
44 changes: 26 additions & 18 deletions front/components/assistant_builder/DataSourceSelectionSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { Transition } from "@headlessui/react";
import { AssistantBuilderDataSourceConfiguration } from "@app/components/assistant_builder/AssistantBuilder";
import {
CONNECTOR_PROVIDER_TO_RESOURCE_NAME,
TIME_FRAME_MODE_TO_LABEL,
FILTERING_MODE_TO_LABEL,
FilteringMode,
TIME_FRAME_UNIT_TO_LABEL,
TimeFrameMode,
} from "@app/components/assistant_builder/shared";
import { CONNECTOR_CONFIGURATIONS } from "@app/lib/connector_providers";
import { classNames } from "@app/lib/utils";
Expand All @@ -27,8 +27,8 @@ export default function DataSourceSelectionSection({
canAddDataSource,
onManageDataSource,
onDelete,
timeFrameMode,
setTimeFrameMode,
filteringMode,
setFilteringMode,
timeFrame,
setTimeFrame,
timeFrameError,
Expand All @@ -42,8 +42,8 @@ export default function DataSourceSelectionSection({
canAddDataSource: boolean;
onManageDataSource: (name: string) => void;
onDelete?: (name: string) => void;
timeFrameMode: TimeFrameMode;
setTimeFrameMode: (timeFrameMode: TimeFrameMode) => void;
filteringMode: FilteringMode;
setFilteringMode: (filteringMode: FilteringMode) => void;
timeFrame: { value: number; unit: TimeframeUnit };
setTimeFrame: (timeframe: { value: number; unit: TimeframeUnit }) => void;
timeFrameError: string | null;
Expand Down Expand Up @@ -175,25 +175,25 @@ export default function DataSourceSelectionSection({
<div>
<div className="flex flex-row items-center space-x-2 pt-4">
<div className="text-sm font-semibold text-element-900">
Timeframe:
Filtering:
</div>
<DropdownMenu>
<DropdownMenu.Button>
<Button
type="select"
labelVisible={true}
label={TIME_FRAME_MODE_TO_LABEL[timeFrameMode]}
label={FILTERING_MODE_TO_LABEL[filteringMode]}
variant="secondary"
size="sm"
/>
</DropdownMenu.Button>
<DropdownMenu.Items origin="bottomRight">
{Object.entries(TIME_FRAME_MODE_TO_LABEL).map(([key, value]) => (
{Object.entries(FILTERING_MODE_TO_LABEL).map(([key, value]) => (
<DropdownMenu.Item
key={key}
label={value}
onClick={() => {
setTimeFrameMode(key as TimeFrameMode);
setFilteringMode(key as FilteringMode);
}}
/>
))}
Expand All @@ -202,7 +202,7 @@ export default function DataSourceSelectionSection({
</div>
<div className="mt-4">
<Transition
show={timeFrameMode === "CUSTOM"}
show={filteringMode === "TIMEFRAME"}
enterFrom="opacity-0"
enterTo="opacity-100"
leave="transition-all duration-300"
Expand All @@ -220,7 +220,7 @@ export default function DataSourceSelectionSection({
>
<div className={"flex flex-row items-center gap-4 pb-4"}>
<div className="text-sm font-semibold text-element-900">
Focus on the last
Collect data from the last
</div>
<input
type="text"
Expand Down Expand Up @@ -273,12 +273,20 @@ export default function DataSourceSelectionSection({
</Transition>
</div>
<div className="text-sm font-normal text-element-700">
You can filter the documents retrieved for a&nbsp;specific
time&nbsp;period.
<br />
When <span className="italic">“Auto”</span> is selected,
the&nbsp;assistant will determine the&nbsp;timeframe from
the&nbsp;instructions and the&nbsp;question being&nbsp;asked.
{filteringMode === "TIMEFRAME" ? (
<>
The assistant will look exhaustively at all data in the data
sources, in reverse chronological order, for the specified
timeframe. It will take as much data as it can in its context, and
warn you if it could not process all of it.
</>
) : (
<>
The assistant will search the data sources for data that best
matches the user query, to retrieve information related to the
question.
</>
)}
</div>
</div>
</Transition>
Expand Down
11 changes: 5 additions & 6 deletions front/components/assistant_builder/shared.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { ConnectorProvider } from "@app/lib/connectors_api";
import { TimeframeUnit } from "@app/types/assistant/actions/retrieval";

export const TIME_FRAME_MODES = ["AUTO", "CUSTOM", "ALL_TIME"] as const;
export type TimeFrameMode = (typeof TIME_FRAME_MODES)[number];
export const TIME_FRAME_MODE_TO_LABEL: Record<TimeFrameMode, string> = {
AUTO: "Auto (default)",
CUSTOM: "Custom",
ALL_TIME: "All time",
export const FILTERING_MODES = ["SEARCH", "TIMEFRAME"] as const;
export type FilteringMode = (typeof FILTERING_MODES)[number];
export const FILTERING_MODE_TO_LABEL: Record<FilteringMode, string> = {
SEARCH: "Search",
TIMEFRAME: "Timeframe",
};
export const TIME_FRAME_UNIT_TO_LABEL: Record<TimeframeUnit, string> = {
hour: "hour(s)",
Expand Down
3 changes: 3 additions & 0 deletions front/migrations/20231004_timeframe_none_to_auto.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UPDATE agent_retrieval_configurations
SET "relativeTimeFrame" = 'auto'
WHERE "relativeTimeFrame" = 'none';
10 changes: 5 additions & 5 deletions front/pages/w/[wId]/builder/assistants/[aId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,18 @@ export default function EditAssistant({
const selectedDataSource =
agentConfiguration.action?.type === "retrieval_configuration";

let timeFrameMode: AssistantBuilderInitialState["timeFrameMode"] = null;
let filteringMode: AssistantBuilderInitialState["filteringMode"] = null;
let timeFrame: AssistantBuilderInitialState["timeFrame"] = null;
if (selectedDataSource && agentConfiguration.action?.relativeTimeFrame) {
switch (agentConfiguration.action.relativeTimeFrame) {
case "auto":
timeFrameMode = "AUTO";
filteringMode = "SEARCH";
break;
case "none":
timeFrameMode = "ALL_TIME";
filteringMode = "SEARCH";
break;
default:
timeFrameMode = "CUSTOM";
filteringMode = "TIMEFRAME";
timeFrame = {
value: agentConfiguration.action.relativeTimeFrame.duration,
unit: agentConfiguration.action.relativeTimeFrame.unit,
Expand All @@ -158,7 +158,7 @@ export default function EditAssistant({
dataSources={Object.values(dataSources)}
initialBuilderState={{
dataSourceMode: selectedDataSource ? "SELECTED" : "GENERIC",
timeFrameMode,
filteringMode: filteringMode,
timeFrame,
dataSourceConfigurations, // TODO
handle: agentConfiguration.name,
Expand Down