Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

fix: DIA-666: [FE] Semantic search polish #266

Merged
merged 21 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4004056
fix: DIA-666: [FE] Semantic search polish
yyassi-heartex Nov 14, 2023
e9eef24
fixing where the upper limit is being set
yyassi-heartex Nov 14, 2023
3a23b25
fixing a null check
yyassi-heartex Nov 15, 2023
abd9f53
Merge branch 'master' into fb-dia-666/semantic-search-polish
yyassi-heartex Nov 15, 2023
46f36d5
applying precision update to similiary upper limit
yyassi-heartex Nov 16, 2023
ead1227
its possible to provide 0 as the max which we cant do defaulting to 10
yyassi-heartex Nov 16, 2023
e69cbd6
dont need to send default - if upper limit undefined just dont show t…
yyassi-heartex Nov 16, 2023
6872fe2
we now invoke an event on view reload
yyassi-heartex Nov 20, 2023
bc180a1
Merge branch 'master' into fb-dia-666/semantic-search-polish
yyassi-heartex Nov 20, 2023
6a748bd
setting a safe fallback for when there is no upper limit
yyassi-heartex Nov 20, 2023
f51cf82
Revert "setting a safe fallback for when there is no upper limit"
yyassi-heartex Nov 20, 2023
4f098f4
send it back if its any nan
yyassi-heartex Nov 20, 2023
cf7ad78
we dont need to save threshold if there is no semantic search
yyassi-heartex Nov 21, 2023
61b3f3a
oops inverse logic
yyassi-heartex Nov 21, 2023
c5d1c39
Merge branch 'master' into fb-dia-666/semantic-search-polish
yyassi-heartex Nov 22, 2023
8af3594
Merge branch 'master' into fb-dia-666/semantic-search-polish
yyassi-heartex Nov 23, 2023
094fafc
this'll prevent a bad min from being saved
yyassi-heartex Nov 23, 2023
fb5f46a
preventing total failure on null for threshold min/max but preventing…
yyassi-heartex Nov 24, 2023
86de28b
Merge branch 'master' into fb-dia-666/semantic-search-polish
yyassi-heartex Nov 27, 2023
9bb8caf
small change to help reduce the number of times we save the view
yyassi-heartex Nov 28, 2023
290f2b2
Merge branch 'master' into fb-dia-666/semantic-search-polish
yyassi-heartex Nov 29, 2023
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
7 changes: 0 additions & 7 deletions src/components/Filters/types/String.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { observer } from "mobx-react";
import React from "react";
import { FilterInput } from "../FilterInput";
import { VariantSelect } from "./List";

const BaseInput = observer(({ value, onChange, placeholder }) => {
return (
Expand Down Expand Up @@ -46,10 +45,4 @@ export const StringFilter = [
valueType: "single",
input: (props) => <BaseInput {...props} />,
},
{
key: "similar_to",
label: "similar to",
valueType: "list",
input: (props) => <VariantSelect {...props} />,
},
];
8 changes: 6 additions & 2 deletions src/stores/DataStores/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DynamicModel, registerModel } from "../DynamicModel";
import { CustomJSON } from "../types";
import { FF_DEV_2536, FF_LOPS_E_3, isFF } from "../../utils/feature-flags";

const SIMILARITY_UPPER_LIMIT_PRECISION = 1000;
const fileAttributes = types.model({
"certainty": types.optional(types.maybeNull(types.number), 0),
"distance": types.optional(types.maybeNull(types.number), 0),
Expand Down Expand Up @@ -218,17 +219,19 @@ export const create = (columns) => {
},

postProcessData(data) {
const { total_annotations, total_predictions } = data;
const { total_annotations, total_predictions, similarity_score_upper_limit } = data;

if (total_annotations !== null)
self.totalAnnotations = total_annotations;
if (total_predictions !== null)
self.totalPredictions = total_predictions;
if (!isNaN(similarity_score_upper_limit))
self.similarityUpperLimit = (Math.ceil(similarity_score_upper_limit * SIMILARITY_UPPER_LIMIT_PRECISION) / SIMILARITY_UPPER_LIMIT_PRECISION);
},

}))
.preProcessSnapshot((snapshot) => {
const { total_annotations, total_predictions, ...sn } = snapshot;
const { total_annotations, total_predictions, similarity_score_upper_limit, ...sn } = snapshot;

return {
...sn,
Expand All @@ -239,6 +242,7 @@ export const create = (columns) => {
})),
totalAnnotations: total_annotations,
totalPredictions: total_predictions,
similarityUpperLimit: similarity_score_upper_limit,
};
});
};
36 changes: 28 additions & 8 deletions src/stores/Tabs/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import { TabSelectedItems } from "./tab_selected_items";
import { History } from '../../utils/history';
import { FF_DEV_1470, FF_LOPS_12, isFF } from "../../utils/feature-flags";
import { CustomJSON, StringOrNumberID, ThresholdType } from "../types";
import { clamp } from "../../utils/helpers";

