From c7efec8bd29d8d6321da446fd4e5d00723701bfb Mon Sep 17 00:00:00 2001 From: Kartik Gupta <84975264+kartik-gupta-ij@users.noreply.github.com> Date: Fri, 17 May 2024 16:28:28 +0530 Subject: [PATCH] Add vector name auto-complete in visualisation (#182) * refactor: Update Autocomplete.js to include vector names in autocomplete suggestions * chore: Update autocomplete-openapi dependency to version 0.1.3 * fmt --- package-lock.json | 14 +++++++------- package.json | 2 +- .../FilterEditorWindow/config/Autocomplete.js | 15 ++++++++++----- src/components/FilterEditorWindow/index.jsx | 2 +- src/components/Sidebar/Sidebar.jsx | 1 - 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index ce7ecae3..75edb5a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,7 +30,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", @@ -2665,9 +2665,9 @@ "license": "MIT" }, "node_modules/autocomplete-openapi": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/autocomplete-openapi/-/autocomplete-openapi-0.1.2.tgz", - "integrity": "sha512-m181So8ih34tiWGX1J62tmZTvxirajpV0mWr5PZsg2lnmiGD76HARf1Z/Qlg6oNsKp3DXIs6K+7nm8upTHQ2uQ==" + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/autocomplete-openapi/-/autocomplete-openapi-0.1.3.tgz", + "integrity": "sha512-TouTKt4qLkU5rpmh8owvReRXH+Tre3Qrs2zUpT9gakYoJBvrppaBNZDoFVLBHwd6YKZ7giXxueU87sx+awligA==" }, "node_modules/available-typed-arrays": { "version": "1.0.5", @@ -9868,9 +9868,9 @@ "version": "0.4.0" }, "autocomplete-openapi": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/autocomplete-openapi/-/autocomplete-openapi-0.1.2.tgz", - "integrity": "sha512-m181So8ih34tiWGX1J62tmZTvxirajpV0mWr5PZsg2lnmiGD76HARf1Z/Qlg6oNsKp3DXIs6K+7nm8upTHQ2uQ==" + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/autocomplete-openapi/-/autocomplete-openapi-0.1.3.tgz", + "integrity": "sha512-TouTKt4qLkU5rpmh8owvReRXH+Tre3Qrs2zUpT9gakYoJBvrppaBNZDoFVLBHwd6YKZ7giXxueU87sx+awligA==" }, "available-typed-arrays": { "version": "1.0.5" diff --git a/package.json b/package.json index 293dccaf..e10c35bd 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/FilterEditorWindow/config/Autocomplete.js b/src/components/FilterEditorWindow/config/Autocomplete.js index 9c3c736a..9457451f 100644 --- a/src/components/FilterEditorWindow/config/Autocomplete.js +++ b/src/components/FilterEditorWindow/config/Autocomplete.js @@ -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); } @@ -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', @@ -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) => { diff --git a/src/components/FilterEditorWindow/index.jsx b/src/components/FilterEditorWindow/index.jsx index 41f63d99..f8fed576 100644 --- a/src/components/FilterEditorWindow/index.jsx +++ b/src/components/FilterEditorWindow/index.jsx @@ -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); }); } diff --git a/src/components/Sidebar/Sidebar.jsx b/src/components/Sidebar/Sidebar.jsx index 3827ac34..1191d816 100644 --- a/src/components/Sidebar/Sidebar.jsx +++ b/src/components/Sidebar/Sidebar.jsx @@ -83,7 +83,6 @@ export default function Sidebar({ open, version, jwtEnabled }) { } function sidebarItem(title, icon, linkPath, isOpen, enabled = true) { - console.log('enabled', enabled); return (