2024-07-17 18:52:20 +08:00
|
|
|
|
<template>
|
2024-09-06 12:54:17 +08:00
|
|
|
|
<div class="database-empty" v-if="!state.showPage">
|
|
|
|
|
|
<a-empty>
|
|
|
|
|
|
<template #description>
|
|
|
|
|
|
<span>
|
2025-02-26 10:57:24 +08:00
|
|
|
|
前往 <router-link to="/setting" style="color: var(--main-color); font-weight: bold;">设置</router-link> 页面启用知识图谱。
|
2024-09-06 12:54:17 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</a-empty>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="graph-container layout-container" v-else>
|
2024-09-14 02:46:44 +08:00
|
|
|
|
<HeaderComponent
|
|
|
|
|
|
title="图数据库"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template #actions>
|
2025-12-15 23:25:56 +08:00
|
|
|
|
<div class="db-selector">
|
2024-09-14 02:46:44 +08:00
|
|
|
|
<div class="status-wrapper">
|
|
|
|
|
|
<div class="status-indicator" :class="graphStatusClass"></div>
|
2025-08-24 16:51:23 +08:00
|
|
|
|
<span class="status-text">{{ graphStatusText }}</span>
|
2024-09-14 02:46:44 +08:00
|
|
|
|
</div>
|
2025-12-15 23:25:56 +08:00
|
|
|
|
<span class="label">知识库: </span>
|
|
|
|
|
|
<a-select
|
|
|
|
|
|
v-model:value="state.selectedDbId"
|
|
|
|
|
|
style="width: 200px"
|
|
|
|
|
|
:options="state.dbOptions"
|
|
|
|
|
|
@change="handleDbChange"
|
|
|
|
|
|
:loading="state.loadingDatabases"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<!-- <a-button type="default" @click="openLink('http://localhost:7474/')" :icon="h(GlobalOutlined)">
|
2025-07-23 19:21:45 +08:00
|
|
|
|
Neo4j 浏览器
|
2025-12-15 23:25:56 +08:00
|
|
|
|
</a-button> -->
|
2024-09-14 02:46:44 +08:00
|
|
|
|
<a-button type="primary" @click="state.showModal = true" ><UploadOutlined/> 上传文件</a-button>
|
2025-03-08 22:49:22 +08:00
|
|
|
|
<a-button v-if="unindexedCount > 0" type="primary" @click="indexNodes" :loading="state.indexing">
|
2025-09-16 00:34:41 +08:00
|
|
|
|
<SyncOutlined v-if="!state.indexing"/> 为{{ unindexedCount }}个节点添加索引
|
2025-03-08 22:49:22 +08:00
|
|
|
|
</a-button>
|
2024-09-14 02:46:44 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</HeaderComponent>
|
|
|
|
|
|
|
2025-09-03 03:00:25 +08:00
|
|
|
|
<div class="container-outter">
|
2025-09-03 16:06:56 +08:00
|
|
|
|
<GraphCanvas
|
|
|
|
|
|
ref="graphRef"
|
2025-12-15 23:25:56 +08:00
|
|
|
|
:graph-data="graph.graphData"
|
2025-09-11 02:44:35 +08:00
|
|
|
|
:highlight-keywords="[state.searchInput]"
|
2025-12-15 23:25:56 +08:00
|
|
|
|
@node-click="graph.handleNodeClick"
|
|
|
|
|
|
@edge-click="graph.handleEdgeClick"
|
|
|
|
|
|
@canvas-click="graph.handleCanvasClick"
|
2025-09-03 16:06:56 +08:00
|
|
|
|
>
|
|
|
|
|
|
<template #top>
|
|
|
|
|
|
<div class="actions">
|
|
|
|
|
|
<div class="actions-left">
|
|
|
|
|
|
<a-input
|
|
|
|
|
|
v-model:value="state.searchInput"
|
2025-12-15 23:25:56 +08:00
|
|
|
|
:placeholder="isNeo4j ? '输入要查询的实体' : '输入要查询的实体 (*为全部)'"
|
2025-09-03 16:06:56 +08:00
|
|
|
|
style="width: 300px"
|
|
|
|
|
|
@keydown.enter="onSearch"
|
|
|
|
|
|
allow-clear
|
|
|
|
|
|
>
|
|
|
|
|
|
<template #suffix>
|
|
|
|
|
|
<component :is="state.searchLoading ? LoadingOutlined : SearchOutlined" @click="onSearch" />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</a-input>
|
|
|
|
|
|
<a-input
|
|
|
|
|
|
v-model:value="sampleNodeCount"
|
2025-12-15 23:25:56 +08:00
|
|
|
|
placeholder="查询数量"
|
2025-09-03 16:06:56 +08:00
|
|
|
|
style="width: 100px"
|
|
|
|
|
|
@keydown.enter="loadSampleNodes"
|
2025-12-15 23:25:56 +08:00
|
|
|
|
:loading="graph.fetching"
|
2025-09-03 16:06:56 +08:00
|
|
|
|
>
|
|
|
|
|
|
<template #suffix>
|
2025-12-15 23:25:56 +08:00
|
|
|
|
<component :is="graph.fetching ? LoadingOutlined : ReloadOutlined" @click="loadSampleNodes" />
|
2025-09-03 16:06:56 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</a-input>
|
|
|
|
|
|
</div>
|
2025-12-15 23:25:56 +08:00
|
|
|
|
<div class="actions-right">
|
|
|
|
|
|
<a-button type="default" @click="state.showInfoModal = true" :icon="h(InfoCircleOutlined)">
|
|
|
|
|
|
说明
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
</div>
|
2025-09-03 03:00:25 +08:00
|
|
|
|
</div>
|
2025-09-03 16:06:56 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
<template #content>
|
2025-12-15 23:25:56 +08:00
|
|
|
|
<a-empty v-show="graph.graphData.nodes.length === 0" style="padding: 4rem 0;"/>
|
2025-09-03 16:06:56 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
<template #bottom>
|
|
|
|
|
|
<div class="footer">
|
2025-11-18 21:21:20 +08:00
|
|
|
|
<GraphInfoPanel
|
2025-12-15 23:25:56 +08:00
|
|
|
|
v-if="isNeo4j"
|
2025-11-18 21:21:20 +08:00
|
|
|
|
:graph-info="graphInfo"
|
2025-12-15 23:25:56 +08:00
|
|
|
|
:graph-data="graph.graphData"
|
2025-11-18 21:21:20 +08:00
|
|
|
|
:unindexed-count="unindexedCount"
|
|
|
|
|
|
:model-matched="modelMatched"
|
|
|
|
|
|
@index-nodes="indexNodes"
|
|
|
|
|
|
@export-data="exportGraphData"
|
|
|
|
|
|
/>
|
2025-12-15 23:25:56 +08:00
|
|
|
|
<LightRAGInfoPanel
|
|
|
|
|
|
v-else
|
|
|
|
|
|
:stats="state.lightragStats"
|
|
|
|
|
|
:graph-data="graph.graphData"
|
|
|
|
|
|
:database-name="getDatabaseName()"
|
|
|
|
|
|
@export-data="exportGraphData"
|
|
|
|
|
|
/>
|
2025-09-03 03:00:25 +08:00
|
|
|
|
</div>
|
2025-09-03 16:06:56 +08:00
|
|
|
|
</template>
|
2025-12-15 23:25:56 +08:00
|
|
|
|
</GraphCanvas>
|
|
|
|
|
|
<!-- 详情浮动卡片 -->
|
|
|
|
|
|
<GraphDetailPanel
|
|
|
|
|
|
:visible="graph.showDetailDrawer"
|
|
|
|
|
|
:item="graph.selectedItem"
|
|
|
|
|
|
:type="graph.selectedItemType"
|
|
|
|
|
|
:nodes="graph.graphData.nodes"
|
|
|
|
|
|
@close="graph.handleCanvasClick"
|
|
|
|
|
|
style="width: 380px;"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2024-09-14 02:46:44 +08:00
|
|
|
|
|
2025-12-15 23:25:56 +08:00
|
|
|
|
<a-modal
|
2024-09-14 02:46:44 +08:00
|
|
|
|
:open="state.showModal" title="上传文件"
|
|
|
|
|
|
@ok="addDocumentByFile"
|
|
|
|
|
|
@cancel="() => state.showModal = false"
|
|
|
|
|
|
ok-text="添加到图数据库" cancel-text="取消"
|
2025-08-24 16:51:23 +08:00
|
|
|
|
:confirm-loading="state.processing">
|
2024-09-14 02:46:44 +08:00
|
|
|
|
<div class="upload">
|
2025-08-25 13:57:47 +08:00
|
|
|
|
<div class="note">
|
|
|
|
|
|
<p>上传的文件内容参考 test/data/A_Dream_of_Red_Mansions_tiny.jsonl 中的格式:</p>
|
|
|
|
|
|
</div>
|
2024-09-14 02:46:44 +08:00
|
|
|
|
<a-upload-dragger
|
|
|
|
|
|
class="upload-dragger"
|
|
|
|
|
|
v-model:fileList="fileList"
|
|
|
|
|
|
name="file"
|
|
|
|
|
|
:fileList="fileList"
|
|
|
|
|
|
:max-count="1"
|
2025-10-17 12:15:40 +08:00
|
|
|
|
accept=".jsonl"
|
|
|
|
|
|
action="/api/knowledge/files/upload?allow_jsonl=true"
|
2025-05-09 23:46:15 +08:00
|
|
|
|
:headers="getAuthHeaders()"
|
2024-09-14 02:46:44 +08:00
|
|
|
|
@change="handleFileUpload"
|
|
|
|
|
|
@drop="handleDrop"
|
|
|
|
|
|
>
|
|
|
|
|
|
<p class="ant-upload-text">点击或者把文件拖拽到这里上传</p>
|
|
|
|
|
|
<p class="ant-upload-hint">
|
2025-08-12 19:14:44 +08:00
|
|
|
|
目前仅支持上传 jsonl 文件。
|
2024-09-14 02:46:44 +08:00
|
|
|
|
</p>
|
|
|
|
|
|
</a-upload-dragger>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</a-modal>
|
2025-08-24 16:51:23 +08:00
|
|
|
|
|
|
|
|
|
|
<!-- 说明弹窗 -->
|
|
|
|
|
|
<a-modal
|
|
|
|
|
|
:open="state.showInfoModal"
|
|
|
|
|
|
title="图数据库说明"
|
|
|
|
|
|
@cancel="() => state.showInfoModal = false"
|
|
|
|
|
|
:footer="null"
|
|
|
|
|
|
width="600px"
|
|
|
|
|
|
>
|
2025-12-15 23:25:56 +08:00
|
|
|
|
<div class="info-content" v-if="isNeo4j">
|
2025-08-24 16:51:23 +08:00
|
|
|
|
<p>本页面展示的是 Neo4j 图数据库中的知识图谱信息。</p>
|
|
|
|
|
|
<p>具体展示内容包括:</p>
|
|
|
|
|
|
<ul>
|
|
|
|
|
|
<li>带有 <code>Entity</code> 标签的节点</li>
|
|
|
|
|
|
<li>带有 <code>RELATION</code> 类型的关系边</li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
<p>注意:</p>
|
|
|
|
|
|
<ul>
|
|
|
|
|
|
<li>这里仅展示用户上传的实体和关系,不包含知识库中自动创建的图谱。</li>
|
2025-12-15 23:25:56 +08:00
|
|
|
|
<li>查询逻辑基于 <code>graphbase.py</code> 中的 <code>get_sample_nodes</code> 方法实现。</li>
|
2025-08-24 16:51:23 +08:00
|
|
|
|
</ul>
|
2025-12-15 23:25:56 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="info-content" v-else>
|
|
|
|
|
|
<p>本页面展示的是 LightRAG 知识库生成的图谱信息。</p>
|
|
|
|
|
|
<p>数据来源于选定的知识库实例。</p>
|
|
|
|
|
|
<p>支持通过实体名称进行模糊搜索,输入 "*" 可查看采样全图。</p>
|
2025-08-24 16:51:23 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</a-modal>
|
2024-09-01 18:10:50 +08:00
|
|
|
|
</div>
|
2024-07-17 18:52:20 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2025-07-23 19:21:45 +08:00
|
|
|
|
import { computed, onMounted, reactive, ref, h } from 'vue';
|
2025-09-03 16:06:56 +08:00
|
|
|
|
import { message } from 'ant-design-vue';
|
2024-09-01 18:10:50 +08:00
|
|
|
|
import { useConfigStore } from '@/stores/config';
|
2025-09-11 02:44:35 +08:00
|
|
|
|
import { UploadOutlined, SyncOutlined, GlobalOutlined, InfoCircleOutlined, SearchOutlined, ReloadOutlined, LoadingOutlined, HighlightOutlined } from '@ant-design/icons-vue';
|
2024-09-14 02:46:44 +08:00
|
|
|
|
import HeaderComponent from '@/components/HeaderComponent.vue';
|
2025-12-15 23:25:56 +08:00
|
|
|
|
import { neo4jApi, unifiedApi } from '@/apis/graph_api';
|
2025-05-09 23:46:15 +08:00
|
|
|
|
import { useUserStore } from '@/stores/user';
|
2025-09-03 16:06:56 +08:00
|
|
|
|
import GraphCanvas from '@/components/GraphCanvas.vue';
|
2025-11-18 21:21:20 +08:00
|
|
|
|
import GraphInfoPanel from '@/components/GraphInfoPanel.vue';
|
2025-12-15 23:25:56 +08:00
|
|
|
|
import LightRAGInfoPanel from '@/components/LightRAGInfoPanel.vue';
|
|
|
|
|
|
import GraphDetailPanel from '@/components/GraphDetailPanel.vue';
|
|
|
|
|
|
import UploadModal from '@/components/FileUploadModal.vue';
|
|
|
|
|
|
import { useGraph } from '@/composables/useGraph';
|
2024-09-01 18:10:50 +08:00
|
|
|
|
|
2025-05-02 23:56:59 +08:00
|
|
|
|
const configStore = useConfigStore();
|
2025-07-28 19:37:02 +08:00
|
|
|
|
const cur_embed_model = computed(() => configStore.config?.embed_model);
|
2025-03-03 15:18:34 +08:00
|
|
|
|
const modelMatched = computed(() => !graphInfo?.value?.embed_model_name || graphInfo.value.embed_model_name === cur_embed_model.value)
|
2024-07-24 18:32:14 +08:00
|
|
|
|
|
2025-09-03 16:06:56 +08:00
|
|
|
|
const graphRef = ref(null)
|
2024-09-06 21:30:49 +08:00
|
|
|
|
const graphInfo = ref(null)
|
2024-07-24 18:32:14 +08:00
|
|
|
|
const fileList = ref([]);
|
2024-09-06 12:54:17 +08:00
|
|
|
|
const sampleNodeCount = ref(100);
|
2025-12-15 23:25:56 +08:00
|
|
|
|
|
|
|
|
|
|
const graph = reactive(useGraph(graphRef));
|
2024-07-24 18:32:14 +08:00
|
|
|
|
|
|
|
|
|
|
const state = reactive({
|
2024-09-06 21:30:49 +08:00
|
|
|
|
loadingGraphInfo: false,
|
2025-12-15 23:25:56 +08:00
|
|
|
|
loadingDatabases: false,
|
2024-07-24 18:32:14 +08:00
|
|
|
|
searchInput: '',
|
|
|
|
|
|
searchLoading: false,
|
|
|
|
|
|
showModal: false,
|
2025-08-24 16:51:23 +08:00
|
|
|
|
showInfoModal: false,
|
2025-09-03 16:06:56 +08:00
|
|
|
|
processing: false,
|
2025-03-08 22:49:22 +08:00
|
|
|
|
indexing: false,
|
2025-06-27 01:47:52 +08:00
|
|
|
|
showPage: true,
|
2025-12-15 23:25:56 +08:00
|
|
|
|
selectedDbId: 'neo4j',
|
|
|
|
|
|
dbOptions: [],
|
|
|
|
|
|
lightragStats: null,
|
2024-07-24 18:32:14 +08:00
|
|
|
|
})
|
2024-07-17 18:52:20 +08:00
|
|
|
|
|
2025-12-15 23:25:56 +08:00
|
|
|
|
const isNeo4j = computed(() => state.selectedDbId === 'neo4j');
|
|
|
|
|
|
|
2025-03-08 22:49:22 +08:00
|
|
|
|
// 计算未索引节点数量
|
|
|
|
|
|
const unindexedCount = computed(() => {
|
|
|
|
|
|
return graphInfo.value?.unindexed_node_count || 0;
|
|
|
|
|
|
});
|
2024-09-03 16:37:59 +08:00
|
|
|
|
|
2025-12-15 23:25:56 +08:00
|
|
|
|
const loadDatabases = async () => {
|
|
|
|
|
|
state.loadingDatabases = true;
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await unifiedApi.getGraphs();
|
|
|
|
|
|
if (res.success && res.data) {
|
|
|
|
|
|
state.dbOptions = res.data.map(db => ({
|
|
|
|
|
|
label: `${db.name} (${db.type})`,
|
|
|
|
|
|
value: db.id,
|
|
|
|
|
|
type: db.type
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
// If no selection or invalid selection, select first
|
|
|
|
|
|
if (!state.selectedDbId || !state.dbOptions.find(o => o.value === state.selectedDbId)) {
|
|
|
|
|
|
if (state.dbOptions.length > 0) {
|
|
|
|
|
|
state.selectedDbId = state.dbOptions[0].value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Failed to load databases:', error);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
state.loadingDatabases = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleDbChange = () => {
|
|
|
|
|
|
// Clear current data
|
|
|
|
|
|
graph.clearGraph();
|
|
|
|
|
|
state.searchInput = '';
|
|
|
|
|
|
state.lightragStats = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (isNeo4j.value) {
|
|
|
|
|
|
loadGraphInfo();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// Also load stats for LightRAG
|
|
|
|
|
|
loadLightRAGStats();
|
|
|
|
|
|
}
|
|
|
|
|
|
loadSampleNodes();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const loadLightRAGStats = () => {
|
|
|
|
|
|
unifiedApi.getStats(state.selectedDbId).then(res => {
|
|
|
|
|
|
if(res.success) {
|
|
|
|
|
|
state.lightragStats = res.data;
|
|
|
|
|
|
}
|
|
|
|
|
|
}).catch(e => console.error(e));
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-09-06 21:30:49 +08:00
|
|
|
|
const loadGraphInfo = () => {
|
|
|
|
|
|
state.loadingGraphInfo = true
|
2025-07-22 17:29:38 +08:00
|
|
|
|
neo4jApi.getInfo()
|
2024-09-06 12:54:17 +08:00
|
|
|
|
.then(data => {
|
|
|
|
|
|
console.log(data)
|
2025-07-22 17:29:38 +08:00
|
|
|
|
graphInfo.value = data.data
|
2024-09-06 21:30:49 +08:00
|
|
|
|
state.loadingGraphInfo = false
|
2024-09-06 12:54:17 +08:00
|
|
|
|
})
|
|
|
|
|
|
.catch(error => {
|
|
|
|
|
|
console.error(error)
|
2025-05-02 23:56:59 +08:00
|
|
|
|
message.error(error.message || '加载图数据库信息失败')
|
2024-09-06 21:30:49 +08:00
|
|
|
|
state.loadingGraphInfo = false
|
2024-09-06 12:54:17 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
2024-07-17 18:52:20 +08:00
|
|
|
|
|
2024-07-24 18:32:14 +08:00
|
|
|
|
const addDocumentByFile = () => {
|
2025-08-24 16:51:23 +08:00
|
|
|
|
state.processing = true
|
2024-07-24 18:32:14 +08:00
|
|
|
|
const files = fileList.value.filter(file => file.status === 'done').map(file => file.response.file_path)
|
2025-07-22 17:29:38 +08:00
|
|
|
|
neo4jApi.addEntities(files[0])
|
2025-05-02 23:56:59 +08:00
|
|
|
|
.then((data) => {
|
|
|
|
|
|
if (data.status === 'success') {
|
|
|
|
|
|
message.success(data.message);
|
|
|
|
|
|
state.showModal = false;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
throw new Error(data.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
|
console.error(error)
|
|
|
|
|
|
message.error(error.message || '添加文件失败');
|
|
|
|
|
|
})
|
2025-08-24 16:51:23 +08:00
|
|
|
|
.finally(() => state.processing = false)
|
2024-07-24 18:32:14 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-09-06 12:54:17 +08:00
|
|
|
|
const loadSampleNodes = () => {
|
2025-12-15 23:25:56 +08:00
|
|
|
|
graph.fetching = true
|
|
|
|
|
|
|
|
|
|
|
|
unifiedApi.getSubgraph({
|
|
|
|
|
|
db_id: state.selectedDbId,
|
|
|
|
|
|
node_label: '*',
|
|
|
|
|
|
max_nodes: sampleNodeCount.value
|
|
|
|
|
|
})
|
2024-09-06 12:54:17 +08:00
|
|
|
|
.then((data) => {
|
2025-12-15 23:25:56 +08:00
|
|
|
|
// Normalize data structure if needed
|
|
|
|
|
|
const result = data.data;
|
|
|
|
|
|
graph.updateGraphData(result.nodes, result.edges);
|
|
|
|
|
|
console.log(graph.graphData)
|
2024-09-06 12:54:17 +08:00
|
|
|
|
})
|
|
|
|
|
|
.catch((error) => {
|
2025-05-02 23:56:59 +08:00
|
|
|
|
console.error(error)
|
|
|
|
|
|
message.error(error.message || '加载节点失败');
|
2024-09-06 12:54:17 +08:00
|
|
|
|
})
|
2025-12-15 23:25:56 +08:00
|
|
|
|
.finally(() => graph.fetching = false)
|
2024-09-06 12:54:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-24 18:32:14 +08:00
|
|
|
|
const onSearch = () => {
|
2025-02-28 14:14:00 +08:00
|
|
|
|
if (state.searchLoading) {
|
|
|
|
|
|
message.error('请稍后再试')
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-15 23:25:56 +08:00
|
|
|
|
if (isNeo4j.value && graphInfo?.value?.embed_model_name !== cur_embed_model.value) {
|
2025-09-03 16:06:56 +08:00
|
|
|
|
// 可选:提示模型不一致
|
2025-02-28 14:14:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-15 23:25:56 +08:00
|
|
|
|
if (!state.searchInput && isNeo4j.value) {
|
2024-07-24 18:32:14 +08:00
|
|
|
|
message.error('请输入要查询的实体')
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
state.searchLoading = true
|
2025-12-15 23:25:56 +08:00
|
|
|
|
|
|
|
|
|
|
unifiedApi.getSubgraph({
|
|
|
|
|
|
db_id: state.selectedDbId,
|
|
|
|
|
|
node_label: state.searchInput || '*',
|
|
|
|
|
|
max_nodes: sampleNodeCount.value
|
|
|
|
|
|
})
|
2024-07-24 18:32:14 +08:00
|
|
|
|
.then((data) => {
|
2025-12-15 23:25:56 +08:00
|
|
|
|
const result = data.data;
|
|
|
|
|
|
if (!result || !result.nodes || !result.edges) {
|
2024-09-14 02:46:44 +08:00
|
|
|
|
throw new Error('返回数据格式不正确');
|
|
|
|
|
|
}
|
2025-12-15 23:25:56 +08:00
|
|
|
|
graph.updateGraphData(result.nodes, result.edges);
|
|
|
|
|
|
if (graph.graphData.nodes.length === 0) {
|
2024-09-09 17:07:03 +08:00
|
|
|
|
message.info('未找到相关实体')
|
|
|
|
|
|
}
|
2024-07-24 18:32:14 +08:00
|
|
|
|
console.log(data)
|
2025-12-15 23:25:56 +08:00
|
|
|
|
console.log(graph.graphData)
|
2024-07-24 18:32:14 +08:00
|
|
|
|
})
|
|
|
|
|
|
.catch((error) => {
|
2024-09-14 02:46:44 +08:00
|
|
|
|
console.error('查询错误:', error);
|
2025-05-02 23:56:59 +08:00
|
|
|
|
message.error(`查询出错:${error.message || '未知错误'}`);
|
2024-07-24 18:32:14 +08:00
|
|
|
|
})
|
|
|
|
|
|
.finally(() => state.searchLoading = false)
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-12-15 23:25:56 +08:00
|
|
|
|
onMounted(async () => {
|
|
|
|
|
|
await loadDatabases();
|
|
|
|
|
|
loadGraphInfo(); // Load default (Neo4j) info
|
2024-09-06 12:54:17 +08:00
|
|
|
|
loadSampleNodes();
|
2024-07-17 18:52:20 +08:00
|
|
|
|
});
|
2024-07-24 18:32:14 +08:00
|
|
|
|
|
|
|
|
|
|
const handleFileUpload = (event) => {
|
|
|
|
|
|
console.log(event)
|
|
|
|
|
|
console.log(fileList.value)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleDrop = (event) => {
|
|
|
|
|
|
console.log(event)
|
|
|
|
|
|
console.log(fileList.value)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-14 02:46:44 +08:00
|
|
|
|
const graphStatusClass = computed(() => {
|
|
|
|
|
|
if (state.loadingGraphInfo) return 'loading';
|
|
|
|
|
|
return graphInfo.value?.status === 'open' ? 'open' : 'closed';
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const graphStatusText = computed(() => {
|
|
|
|
|
|
if (state.loadingGraphInfo) return '加载中';
|
|
|
|
|
|
return graphInfo.value?.status === 'open' ? '已连接' : '已关闭';
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-02-28 14:14:00 +08:00
|
|
|
|
|
2025-03-08 22:49:22 +08:00
|
|
|
|
// 为未索引节点添加索引
|
|
|
|
|
|
const indexNodes = () => {
|
|
|
|
|
|
// 判断 embed_model_name 是否相同
|
|
|
|
|
|
if (!modelMatched.value) {
|
|
|
|
|
|
message.error(`向量模型不匹配,无法添加索引,当前向量模型为 ${cur_embed_model.value},图数据库向量模型为 ${graphInfo.value?.embed_model_name}`)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-24 16:51:23 +08:00
|
|
|
|
if (state.processing) {
|
2025-03-08 22:49:22 +08:00
|
|
|
|
message.error('后台正在处理,请稍后再试')
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
state.indexing = true;
|
2025-07-22 17:29:38 +08:00
|
|
|
|
neo4jApi.indexEntities('neo4j')
|
2025-05-02 23:56:59 +08:00
|
|
|
|
.then(data => {
|
|
|
|
|
|
message.success(data.message || '索引添加成功');
|
|
|
|
|
|
// 刷新图谱信息
|
|
|
|
|
|
loadGraphInfo();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch(error => {
|
|
|
|
|
|
console.error(error);
|
|
|
|
|
|
message.error(error.message || '添加索引失败');
|
|
|
|
|
|
})
|
|
|
|
|
|
.finally(() => {
|
|
|
|
|
|
state.indexing = false;
|
|
|
|
|
|
});
|
2025-03-08 22:49:22 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-11-18 21:21:20 +08:00
|
|
|
|
const exportGraphData = () => {
|
|
|
|
|
|
const dataStr = JSON.stringify({
|
2025-12-15 23:25:56 +08:00
|
|
|
|
nodes: graph.graphData.nodes,
|
|
|
|
|
|
edges: graph.graphData.edges,
|
|
|
|
|
|
graphInfo: isNeo4j.value ? graphInfo.value : state.lightragStats,
|
|
|
|
|
|
source: state.selectedDbId,
|
2025-11-18 21:21:20 +08:00
|
|
|
|
exportTime: new Date().toISOString()
|
|
|
|
|
|
}, null, 2);
|
|
|
|
|
|
|
|
|
|
|
|
const dataBlob = new Blob([dataStr], { type: 'application/json' });
|
|
|
|
|
|
const url = URL.createObjectURL(dataBlob);
|
|
|
|
|
|
const link = document.createElement('a');
|
|
|
|
|
|
link.href = url;
|
2025-12-15 23:25:56 +08:00
|
|
|
|
link.download = `graph-data-${state.selectedDbId}-${new Date().toISOString().slice(0, 10)}.json`;
|
2025-11-18 21:21:20 +08:00
|
|
|
|
document.body.appendChild(link);
|
|
|
|
|
|
link.click();
|
|
|
|
|
|
document.body.removeChild(link);
|
|
|
|
|
|
URL.revokeObjectURL(url);
|
|
|
|
|
|
|
|
|
|
|
|
message.success('图谱数据已导出');
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-11-23 01:39:44 +08:00
|
|
|
|
const getAuthHeaders = () => {
|
|
|
|
|
|
const userStore = useUserStore();
|
|
|
|
|
|
return userStore.getAuthHeaders();
|
2025-11-18 21:21:20 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-07-23 19:21:45 +08:00
|
|
|
|
const openLink = (url) => {
|
|
|
|
|
|
window.open(url, '_blank')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-15 23:25:56 +08:00
|
|
|
|
const getDatabaseName = () => {
|
|
|
|
|
|
const selectedDb = state.dbOptions.find(db => db.value === state.selectedDbId);
|
|
|
|
|
|
return selectedDb ? selectedDb.label : state.selectedDbId;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-07-17 18:52:20 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
2024-07-24 18:32:14 +08:00
|
|
|
|
<style lang="less" scoped>
|
2025-09-03 03:00:25 +08:00
|
|
|
|
@graph-header-height: 55px;
|
|
|
|
|
|
|
2024-09-06 12:54:17 +08:00
|
|
|
|
.graph-container {
|
2024-09-14 02:46:44 +08:00
|
|
|
|
padding: 0;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
background-color: var(--gray-0);
|
2025-09-03 03:00:25 +08:00
|
|
|
|
|
|
|
|
|
|
.header-container {
|
|
|
|
|
|
height: @graph-header-height;
|
|
|
|
|
|
}
|
2024-09-14 02:46:44 +08:00
|
|
|
|
}
|
2024-09-06 12:54:17 +08:00
|
|
|
|
|
2025-12-15 23:25:56 +08:00
|
|
|
|
.db-selector {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
margin-right: 20px;
|
|
|
|
|
|
|
|
|
|
|
|
.label {
|
|
|
|
|
|
margin-right: 8px;
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
color: var(--color-text-secondary);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-14 02:46:44 +08:00
|
|
|
|
.status-wrapper {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
margin-right: 16px;
|
|
|
|
|
|
font-size: 14px;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
color: var(--color-text-secondary);
|
2024-09-14 02:46:44 +08:00
|
|
|
|
}
|
2024-09-06 12:54:17 +08:00
|
|
|
|
|
2025-08-24 16:51:23 +08:00
|
|
|
|
.status-text {
|
|
|
|
|
|
margin-left: 8px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-14 02:46:44 +08:00
|
|
|
|
.status-indicator {
|
|
|
|
|
|
width: 12px;
|
|
|
|
|
|
height: 12px;
|
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
|
display: inline-block;
|
|
|
|
|
|
|
|
|
|
|
|
&.loading {
|
2025-11-25 22:34:44 +08:00
|
|
|
|
background-color: var(--color-warning-500);
|
2024-09-14 02:46:44 +08:00
|
|
|
|
animation: pulse 1.5s infinite ease-in-out;
|
2024-09-06 12:54:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-14 02:46:44 +08:00
|
|
|
|
&.open {
|
2025-11-25 22:34:44 +08:00
|
|
|
|
background-color: var(--color-success-500);
|
2024-09-06 12:54:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-14 02:46:44 +08:00
|
|
|
|
&.closed {
|
2025-11-25 22:34:44 +08:00
|
|
|
|
background-color: var(--color-error-500);
|
2024-09-06 12:54:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-14 02:46:44 +08:00
|
|
|
|
@keyframes pulse {
|
|
|
|
|
|
0% {
|
|
|
|
|
|
transform: scale(0.8);
|
|
|
|
|
|
opacity: 0.5;
|
|
|
|
|
|
}
|
|
|
|
|
|
50% {
|
|
|
|
|
|
transform: scale(1.2);
|
|
|
|
|
|
opacity: 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
100% {
|
|
|
|
|
|
transform: scale(0.8);
|
|
|
|
|
|
opacity: 0.5;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-09-06 12:54:17 +08:00
|
|
|
|
|
2025-09-03 03:00:25 +08:00
|
|
|
|
|
|
|
|
|
|
.upload {
|
|
|
|
|
|
margin-bottom: 20px;
|
|
|
|
|
|
|
|
|
|
|
|
.upload-dragger {
|
|
|
|
|
|
margin: 0px;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.container-outter {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: calc(100vh - @graph-header-height);
|
|
|
|
|
|
overflow: hidden;
|
2025-10-07 00:15:14 +08:00
|
|
|
|
background: var(--gray-10);
|
2025-09-03 03:00:25 +08:00
|
|
|
|
|
|
|
|
|
|
.actions,
|
|
|
|
|
|
.footer {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
margin: 20px 0;
|
|
|
|
|
|
padding: 0 24px;
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
}
|
2025-11-23 01:39:44 +08:00
|
|
|
|
|
|
|
|
|
|
.tags {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
gap: 8px;
|
|
|
|
|
|
}
|
2025-09-03 03:00:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-24 18:32:14 +08:00
|
|
|
|
.actions {
|
2025-09-03 03:00:25 +08:00
|
|
|
|
top: 0;
|
2024-07-24 18:32:14 +08:00
|
|
|
|
|
2024-09-06 21:30:49 +08:00
|
|
|
|
.actions-left, .actions-right {
|
2024-09-06 12:54:17 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 10px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-03 03:00:25 +08:00
|
|
|
|
:deep(.ant-input) {
|
|
|
|
|
|
padding: 2px 10px;
|
2024-07-24 18:32:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
button {
|
2025-09-03 03:00:25 +08:00
|
|
|
|
height: 37px;
|
2024-07-24 18:32:14 +08:00
|
|
|
|
box-shadow: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-15 23:25:56 +08:00
|
|
|
|
</style>
|