Skip to content

Commit

Permalink
Add vector name auto-complete in visualisation (#182)
Browse files Browse the repository at this point in the history
* refactor: Update Autocomplete.js to include vector names in autocomplete suggestions

* chore: Update autocomplete-openapi dependency to version 0.1.3

* fmt
  • Loading branch information
kartik-gupta-ij authored May 17, 2024
1 parent fa0a058 commit c7efec8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@uppy/react": "^3.1.2",
"@uppy/xhr-upload": "^3.3.1",
"@vitejs/plugin-react": "^4.0.0",
"autocomplete-openapi": "^0.1.2",
"autocomplete-openapi": "0.1.3",
"axios": "^1.6.7",
"chart.js": "^4.3.0",
"chroma-js": "^2.4.2",
Expand Down
15 changes: 10 additions & 5 deletions src/components/FilterEditorWindow/config/Autocomplete.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { OpenapiAutocomplete } from 'autocomplete-openapi/src/autocomplete';

export const autocomplete = async (monaco, qdrantClient) => {
export const autocomplete = async (monaco, qdrantClient, collectionName) => {
const response = await fetch(import.meta.env.BASE_URL + './openapi.json');
const openapi = await response.json();

let collections = [];
const vectorNames = [];
try {
collections = (await qdrantClient.getCollections()).collections.map((c) => c.name);
const collectionInfo = await qdrantClient.getCollection(collectionName);
Object.keys(collectionInfo.config.params.vectors).map((key) => {
if (typeof collectionInfo.config.params.vectors[key] === 'object') {
vectorNames.push(key);
}
});
} catch (e) {
console.error(e);
}
Expand Down Expand Up @@ -35,7 +40,7 @@ export const autocomplete = async (monaco, qdrantClient) => {
vector_name: {
description: 'Vector field name',
type: 'string',
nullable: true,
enum: vectorNames,
},
color_by: {
description: 'Color points by this field',
Expand All @@ -46,7 +51,7 @@ export const autocomplete = async (monaco, qdrantClient) => {
};
openapi.components.schemas.FilterRequest = FilterRequest;

const autocomplete = new OpenapiAutocomplete(openapi, collections);
const autocomplete = new OpenapiAutocomplete(openapi, []);

return {
provideCompletionItems: (model, position) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/FilterEditorWindow/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const CodeEditorWindow = ({ onChange, code, onChangeResult }) => {
});
}
function handleEditorWillMount(monaco) {
autocomplete(monaco, qdrantClient).then((autocomplete) => {
autocomplete(monaco, qdrantClient, collectionName).then((autocomplete) => {
autocompleteRef.current = monaco.languages.registerCompletionItemProvider('custom-language', autocomplete);
});
}
Expand Down
1 change: 0 additions & 1 deletion src/components/Sidebar/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export default function Sidebar({ open, version, jwtEnabled }) {
}

function sidebarItem(title, icon, linkPath, isOpen, enabled = true) {
console.log('enabled', enabled);
return (
<ListItem key={title} disablePadding sx={{ display: 'block' }}>
<Tooltip title={title} placement="right" arrow disableHoverListener={isOpen}>
Expand Down

0 comments on commit c7efec8

Please sign in to comment.