mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-05-07 06:22:58 +08:00
feat: Add vector database clearing
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from fastapi import FastAPI
|
||||
|
||||
from .routes import adapters, virtual_fs, auth, config, processors, tasks, logs, share, backup, search
|
||||
from .routes import adapters, virtual_fs, auth, config, processors, tasks, logs, share, backup, search, vector_db
|
||||
|
||||
|
||||
def include_routers(app: FastAPI):
|
||||
@@ -14,4 +14,5 @@ def include_routers(app: FastAPI):
|
||||
app.include_router(logs.router)
|
||||
app.include_router(share.router)
|
||||
app.include_router(share.public_router)
|
||||
app.include_router(backup.router)
|
||||
app.include_router(backup.router)
|
||||
app.include_router(vector_db.router)
|
||||
19
api/routes/vector_db.py
Normal file
19
api/routes/vector_db.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from services.auth import get_current_active_user
|
||||
from models.database import UserAccount
|
||||
from services.vector_db import VectorDBService
|
||||
from api.response import success
|
||||
|
||||
router = APIRouter(prefix="/api/vector-db", tags=["vector-db"])
|
||||
|
||||
|
||||
@router.post("/clear-all", summary="清空向量数据库")
|
||||
async def clear_vector_db(user: UserAccount = Depends(get_current_active_user)):
|
||||
if user.username != 'admin':
|
||||
raise HTTPException(status_code=403, detail="仅管理员可操作")
|
||||
try:
|
||||
service = VectorDBService()
|
||||
service.clear_all_data()
|
||||
return success(msg="向量数据库已清空")
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
@@ -75,3 +75,9 @@ class VectorDBService:
|
||||
output_fields=["path"]
|
||||
)
|
||||
return [[{'id': r['path'], 'distance': 1.0, 'entity': {'path': r['path']}} for r in results]]
|
||||
|
||||
def clear_all_data(self):
|
||||
"""清空所有集合的内容"""
|
||||
collections = self.client.list_collections()
|
||||
for collection_name in collections:
|
||||
self.client.drop_collection(collection_name)
|
||||
|
||||
5
web/src/api/vectorDB.ts
Normal file
5
web/src/api/vectorDB.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import client from './client';
|
||||
|
||||
export const vectorDBApi = {
|
||||
clearAll: () => client('/vector-db/clear-all', { method: 'POST' }),
|
||||
};
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Form, Input, Button, message, Tabs, Space, Card } from 'antd';
|
||||
import { Form, Input, Button, message, Tabs, Space, Card, Select, Modal } from 'antd';
|
||||
import { useEffect, useState } from 'react';
|
||||
import PageCard from '../../components/PageCard';
|
||||
import { getAllConfig, setConfig } from '../../api/config';
|
||||
import { AppstoreOutlined, RobotOutlined } from '@ant-design/icons';
|
||||
import { vectorDBApi } from '../../api/vectorDB';
|
||||
import { AppstoreOutlined, RobotOutlined, DatabaseOutlined } from '@ant-design/icons';
|
||||
|
||||
const APP_CONFIG_KEYS: {key: string, label: string, default?: string}[] = [
|
||||
{ key: 'APP_NAME', label: '应用名称' },
|
||||
@@ -134,6 +135,54 @@ export default function SystemSettingsPage() {
|
||||
</Form>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'vector-db',
|
||||
label: (
|
||||
<span>
|
||||
<DatabaseOutlined style={{ marginRight: 8 }} />
|
||||
向量数据库
|
||||
</span>
|
||||
),
|
||||
children: (
|
||||
<Card title="向量数据库设置" style={{ marginTop: 24 }}>
|
||||
<Form layout="vertical">
|
||||
<Form.Item label="数据库类型">
|
||||
<Select
|
||||
size="large"
|
||||
value="Milvus Lite"
|
||||
disabled
|
||||
options={[{ value: 'Milvus Lite', label: 'Milvus Lite' }]}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Button
|
||||
danger
|
||||
block
|
||||
onClick={() => {
|
||||
Modal.confirm({
|
||||
title: '确认清空向量数据库?',
|
||||
content: '此操作将删除所有集合中的所有数据,且不可逆。',
|
||||
okText: '确认清空',
|
||||
okType: 'danger',
|
||||
cancelText: '取消',
|
||||
onOk: async () => {
|
||||
try {
|
||||
await vectorDBApi.clearAll();
|
||||
message.success('向量数据库已清空');
|
||||
} catch (e: any) {
|
||||
message.error(e.message || '清空失败');
|
||||
}
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
清空向量库
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Card>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</Space>
|
||||
|
||||
Reference in New Issue
Block a user