Skip to content

Commit

Permalink
feature: add scoreThreshold to search UI options tab
Browse files Browse the repository at this point in the history
  • Loading branch information
skeptrunedev committed Jun 12, 2024
1 parent 8049ca3 commit 7b657fc
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 16 deletions.
13 changes: 3 additions & 10 deletions dashboard/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1190,9 +1190,9 @@ camelcase-css@^2.0.1:
integrity sha512-QOSvevhslijgYwRx6Rv7zKdMF8lbRmx+uQGx2+vDc+KI/eBnsy9kit5aj23AgGu3pa4t9AgwbnXWqS+iOY+2aA==

caniuse-lite@^1.0.30001538, caniuse-lite@^1.0.30001565:
version "1.0.30001568"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001568.tgz"
integrity sha512-vSUkH84HontZJ88MiNrOau1EBrCqEQYgkC5gIySiDlpsm8sGVrhU7Kx4V6h0tnqaHzIHZv08HlJIwPbL4XL9+A==
version "1.0.30001632"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001632.tgz"
integrity sha512-udx3o7yHJfUxMLkGohMlVHCvFvWmirKh9JAH/d7WOLPetlH+LTL5cocMZ0t7oZx/mdlOWXti97xLZWc8uURRHg==

ccount@^2.0.0:
version "2.0.1"
Expand Down Expand Up @@ -1677,19 +1677,12 @@ eslint-utils@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-3.0.0.tgz#8aebaface7345bb33559db0a1f13a1d2d48c3672"
integrity sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==
dependencies:
eslint-visitor-keys "^2.0.0"

eslint-visitor-keys@^1.1.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e"
integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==

eslint-visitor-keys@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303"
integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==

