Skip to content

Commit

Permalink
fix(autocomplete): adjust Fuse search parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
mert-ergun committed Jan 29, 2025
1 parent f1d293a commit 7a5fda3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 41 deletions.
2 changes: 1 addition & 1 deletion crossbar_llm/frontend/public/suggestions.json

Large diffs are not rendered by default.

41 changes: 2 additions & 39 deletions crossbar_llm/frontend/src/components/AutocompleteTextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,11 @@ function AutocompleteTextField({ value, setValue, label, placeholder }) {

const fuse = new Fuse(suggestions, {
includeScore: true,
threshold: 0.2,
distance: 10,
location: 0,
keys: [
{
name: 'default',
weight: 1.0
}
],
sortFn: (a, b) => {
const aStr = suggestions[a.idx].toLowerCase();
const bStr = suggestions[b.idx].toLowerCase();
const query = value.slice(value.lastIndexOf('@') + 1, cursorPosition).toLowerCase();

// Exact prefix match gets highest priority
const aStartsWithQuery = aStr.startsWith(query);
const bStartsWithQuery = bStr.startsWith(query);

if (aStartsWithQuery && !bStartsWithQuery) return -1;
if (!aStartsWithQuery && bStartsWithQuery) return 1;

// If both start with query, shorter one gets priority
if (aStartsWithQuery && bStartsWithQuery) {
return aStr.length - bStr.length;
}

// Fall back to default Fuse score comparison
return a.score - b.score;
}
threshold: 0.3,
});

const debounceTimeoutRef = useRef(null);

const getMentionState = (position) => {
for (const mention of mentions) {
if (position >= mention.start && position <= mention.end) {
return mention.state;
}
}
return null;
};

const renderStyledText = () => {
const parts = [];
let lastIndex = 0;
Expand Down Expand Up @@ -157,7 +120,7 @@ function AutocompleteTextField({ value, setValue, label, placeholder }) {
const lastAtSymbol = newValue.lastIndexOf('@', cursorPosition - 1);

if (lastAtSymbol !== -1) {
const query = newValue.slice(lastAtSymbol + 1, cursorPosition);
const query = newValue.slice(lastAtSymbol + 1, cursorPosition+1);
if (query.length > 2) {
const results = fuse.search(query);
const matchedSuggestions = results.map((result) => result.item);
Expand Down
2 changes: 1 addition & 1 deletion crossbar_llm/frontend/src/scripts/createSuggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re

def create_suggestions():
folder_path = "../../public"
folder_path = "../../public/"
suggestions_set = set()
for file_name in os.listdir(folder_path):
if file_name.endswith(".txt"):
Expand Down

0 comments on commit 7a5fda3

Please sign in to comment.