Skip to content

Commit

Permalink
CON-232 bring custom docs to top, alphabetize doc results, make scrol… (
Browse files Browse the repository at this point in the history
#1239)

* CON-232 bring custom docs to top, alphabetize doc results, make scrollable

* CON-232 cleanup

---------

Co-authored-by: Justin Milner <jmilner@jmilner-lt2.deka.local>
  • Loading branch information
justinmilner1 and Justin Milner committed May 6, 2024
1 parent 7f05366 commit 6803dc5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
18 changes: 17 additions & 1 deletion core/context/providers/DocsContextProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class DocsContextProvider extends BaseContextProvider {
extras: ContextProviderExtras,
): Promise<ContextItem[]> {
const { retrieveDocs } = await import("../../indexing/docs/db");

const embeddingsProvider = new TransformersJsEmbeddingsProvider();
const [vector] = await embeddingsProvider.embed([extras.fullInput]);

Expand Down Expand Up @@ -102,6 +101,23 @@ class DocsContextProvider extends BaseContextProvider {
id: config.startUrl,
})),
);

// Sort submenuItems such that the objects with titles which don't occur in configs occur first, and alphabetized
submenuItems.sort((a, b) => {
const aTitleInConfigs = !!configs.find(config => config.title === a.title);
const bTitleInConfigs = !!configs.find(config => config.title === b.title);

// Primary criterion: Items not in configs come first
if (!aTitleInConfigs && bTitleInConfigs) {
return -1;
} else if (aTitleInConfigs && !bTitleInConfigs) {
return 1;
} else {
// Secondary criterion: Alphabetical order when both items are in the same category
return a.title.localeCompare(b.title);
}
});

return submenuItems;
}
}
Expand Down
2 changes: 2 additions & 0 deletions gui/src/components/mainInput/MentionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ const ItemsDiv = styled.div`
0px 10px 20px rgba(0, 0, 0, 0.1);
font-size: 0.9rem;
overflow-x: hidden;
overflow-y: auto;
max-height: 330px;
padding: 0.2rem;
position: relative;
Expand Down
2 changes: 1 addition & 1 deletion gui/src/hooks/useSubmenuContextProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const MINISEARCH_OPTIONS = {
fuzzy: 2,
};

const MAX_LENGTH = 10;
const MAX_LENGTH = 70;

function useSubmenuContextProviders() {
// TODO: Refresh periodically
Expand Down

0 comments on commit 6803dc5

Please sign in to comment.