Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weaviate frontend #1036

Merged
merged 3 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions gui/pages/Content/Knowledge/KnowledgeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function KnowledgeForm({
const [indexDropdown, setIndexDropdown] = useState(false);
const [pinconeIndices, setPineconeIndices] = useState([]);
const [qdrantIndices, setQdrantIndices] = useState([]);
const [weaviateIndices, setWeaviateIndices] = useState([]);

useEffect(() => {
getValidIndices()
Expand All @@ -33,6 +34,7 @@ export default function KnowledgeForm({
if (data) {
setPineconeIndices(data.pinecone || []);
setQdrantIndices(data.qdrant || []);
setWeaviateIndices(data.weaviate || []);
}
})
.catch((error) => {
Expand Down Expand Up @@ -223,6 +225,23 @@ export default function KnowledgeForm({
</div>}
</div>))}
</div>}
{weaviateIndices && weaviateIndices.length > 0 &&
<div className={styles1.knowledge_db} style={{maxWidth: '100%'}}>
<div className={styles1.knowledge_db_name}>Weaviate</div>
{weaviateIndices.map((index) => (<div key={index.id} className="custom_select_option index_options"
onClick={() => handleIndexSelect(index)}>
<div style={!checkIndexValidity(index.is_valid_state)[0] ? {
color: '#888888',
textDecoration: 'line-through',
pointerEvents : 'none',
} : {}}>{index.name}</div>
{!checkIndexValidity(index.is_valid_state)[0] &&
<div>
<Image width={15} height={15} src="/images/info.svg" alt="info-icon"
title={checkIndexValidity(index.is_valid_state)[1]}/>
</div>}
</div>))}
</div>}
</div>}
</div>
</div>
Expand Down
24 changes: 24 additions & 0 deletions gui/pages/Content/Marketplace/KnowledgeTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function KnowledgeTemplate({template, env}) {
const [indexDropdown, setIndexDropdown] = useState(false);
const [pinconeIndices, setPineconeIndices] = useState([]);
const [qdrantIndices, setQdrantIndices] = useState([]);
const [weaviateIndices, setWeaviateIndices] = useState([]);

useEffect(() => {
getValidMarketplaceIndices(template.name)
Expand All @@ -33,6 +34,7 @@ export default function KnowledgeTemplate({template, env}) {
if (data) {
setPineconeIndices(data.pinecone || []);
setQdrantIndices(data.qdrant || []);
setWeaviateIndices(data.weaviate || [])
}
})
.catch((error) => {
Expand Down Expand Up @@ -239,6 +241,28 @@ export default function KnowledgeTemplate({template, env}) {
</div>}
</div>))}
</div>}
{weaviateIndices && weaviateIndices.length > 0 &&
<div className={styles3.knowledge_db} style={{maxWidth: '100%'}}>
<div className={styles3.knowledge_db_name}>Weaviate</div>
{weaviateIndices.map((index) => (<div key={index.id} className="custom_select_option"
onClick={() => handleInstallClick(index.id)} style={{
padding: '12px 14px',
maxWidth: '100%',
display: 'flex',
justifyContent: 'space-between'
}}>
<div style={!checkIndexValidity(index.is_valid_state, index.is_valid_dimension)[0] ? {
color: '#888888',
textDecoration: 'line-through',
pointerEvents : 'none',
} : {}}>{index.name}</div>
{!checkIndexValidity(index.is_valid_state, index.is_valid_dimension)[0] &&
<div>
<Image width={15} height={15} src="/images/info.svg" alt="info-icon"
title={checkIndexValidity(index.is_valid_state, index.is_valid_dimension)[1]}/>
</div>}
</div>))}
</div>}
</div>}
</div>
</div>}
Expand Down
71 changes: 70 additions & 1 deletion gui/pages/Dashboard/Settings/AddDatabase.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import knowledgeStyles from "@/pages/Content/Knowledge/Knowledge.module.css";
import styles from "@/pages/Content/Marketplace/Market.module.css";
import Image from "next/image";
import styles1 from "@/pages/Content/Agents/Agents.module.css";
import {connectPinecone, connectQdrant, fetchVectorDBList} from "@/pages/api/DashboardService";
import {connectPinecone, connectQdrant, connectWeaviate, fetchVectorDBList} from "@/pages/api/DashboardService";

