Skip to content

Commit

Permalink
Index accuracy check (#199)
Browse files Browse the repository at this point in the history
* added vectors view to the collection info tab

* format

* getting accuracy

* fixes and tests

* separate tab for accuracy checks with logging

* fix test

* advanced mod switch

* refactor named vectors, improve logging, rename to precision

* add files

* fmt

* fixes

* fix table and progress bar

* make advanced mode work

* allow to set fixed heigh to editor

* add SearchQualityPannel

* format

* rename files

---------

Co-authored-by: generall <[email protected]>
  • Loading branch information
trean and generall authored Aug 8, 2024
1 parent 7b2ab8b commit 6e2e2e8
Show file tree
Hide file tree
Showing 7 changed files with 511 additions and 4 deletions.
97 changes: 97 additions & 0 deletions src/components/Collections/SearchQuality/SearchQuality.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
import { getSnackbarOptions } from '../../Common/utils/snackbarOptions';
import { useClient } from '../../../context/client-context';
import SearchQualityPannel from './SearchQualityPannel';
import { useSnackbar } from 'notistack';
import { Box, Card, CardHeader } from '@mui/material';
import { CopyButton } from '../../Common/CopyButton';
import { bigIntJSON } from '../../../common/bigIntJSON';
import EditorCommon from '../../EditorCommon';
import _ from 'lodash';

const SearchQuality = ({ collectionName }) => {
const { enqueueSnackbar, closeSnackbar } = useSnackbar();
const { client } = useClient();
const [collection, setCollection] = React.useState(null);
const [log, setLog] = React.useState('');

const handleLogUpdate = (newLog) => {
const date = new Date().toLocaleString();
newLog = `[${date}] ${newLog}`;
setLog((prevLog) => {
return newLog + '\n' + prevLog;
});
};

const clearLogs = () => {
setLog('');
};

useEffect(() => {
client
.getCollection(collectionName)
.then((res) => {
setCollection(() => {
return { ...res };
});
})
.catch((err) => {
enqueueSnackbar(err.message, getSnackbarOptions('error', closeSnackbar));
});
}, []);

// Check that collection.config.params.vectors?.size exists and integer
const isNamedVectors = collection?.config?.params.vectors?.size && !_.isObject(collection?.config?.params?.vectors);
let vectors = {};
if (collection) {
vectors = isNamedVectors ? collection?.config?.params?.vectors : { '': collection?.config?.params?.vectors };
}

return (
<>
{collection?.config?.params?.vectors && (
<SearchQualityPannel
collectionName={collectionName}
vectors={vectors}
loggingFoo={handleLogUpdate}
clearLogsFoo={clearLogs}
sx={{ mt: 5 }}
/>
)}

<Card varian="dual" sx={{ mt: 5 }}>
<CardHeader
title={'Report'}
variant="heading"
sx={{
flexGrow: 1,
}}
action={<CopyButton text={bigIntJSON.stringify(log)} />}
/>
<Box sx={{ pt: 2, pb: 1, pr: 1 }}>
<EditorCommon
theme={'custom-language-theme'}
value={log}
options={{
scrollBeyondLastLine: false,
fontSize: 12,
wordWrap: 'on',
minimap: { enabled: false },
automaticLayout: true,
readOnly: true,
mouseWheelZoom: true,
lineNumbers: 'off',
}}
/>
</Box>
</Card>
</>
);
};

SearchQuality.propTypes = {
collectionName: PropTypes.string,
};

export default SearchQuality;
Loading

0 comments on commit 6e2e2e8

Please sign in to comment.