Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #215 from Tumao727/bugfix/vector-search-id
Browse files Browse the repository at this point in the history
Fix not show id field in vector search
  • Loading branch information
shanghaikid authored Aug 14, 2021
2 parents b5b8183 + 2e86c96 commit 2de7970
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 21 additions & 3 deletions client/src/pages/seach/VectorSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,36 @@ const VectorSearch = () => {
return nonVectorFields.map(f => f._fieldName);
}, [selectedCollection, collections]);

const primaryKeyField = useMemo(() => {
const selectedCollectionInfo = collections.find(
c => c._name === selectedCollection
);
const fields = selectedCollectionInfo?._fields || [];
return fields.find(f => f._isPrimaryKey)?._fieldName;
}, [selectedCollection, collections]);

const colDefinitions: ColDefinitionsType[] = useMemo(() => {
// filter id and score
/**
* id represents primary key, score represents distance
* since we transfer score to distance in the view, and original field which is primary key has already in the table
* we filter 'id' and 'score' to avoid redundant data
*/
return searchResult && searchResult.length > 0
? Object.keys(searchResult[0])
.filter(item => item !== 'id' && item !== 'score')
.filter(item => {
// if primary key field name is id, don't filter it
const invalidItems =
primaryKeyField === 'id' ? ['score'] : ['id', 'score'];
return !invalidItems.includes(item);
})
.map(key => ({
id: key,
align: 'left',
disablePadding: false,
label: key,
}))
: [];
}, [searchResult]);
}, [searchResult, primaryKeyField]);

const {
metricType,
Expand Down Expand Up @@ -367,6 +384,7 @@ const VectorSearch = () => {
value={selectedCollection}
onChange={(e: { target: { value: unknown } }) => {
const collection = e.target.value;

setSelectedCollection(collection as string);
// every time selected collection changed, reset field
setSelectedField('');
Expand Down
2 changes: 1 addition & 1 deletion client/src/utils/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const transferSearchResult = (
.sort((a, b) => a.score - b.score)
.map((r, index) => ({
rank: index + 1,
distance: r.score,
...r,
distance: r.score,
}));

return resultView;
Expand Down

0 comments on commit 2de7970

Please sign in to comment.