Skip to content
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
42 changes: 42 additions & 0 deletions frontends/chat/src/components/Layouts/MainLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ const MainLayout = (props: LayoutProps) => {
>(null);

const [useImages, setUseImages] = createSignal<boolean | null>(null);
const [useMmr, setUseMmr] = createSignal<boolean | null>(false);
const [mmrLambda, setMmrLambda] = createSignal<number | null>(0.5);
const [useGroupSearch, setUseGroupSearch] = createSignal<boolean | null>(
null,
);
Expand Down Expand Up @@ -232,6 +234,12 @@ const MainLayout = (props: LayoutProps) => {
use_images: useImages(),
},
},
sort_options: {
mmr: {
use_mmr: useMmr(),
mmr_lambda: mmrLambda(),
},
},
no_result_message: noResultMessage(),
use_group_search: useGroupSearch(),
search_type: searchType(),
Expand Down Expand Up @@ -344,6 +352,13 @@ const MainLayout = (props: LayoutProps) => {
filters: getFiltersFromStorage(dataset.dataset.id),
concat_user_messages_query: concatUserMessagesQuery(),
page_size: pageSize(),
sort_options: {
mmr: {
use_mmr: useMmr(),
mmr_lambda: mmrLambda(),
},
},
use_group_search: useGroupSearch(),
search_query:
searchQuery() != "" ? searchQuery() : undefined,
score_threshold: minScore(),
Expand Down Expand Up @@ -514,6 +529,33 @@ const MainLayout = (props: LayoutProps) => {
}}
/>
</div>
<div class="flex w-full items-center gap-x-2">
<div class="flex items-center gap-x-2">
<label for="concat_user_messages">Use MMR</label>
</div>
<input
type="checkbox"
id="concat_user_messages"
class="h-4 w-4 rounded-md border border-neutral-300 bg-neutral-100 p-1 dark:border-neutral-900 dark:bg-neutral-800"
checked={useMmr() ?? false}
onChange={(e) => {
setUseMmr(e.target.checked);
}}
/>
</div>
<div class="flex w-full items-center gap-x-2">
<label for="search_query">MMR Lambda:</label>
<input
type="text"
id="search_query"
class="w-12 rounded-md border border-neutral-300 bg-neutral-100 p-1 dark:border-neutral-900 dark:bg-neutral-700"
step={"any"}
value={mmrLambda() ?? ""}
onChange={(e) => {
setMmrLambda(parseFloat(e.target.value));
}}
/>
</div>
<div class="flex w-full items-center gap-x-2">
<label for="page_size">Page Size:</label>
<input
Expand Down
2 changes: 1 addition & 1 deletion server/src/data/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6667,7 +6667,7 @@ pub struct SortOptions {
}

#[derive(Serialize, Deserialize, Debug, Clone, ToSchema, Default)]
/// MMR Options lets you specify different methods to rerank the chunks in the result set. If not specified, this defaults to the score of the chunks.
/// MMR Options lets you specify different methods to rerank the chunks in the result set using Maximal Marginal Relevance. If not specified, this defaults to the score of the chunks.
pub struct MmrOptions {
/// Set use_mmr to true to use the Maximal Marginal Relevance algorithm to rerank the results.
pub use_mmr: bool,
Expand Down
4 changes: 2 additions & 2 deletions server/src/handlers/message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ pub struct CreateMessageReqPayload {
pub page_size: Option<u64>,
/// Sort Options lets you specify different methods to rerank the chunks in the result set. If not specified, this defaults to the score of the chunks.
pub sort_options: Option<SortOptions>,
/// Filters is a JSON object which can be used to filter chunks. This is useful for when you want to filter chunks by arbitrary metadata. Unlike with tag filtering, there is a performance hit for filtering on metadata.
pub filters: Option<ChunkFilter>,
/// Set score_threshold to a float to filter out chunks with a score below the threshold. This threshold applies before weight and bias modifications. If not specified, this defaults to 0.0.
pub score_threshold: Option<f32>,
/// Filters is a JSON object which can be used to filter chunks. This is useful for when you want to filter chunks by arbitrary metadata. Unlike with tag filtering, there is a performance hit for filtering on metadata.
pub filters: Option<ChunkFilter>,
/// LLM options to use for the completion. If not specified, this defaults to the dataset's LLM options.
pub llm_options: Option<LLMOptions>,
/// Context options to use for the completion. If not specified, all options will default to false.
Expand Down
12 changes: 10 additions & 2 deletions server/src/operators/qdrant_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,11 @@ pub async fn search_over_groups_qdrant_query(

QueryPointGroups {
collection_name: qdrant_collection.to_string(),
limit: Some(query.limit * page),
limit: if use_mmr && query.limit < 20 {
Some(query.limit * 2)
} else {
Some(query.limit * page)
},
prefetch,
using: vector_name,
query: Some(qdrant_query),
Expand Down Expand Up @@ -1101,7 +1105,11 @@ pub async fn search_qdrant_query(

QueryPoints {
collection_name: qdrant_collection.to_string(),
limit: Some(query.limit),
limit: if use_mmr && query.limit < 20 {
Some(query.limit * 2)
} else {
Some(query.limit * page)
},
offset: Some(offset),
prefetch,
using: vector_name,
Expand Down
Loading