const DEFAULT_THRESHOLD = { min: 0, max: 10 };
const THRESHOLD_MIN = 0;
const THRESHOLD_MIN_DIFF = 0.001;

export const Tab = types
.model("View", {
Expand Down Expand Up @@ -53,7 +55,7 @@ export const Tab = types
editable: true,
deletable: true,
semantic_search: types.optional(types.array(CustomJSON), []),
threshold: types.optional(ThresholdType, DEFAULT_THRESHOLD),
threshold: types.optional(types.maybeNull(ThresholdType), null),
})
.volatile(() => {
const defaultWidth = getComputedStyle(document.body).getPropertyValue("--menu-sidebar-width").replace("px", "").trim();
Expand Down Expand Up @@ -218,7 +220,7 @@ export const Tab = types
columnsDisplayType: self.columnsDisplayType.toPOJO(),
gridWidth: self.gridWidth,
semantic_search: self.semantic_search?.toJSON() ?? [],
threshold: self.threshold?.toJSON() ?? DEFAULT_THRESHOLD,
threshold: self.threshold?.toJSON(),
};

if (self.saved || apiVersion === 1) {
Expand Down Expand Up @@ -305,14 +307,30 @@ export const Tab = types
self.selected = ids;
},

setSemanticSearch(semanticSearchList) {
setSemanticSearch(semanticSearchList, min, max) {
self.semantic_search = semanticSearchList ?? [];
return self.save();
/* if no semantic search we have to clean up threshold */
if (self.semantic_search.length === 0) {
self.threshold = null;
return self.save();
}
/* if we have a min and max we need to make sure we save that too.
this prevents firing 2 view save requests to accomplish the same thing */
return ( !isNaN(min) && !isNaN(max) ) ? self.setSemanticSearchThreshold(min, max) : self.save();
},

setSemanticSearchThreshold(min, max) {
self.threshold = { min, max };
return self.save();
setSemanticSearchThreshold(_min, max) {
const min = clamp(_min ?? THRESHOLD_MIN, THRESHOLD_MIN, max - THRESHOLD_MIN_DIFF);

if (self.semantic_search?.length && !isNaN(min) && !isNaN(max)) {
self.threshold = { min, max };
return self.save();
}
},

clearSemanticSearchThreshold(save = true) {
self.threshold = null;
return save && self.save();
},

selectAll() {
Expand Down Expand Up @@ -381,6 +399,8 @@ export const Tab = types
} else if (isFF(FF_LOPS_12) && self.root.SDK.type === 'labelops') {
yield self.dataStore.reload({ query: self.query, interaction });
}

getRoot(self).SDK.invoke("tabReloaded", self);
}),

deleteFilter(filter) {
Expand Down
4 changes: 2 additions & 2 deletions src/stores/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ export const HtmlOrReact = types.custom({
});

export const ThresholdType = types.model("ThresholdType", {
min: types.number,
max: types.number,
min: types.maybeNull(types.number),
max: types.maybeNull(types.number),
});