export default function AddDatabase({internalId, sendDatabaseDetailsData}) {
const [activeView, setActiveView] = useState('select_database');
Expand All @@ -27,6 +27,10 @@ export default function AddDatabase({internalId, sendDatabaseDetailsData}) {

const [qdrantApiKey, setQdrantApiKey] = useState('');
const [qdrantURL, setQdrantURL] = useState('');

const [weaviateApiKey, setWeaviateApiKey] = useState('');
const [weaviateURL, setWeaviateURL] = useState('');

const [qdrantPort, setQdrantPort] = useState(8001);
const [connectText, setConnectText] = useState('Connect');

Expand Down Expand Up @@ -70,6 +74,17 @@ export default function AddDatabase({internalId, sendDatabaseDetailsData}) {
if (qdrant_port) {
setQdrantPort(Number(qdrant_port));
}

const weaviate_api = localStorage.getItem('weaviate_api_' + String(internalId));
if (weaviate_api) {
setWeaviateApiKey(weaviate_api);
}

const weaviate_url = localStorage.getItem('weaviate_url_' + String(internalId));
if (weaviate_url) {
setWeaviateURL(weaviate_url);
}

}, [internalId]);

useEffect(() => {
Expand Down Expand Up @@ -109,6 +124,14 @@ export default function AddDatabase({internalId, sendDatabaseDetailsData}) {
setLocalStorageValue('qdrant_port_' + String(internalId), event.target.value, setQdrantPort);
}

const handleWeaviateAPIKeyChange = (event) => {
setLocalStorageValue('weaviate_api_' + String(internalId), event.target.value, setWeaviateApiKey);
}

const handleWeaviateURLChange = (event) => {
setLocalStorageValue('weaviate_url_' + String(internalId), event.target.value, setWeaviateURL);
}

const addCollection = () => {
setLocalStorageArray("db_collections_" + String(internalId), [...collections, 'collection name'], setCollections);
};
Expand Down Expand Up @@ -140,6 +163,11 @@ export default function AddDatabase({internalId, sendDatabaseDetailsData}) {
return;
}

if(collections.length === 1 && collections[0].length < 1){
toast.error("Atleast add 1 Collection/Index", {autoClose: 1800});
return;
}

if (selectedDB === 'Pinecone') {
if (pineconeApiKey.replace(/\s/g, '') === '') {
toast.error("Pinecone API key is empty", {autoClose: 1800});
Expand Down Expand Up @@ -207,6 +235,37 @@ export default function AddDatabase({internalId, sendDatabaseDetailsData}) {
setConnectText("Connect");
});
}

if (selectedDB === 'Weaviate') {
if (weaviateApiKey.replace(/\s/g, '') === '') {
toast.error("Weaviate API key is empty", {autoClose: 1800});
return;
}

if (weaviateURL.replace(/\s/g, '') === '') {
toast.error("Weaviate URL is empty", {autoClose: 1800});
return;
}

setConnectText("Connecting...");

const weaviateData = {
"name": databaseName,
"collections": collections,
"api_key": weaviateApiKey,
"url": weaviateURL,
}

connectWeaviate(weaviateData)
.then((response) => {
connectResponse(response.data);
})
.catch((error) => {
toast.error("Unable to connect database", {autoClose: 1800});
console.error('Error fetching vector databases:', error);
setConnectText("Connect");
});
}
}

const proceedAddDatabase = () => {
Expand Down Expand Up @@ -321,6 +380,16 @@ export default function AddDatabase({internalId, sendDatabaseDetailsData}) {
<input className="input_medium" type="number" value={qdrantPort} onChange={handleQdrantPortChange}/>
</div>
</div>}
{selectedDB === 'Weaviate' && <div>
<div className="mt_15">
<label className={styles1.form_label}>Weaviate API key</label>
<input className="input_medium" type="password" value={weaviateApiKey} onChange={handleWeaviateAPIKeyChange}/>
</div>
<div className="mt_15">
<label className={styles1.form_label}>Weaviate URL</label>
<input className="input_medium" type="text" value={weaviateURL} onChange={handleWeaviateURLChange}/>
</div>
</div>}
<div style={{display: 'flex', justifyContent: 'flex-end', marginTop: '15px'}}>
<button onClick={() => removeTab(-7, "new database", "Add_Database", internalId)}
className="secondary_button" style={{marginRight: '10px'}}>
Expand Down
1 change: 1 addition & 0 deletions gui/pages/_app.css
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ p {
.mt_10{margin-top: 10px;}
.mt_12{margin-top: 12px;}
.mt_14{margin-top: 14px;}
.mt_15{margin-top: 15px;}
.mt_16{margin-top: 16px;}
.mt_20{margin-top: 20px;}
.mt_24{margin-top: 24px;}
Expand Down
4 changes: 4 additions & 0 deletions gui/pages/api/DashboardService.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ export const connectQdrant = (qdrantData) => {
return api.post(`/vector_dbs/connect/qdrant`, qdrantData);
};

export const connectWeaviate = (weaviateData) => {
return api.post(`/vector_dbs/connect/weaviate`, weaviateData);
};

export const getKnowledge = () => {
return api.get(`/knowledges/user/list`);
};
Expand Down
9 changes: 9 additions & 0 deletions gui/public/images/weaviate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion gui/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,8 @@ export const returnResourceIcon = (file) => {
export const returnDatabaseIcon = (database) => {
const dbTypeIcons = {
'Pinecone': '/images/pinecone.svg',
'Qdrant': '/images/qdrant.svg'
'Qdrant': '/images/qdrant.svg',
'Weaviate' : '/images/weaviate.svg'
};

return dbTypeIcons[database]
Expand Down