eslint-visitor-keys@^3.3.0, eslint-visitor-keys@^3.4.1, eslint-visitor-keys@^3.4.3:
version "3.4.3"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz#0cd72fe8550e3c2eae156a96a4dddcd1c8ac5800"
Expand Down
2 changes: 2 additions & 0 deletions search/src/HomeSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const HomeSearch = () => {
const params = new URLSearchParams(requestParams);
const extendResults = params.get("extendResults") === "true" || false;
const searchType: string = params.get("searchType") ?? "search";
const scoreThreshold = Number(params.get("scoreThreshold")) || 0.0;
const recencyBias = Number(params.get("recencyBias")) || 0.0;
const groupUnique = params.get("groupUnique") === "true" || false;
const slimChunks = params.get("slimChunks") === "true" || false;
Expand Down Expand Up @@ -58,6 +59,7 @@ export const HomeSearch = () => {
<div class="mt-8 w-full max-w-7xl px-4 sm:px-8 md:px-20">
<SearchForm
searchType={searchType}
scoreThreshold={scoreThreshold}
recencyBias={recencyBias}
extendResults={extendResults}
groupUniqueSearch={groupUnique}
Expand Down
4 changes: 4 additions & 0 deletions search/src/components/GroupPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const GroupPage = (props: GroupPageProps) => {

const [query, setQuery] = createSignal<string>("");
const [page, setPage] = createSignal<number>(1);
const [scoreThreshold, setScoreThreshold] = createSignal<number>(0.0);
const [searchType, setSearchType] = createSignal<string>("hybrid");
const [recencyBias, setRecencyBias] = createSignal<number>(0.0);
const [slimChunks, setSlimChunks] = createSignal(false);
Expand Down Expand Up @@ -131,6 +132,7 @@ export const GroupPage = (props: GroupPageProps) => {
createEffect(() => {
setQuery(location.query.q ?? "");
setPage(Number(location.query.page) || 1);
setScoreThreshold(Number(location.query.scoreThreshold) || 0.0);
setSearchType(location.query.searchType ?? "hybrid");
setRecencyBias(Number(location.query.recencyBias) || 0.0);
setSlimChunks(location.query.slimChunks === "true");
Expand Down Expand Up @@ -191,6 +193,7 @@ export const GroupPage = (props: GroupPageProps) => {
body: JSON.stringify({
query: query(),
page: page(),
score_threshold: scoreThreshold(),
group_id: props.groupID,
search_type: searchType(),
slim_chunks: slimChunks(),
Expand Down Expand Up @@ -563,6 +566,7 @@ export const GroupPage = (props: GroupPageProps) => {
<SearchForm
query={query()}
searchType={searchType()}
scoreThreshold={scoreThreshold()}
pageSize={pageSize()}
getTotalPages={getTotalPages()}
recencyBias={recencyBias()}
Expand Down
2 changes: 2 additions & 0 deletions search/src/components/ResultsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { createToast } from "./ShowToasts";
export interface ResultsPageProps {
query: string;
page: number;
scoreThreshold: number;
searchType: string;
recencyBias?: number;
extendResults?: boolean;
Expand Down Expand Up @@ -146,6 +147,7 @@ const ResultsPage = (props: ResultsPageProps) => {
search_type: props.searchType.includes("autocomplete")
? props.searchType.replace("autocomplete-", "")
: props.searchType,
score_threshold: props.scoreThreshold,
recency_bias: props.recencyBias ?? 0.0,
get_collisions: true,
slim_chunks: props.slimChunks ?? false,
Expand Down
38 changes: 33 additions & 5 deletions search/src/components/SearchForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { FiChevronDown, FiChevronUp } from "solid-icons/fi";
const SearchForm = (props: {
query?: string;
searchType: string;
scoreThreshold?: number;
extendResults?: boolean;
groupUniqueSearch?: boolean;
slimChunks?: boolean;
Expand Down Expand Up @@ -59,6 +60,10 @@ const SearchForm = (props: {
route: "autocomplete-fulltext",
},
]);
const [scoreThreshold, setScoreThreshold] = createSignal(
// eslint-disable-next-line solid/reactivity
props.scoreThreshold ?? 0.0,
);
const [textareaInput, setTextareaInput] = createSignal("");
const [typewriterEffect, setTypewriterEffect] = createSignal("");
const [textareaFocused, setTextareaFocused] = createSignal(false);
Expand Down Expand Up @@ -128,6 +133,9 @@ const SearchForm = (props: {
if (searchTypeRoute.includes("autocomplete")) {
extendResultsUrlParam = extendResults() ? "&extendResults=true" : "";
}
const scoreThresholdUrlParam = scoreThreshold()
? `&scoreThreshold=${scoreThreshold()}`
: "";
const groupUniqueUrlParam = groupUniqueSearch() ? "&groupUnique=true" : "";
const slimChunksUrlParam = slimChunks() ? "&slimChunks=true" : "";
const recencyBiasUrlParam = recencyBias()
Expand All @@ -150,6 +158,7 @@ const SearchForm = (props: {

const sharedUrlParams =
searchTypeUrlParam +
scoreThresholdUrlParam +
extendResultsUrlParam +
slimChunksUrlParam +
recencyBiasUrlParam +
Expand Down Expand Up @@ -477,6 +486,25 @@ const SearchForm = (props: {
Reset
</button>
</div>
<div class="flex items-center justify-between space-x-2 p-1">
<label>Score Threshold (0.0 to 1.0):</label>
<input
class="w-16 rounded border border-neutral-400 p-0.5 text-black"
type="number"
min="0.0"
max="1.0"
step="0.00001"
value={props.scoreThreshold}
onInput={(e) => {
setScoreThreshold(
parseFloat(e.currentTarget.value),
);
}}
onBlur={(e) => {
onSubmit(e);
}}
/>
</div>
<Show
when={
searchTypes().find((type) => type.isSelected)
Expand Down Expand Up @@ -523,7 +551,7 @@ const SearchForm = (props: {
<div class="flex items-center justify-between space-x-2 p-1">
<label>Recency Bias (0.0 to 1.0):</label>
<input
class="w-12 rounded border border-neutral-400 p-0.5 text-black"
class="w-16 rounded border border-neutral-400 p-0.5 text-black"
type="number"
min="0.0"
max="1.0"
Expand All @@ -540,7 +568,7 @@ const SearchForm = (props: {
<div class="flex items-center justify-between space-x-2 p-1">
<label>Page Size:</label>
<input
class="w-12 rounded border border-neutral-400 p-0.5 text-black"
class="w-16 rounded border border-neutral-400 p-0.5 text-black"
type="number"
value={props.pageSize}
onInput={(e) => {
Expand Down Expand Up @@ -588,7 +616,7 @@ const SearchForm = (props: {
<div class="items flex justify-between space-x-2 p-1">
<label>Highlight Delimiters (Comma Separated):</label>
<input
class="w-12 rounded border border-neutral-400 p-0.5 text-black"
class="w-16 rounded border border-neutral-400 p-0.5 text-black"
type="text"
value={highlightDelimiters().join(",")}
onInput={(e) => {
Expand All @@ -608,7 +636,7 @@ const SearchForm = (props: {
<div class="items flex justify-between space-x-2 p-1">
<label>Highlight Max Length:</label>
<input
class="w-12 rounded border border-neutral-400 p-0.5 text-black"
class="w-16 rounded border border-neutral-400 p-0.5 text-black"
type="number"
value={props.highlightMaxLength}
onInput={(e) => {
Expand All @@ -624,7 +652,7 @@ const SearchForm = (props: {
<div class="items flex justify-between space-x-2 p-1">
<label>Highlight Max Num:</label>
<input
class="w-12 rounded border border-neutral-400 p-0.5 text-black"
class="w-16 rounded border border-neutral-400 p-0.5 text-black"
type="number"
value={props.highlightMaxNum}
onInput={(e) => {
Expand Down
6 changes: 5 additions & 1 deletion search/src/pages/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const Search = () => {
const [loading, setLoading] = createSignal<boolean>(false);
const [query, setQuery] = createSignal<string>("");
const [page, setPage] = createSignal<number>(1);
const [scoreThreshold, setScoreThreshold] = createSignal<number>(0.0);
const [searchType, setSearchType] = createSignal<string>("hybrid");
const [recencyBias, setRecencyBias] = createSignal<number>(0.0);
const [extendResults, setExtendResults] = createSignal<boolean>(false);
Expand All @@ -34,6 +35,7 @@ export const Search = () => {
setQuery(location.query.q ?? "");
setExtendResults(location.query.extendResults === "true" || false);
setPage(Number(location.query.page) || 1);
setScoreThreshold(Number(location.query.scoreThreshold) || 0.0);
setSearchType(location.query.searchType ?? "hybrid");
setRecencyBias(Number(location.query.recencyBias) || 0.0);
setGroupUnique(location.query.groupUnique === "true" || false);
Expand All @@ -56,10 +58,11 @@ export const Search = () => {
<div class="mx-auto mt-8 w-full max-w-[calc(100%-32px)] px-4 min-[360px]:max-w-[calc(100%-64px)] sm:px-8 md:px-20">
<SearchForm
query={query()}
searchType={searchType()}
scoreThreshold={scoreThreshold()}
extendResults={extendResults()}
groupUniqueSearch={groupUnique()}
slimChunks={slimChunks()}
searchType={searchType()}
recencyBias={recencyBias()}
pageSize={pageSize()}
getTotalPages={getTotalPages()}
Expand All @@ -74,6 +77,7 @@ export const Search = () => {
<ResultsPage
page={page()}
query={query()}
scoreThreshold={scoreThreshold()}
searchType={searchType()}
recencyBias={recencyBias()}
extendResults={extendResults()}
Expand Down

0 comments on commit 7b657fc

Please sign in to comment.