Merge branch 'main' into select-datastore-in-api-server
This commit is contained in:
@@ -101,7 +101,6 @@ def estimate_tokens(text: str) -> int:
|
||||
|
||||
return int(tokens)
|
||||
|
||||
|
||||
def get_default_host(binding_type: str) -> str:
|
||||
default_hosts = {
|
||||
"ollama": os.getenv("LLM_BINDING_HOST", "http://localhost:11434"),
|
||||
@@ -249,6 +248,10 @@ def display_splash_screen(args: argparse.Namespace) -> None:
|
||||
ASCIIColors.yellow(f"{protocol}://localhost:{args.port}/docs")
|
||||
ASCIIColors.white(" └─ Alternative Documentation (local): ", end="")
|
||||
ASCIIColors.yellow(f"{protocol}://localhost:{args.port}/redoc")
|
||||
ASCIIColors.white(" ├─ WebUI (local): ", end="")
|
||||
ASCIIColors.yellow(f"{protocol}://localhost:{args.port}/webui")
|
||||
ASCIIColors.white(" ├─ Graph Viewer (local): ", end="")
|
||||
ASCIIColors.yellow(f"{protocol}://localhost:{args.port}/graph-viewer")
|
||||
|
||||
ASCIIColors.yellow("\n📝 Note:")
|
||||
ASCIIColors.white(""" Since the server is running on 0.0.0.0:
|
||||
@@ -1614,8 +1617,8 @@ def create_app(args):
|
||||
|
||||
# query all graph
|
||||
@app.get("/graphs")
|
||||
async def get_graphs(label: str):
|
||||
return await rag.get_graps(nodel_label=label, max_depth=100)
|
||||
async def get_knowledge_graph(label: str):
|
||||
return await rag.get_knowledge_graph(nodel_label=label, max_depth=100)
|
||||
|
||||
# Add Ollama API routes
|
||||
ollama_api = OllamaAPI(rag, top_k=args.top_k)
|
||||
@@ -1653,19 +1656,18 @@ def create_app(args):
|
||||
},
|
||||
}
|
||||
|
||||
# webui mount /webui/index.html
|
||||
# app.mount(
|
||||
# "/webui",
|
||||
# StaticFiles(
|
||||
# directory=Path(__file__).resolve().parent / "webui" / "static", html=True
|
||||
# ),
|
||||
# name="webui_static",
|
||||
# )
|
||||
# Webui mount webui/index.html
|
||||
webui_dir = Path(__file__).parent / "webui"
|
||||
app.mount(
|
||||
"/graph-viewer",
|
||||
StaticFiles(directory=webui_dir, html=True),
|
||||
name="webui",
|
||||
)
|
||||
|
||||
# Serve the static files
|
||||
static_dir = Path(__file__).parent / "static"
|
||||
static_dir.mkdir(exist_ok=True)
|
||||
app.mount("/", StaticFiles(directory=static_dir, html=True), name="static")
|
||||
app.mount("/webui", StaticFiles(directory=static_dir, html=True), name="static")
|
||||
|
||||
return app
|
||||
|
||||
|
@@ -98,7 +98,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/js/api.js"></script>
|
||||
<script src="./js/api.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
1
lightrag/api/webui/assets/index-BAeLPZpd.css
Normal file
1
lightrag/api/webui/assets/index-BAeLPZpd.css
Normal file
File diff suppressed because one or more lines are too long
967
lightrag/api/webui/assets/index-CF-pcoIl.js
Normal file
967
lightrag/api/webui/assets/index-CF-pcoIl.js
Normal file
File diff suppressed because one or more lines are too long
14
lightrag/api/webui/index.html
Normal file
14
lightrag/api/webui/index.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="./vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Lightrag Graph Viewer</title>
|
||||
<script type="module" crossorigin src="./assets/index-CF-pcoIl.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="./assets/index-BAeLPZpd.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
1
lightrag/api/webui/vite.svg
Normal file
1
lightrag/api/webui/vite.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
After Width: | Height: | Size: 1.5 KiB |
@@ -1,86 +0,0 @@
|
||||
/* css/lightrag.css */
|
||||
|
||||
/*Modal box style*/
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background-color: var(--surface);
|
||||
padding: 1.5rem;
|
||||
border-radius: 8px;
|
||||
width: 80%;
|
||||
max-width: 1200px;
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.btn-close {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 1.5rem;
|
||||
cursor: pointer;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.btn-close:hover {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
/* graph style */
|
||||
.node {
|
||||
cursor: pointer;
|
||||
fill: var(--primary);
|
||||
stroke: var(--surface);
|
||||
stroke-width: 2px;
|
||||
}
|
||||
|
||||
.node:hover {
|
||||
fill: var(--secondary);
|
||||
}
|
||||
|
||||
.link {
|
||||
stroke: var(--text-secondary);
|
||||
stroke-width: 2px;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 12px;
|
||||
fill: var(--text-primary);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* edge style */
|
||||
.link {
|
||||
stroke: #999;
|
||||
stroke-width: 2px;
|
||||
stroke-opacity: 0.8;
|
||||
}
|
||||
|
||||
/* Arrow color matches edge color */
|
||||
#arrow path {
|
||||
fill: #999 !important;
|
||||
}
|
@@ -1,385 +0,0 @@
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
||||
line-height: 1.6;
|
||||
background-color: var(--background);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
/* main container */
|
||||
.app-container {
|
||||
max-width: 1600px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
display: grid;
|
||||
grid-template-columns: 240px 1fr;
|
||||
gap: 2rem;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
/* Navigation sidebar */
|
||||
.nav-panel {
|
||||
position: sticky;
|
||||
top: 2rem;
|
||||
height: fit-content;
|
||||
background: var(--surface);
|
||||
border-radius: 12px;
|
||||
padding: 1.5rem;
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.nav-title {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
color: var(--primary);
|
||||
padding-bottom: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
/* Main content area */
|
||||
.main-content {
|
||||
display: grid;
|
||||
gap: 1.5rem;
|
||||
align-content: start;
|
||||
}
|
||||
|
||||
/* Card based module */
|
||||
.card {
|
||||
background: var(--surface);
|
||||
border-radius: 12px;
|
||||
padding: 1.5rem;
|
||||
box-shadow: var(--shadow);
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 1rem;
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
/* File upload area */
|
||||
.file-dropzone {
|
||||
border: 2px dashed var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
transition: all 0.3s ease;
|
||||
background: rgba(241, 245, 249, 0.5);
|
||||
}
|
||||
|
||||
.file-dropzone.active {
|
||||
border-color: var(--primary);
|
||||
background: rgba(79, 70, 229, 0.05);
|
||||
}
|
||||
|
||||
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.75rem 1.5rem;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--primary);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: #4338CA;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: var(--secondary);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background: #059669;
|
||||
}
|
||||
|
||||
.input-field {
|
||||
width: 100%;
|
||||
padding: 0.875rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
font-size: 1rem;
|
||||
transition: border-color 0.2s ease;
|
||||
}
|
||||
|
||||
.input-field:focus {
|
||||
outline: none;
|
||||
border-color: var(--primary);
|
||||
box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
|
||||
}
|
||||
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.app-container {
|
||||
grid-template-columns: 1fr;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.nav-panel {
|
||||
position: static;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.btn.active {
|
||||
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
transform: translateY(1px);
|
||||
}
|
||||
}
|
||||
|
||||
.toast {
|
||||
position: fixed;
|
||||
bottom: 20px;
|
||||
right: 20px;
|
||||
padding: 12px 24px;
|
||||
border-radius: 8px;
|
||||
background: var(--surface);
|
||||
box-shadow: var(--shadow);
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.toast.success {
|
||||
background: var(--secondary);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.toast.error {
|
||||
background: #EF4444;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.loading {
|
||||
position: relative;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.loading::after {
|
||||
content: "···";
|
||||
animation: loading 1s infinite;
|
||||
}
|
||||
|
||||
@keyframes loading {
|
||||
0% {
|
||||
content: "·";
|
||||
}
|
||||
33% {
|
||||
content: "··";
|
||||
}
|
||||
66% {
|
||||
content: "···";
|
||||
}
|
||||
}
|
||||
|
||||
.text-upload-form {
|
||||
display: grid;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 0.5rem;
|
||||
color: var(--text-primary);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.status-indicator {
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 6px;
|
||||
font-size: 0.9em;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.status-indicator.success {
|
||||
background: var(--secondary);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.status-indicator.error {
|
||||
background: #ef4444;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.status-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
gap: 1.5rem;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.status-card {
|
||||
background: var(--surface);
|
||||
border-radius: 12px;
|
||||
padding: 1.5rem;
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.status-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.status-icon {
|
||||
font-size: 1.5rem;
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
.progress-container {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.progress-labels {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-top: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.config-list {
|
||||
display: grid;
|
||||
grid-template-columns: max-content 1fr;
|
||||
gap: 0.75rem 1.5rem;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.config-list dt {
|
||||
font-weight: 500;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.config-list dd {
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.directory-list {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.directory-item {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.directory-label {
|
||||
font-weight: 500;
|
||||
color: var(--text-secondary);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.directory-path {
|
||||
color: var(--text-primary);
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: inline-block;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 20px;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.health-status .status-badge {
|
||||
background: rgba(16, 185, 129, 0.1);
|
||||
color: #10B981;
|
||||
border: 1px solid rgba(16, 185, 129, 0.2);
|
||||
}
|
||||
|
||||
.status-badge.loading {
|
||||
background: rgba(79, 70, 229, 0.1);
|
||||
color: var(--primary);
|
||||
}
|
||||
|
||||
.status-badge.error {
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
color: #EF4444;
|
||||
}
|
||||
|
||||
.label-container {
|
||||
max-height: 60vh;
|
||||
overflow-y: auto;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.label-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0.75rem;
|
||||
margin-bottom: 0.5rem;
|
||||
background: var(--surface);
|
||||
border-radius: 6px;
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.label-item:hover {
|
||||
transform: translateX(4px);
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
.label-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.toast {
|
||||
position: fixed;
|
||||
bottom: 2rem;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
padding: 0.75rem 1.5rem;
|
||||
border-radius: 999px;
|
||||
font-size: 0.9rem;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.toast-success {
|
||||
background: var(--secondary);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.toast-info {
|
||||
background: var(--primary);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.toast-error {
|
||||
background: #EF4444;
|
||||
color: white;
|
||||
}
|
@@ -1,291 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>LightRAG</title>
|
||||
<style>
|
||||
:root {
|
||||
--primary: #4F46E5;
|
||||
--secondary: #10B981;
|
||||
--background: #F8FAFC;
|
||||
--surface: #FFFFFF;
|
||||
--text-primary: #1E293B;
|
||||
--text-secondary: #64748B;
|
||||
--border: #E2E8F0;
|
||||
--shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
</style>
|
||||
<link rel="stylesheet" type="text/css" href="css/lightrag.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/graph.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="app-container">
|
||||
<nav class="nav-panel">
|
||||
<h2 class="nav-title">LightRAG</h2>
|
||||
<div class="nav-menu">
|
||||
<button class="btn btn-primary" style="width: 100%; margin-bottom: 1rem;"
|
||||
onclick="showSection('documents')">
|
||||
📁 DOC MANAGE
|
||||
</button>
|
||||
<button class="btn btn-primary" style="width: 100%; margin-bottom: 1rem;"
|
||||
onclick="showSection('text-upload')">
|
||||
📝 TEXT UPLOAD
|
||||
</button>
|
||||
|
||||
<button class="btn btn-primary" style="width: 100%; margin-bottom: 1rem;" onclick="showSection('query')">
|
||||
🔍 GRAPH SEARCH
|
||||
</button>
|
||||
<button class="btn btn-primary" style="width: 100%; margin-bottom: 1rem;"
|
||||
onclick="showSection('label-management'); loadLabels()">
|
||||
🏷️ GRAPH MANAGE
|
||||
</button>
|
||||
<button class="btn btn-secondary" style="width: 100%;" onclick="showSection('status')">
|
||||
📊 SYSTEM STATUS
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="main-content">
|
||||
<section id="documents" class="card">
|
||||
<h3 class="card-title">DOC MANAGE</h3>
|
||||
<div class="file-dropzone" id="dropzone">
|
||||
<input type="file" id="fileInput" hidden multiple>
|
||||
<p>Drap file</p>
|
||||
<button class="btn btn-primary" onclick="document.getElementById('fileInput').click()">
|
||||
📤 select file
|
||||
</button>
|
||||
<div class="file-list" style="margin-top: 1rem;"></div>
|
||||
<div class="status-indicator" id="fileUploadStatus"></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="text-upload" class="card" style="display: none;">
|
||||
<h3 class="card-title">TEXT UPLOAD</h3>
|
||||
<div class="text-upload-form">
|
||||
<div class="form-group">
|
||||
<label for="textDescription">Title(optional)</label>
|
||||
<input
|
||||
type="text"
|
||||
id="textDescription"
|
||||
class="input-field"
|
||||
placeholder="Please enter a text title..."
|
||||
>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="textContent">TEXT CONTENT</label>
|
||||
<textarea
|
||||
id="textContent"
|
||||
class="input-field"
|
||||
placeholder="lease enter a text content..."
|
||||
rows="8"
|
||||
required
|
||||
></textarea>
|
||||
</div>
|
||||
<div class="action-bar">
|
||||
<button class="btn btn-primary" onclick="handleTextUpload()">
|
||||
📤 submit
|
||||
</button>
|
||||
<div class="status-indicator" id="textUploadStatus"></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="label-management" class="card" style="display: none;">
|
||||
<h3 class="card-title">GRAPH MANAGE(neo4j)</h3>
|
||||
<div class="action-bar" style="margin-bottom: 1rem;">
|
||||
<button class="btn btn-secondary" onclick="refreshLabels()">
|
||||
🔄 refresh
|
||||
</button>
|
||||
</div>
|
||||
<div id="label-list" class="label-container">
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- search -->
|
||||
<section id="query" class="card" style="display: none;">
|
||||
<h3 class="card-title">SEARCH API</h3>
|
||||
<select class="input-field" style="margin-bottom: 1rem;">
|
||||
<option value="local">local search</option>
|
||||
<option value="global">global search</option>
|
||||
<option value="native">native search</option>
|
||||
<option value="hybrid">hybrid search</option>
|
||||
<option value="mix">mix search</option>
|
||||
</select>
|
||||
<textarea
|
||||
class="input-field"
|
||||
placeholder="enter your content..."
|
||||
style="height: 120px; resize: vertical;"
|
||||
></textarea>
|
||||
<div style="margin-top: 1rem; display: flex; gap: 0.5rem;">
|
||||
<button class="btn btn-primary">🔍 searching</button>
|
||||
<label class="btn btn-secondary">
|
||||
<input type="checkbox" style="margin-right: 0.5rem;">stream modal
|
||||
</label>
|
||||
</div>
|
||||
<div class="results"
|
||||
style="margin-top: 1rem; padding: 1rem; border: 1px solid var(--border); border-radius: 8px;"></div>
|
||||
</section>
|
||||
|
||||
|
||||
<section id="status" class="card" style="display: none;">
|
||||
<h3 class="card-title">System Status</h3>
|
||||
<div class="status-grid">
|
||||
<div class="status-card health-status">
|
||||
<div class="status-header">
|
||||
<i class="status-icon fas fa-heartbeat"></i>
|
||||
<h4>HEATH STATUS</h4>
|
||||
</div>
|
||||
<div class="status-badge" id="healthStatus">checking...</div>
|
||||
</div>
|
||||
|
||||
<!-- 存储状态 -->
|
||||
<div class="status-card storage-status">
|
||||
<div class="status-header">
|
||||
<i class="status-icon fas fa-database"></i>
|
||||
<h4>Storage status</h4>
|
||||
</div>
|
||||
<div class="progress-container">
|
||||
<progress value="0" max="100" id="storageProgress"></progress>
|
||||
<div class="progress-labels">
|
||||
<span id="indexedFiles">Indexed files:0</span>
|
||||
<span id="storageUsage">Use ratio:0%</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="status-card model-config">
|
||||
<div class="status-header">
|
||||
<i class="status-icon fas fa-brain"></i>
|
||||
<h4>LLM configuration</h4>
|
||||
</div>
|
||||
<dl class="config-list">
|
||||
<dt>LLM MODEL</dt>
|
||||
<dd id="llmModel">Loading...</dd>
|
||||
|
||||
<dt>Embedded model</dt>
|
||||
<dd id="embedModel">Loading...</dd>
|
||||
|
||||
<dt>Max token</dt>
|
||||
<dd id="maxTokens">0</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<div class="status-card directory-info">
|
||||
<div class="status-header">
|
||||
<i class="status-icon fas fa-folder-open"></i>
|
||||
<h4>Catalog information</h4>
|
||||
</div>
|
||||
<div class="directory-list">
|
||||
<div class="directory-item">
|
||||
<span class="directory-label">Work directory:</span>
|
||||
<span class="directory-path" id="workingDir"></span>
|
||||
</div>
|
||||
<div class="directory-item">
|
||||
<span class="directory-label">Input directory:</span>
|
||||
<span class="directory-path" id="inputDir"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="status-card directory-info">
|
||||
<div class="status-header">
|
||||
<i class="status-icon fas fa-folder-open"></i>
|
||||
<h4>Store information</h4>
|
||||
</div>
|
||||
<div class="directory-list">
|
||||
<div class="directory-item">
|
||||
<span class="directory-label">kv_storage:</span>
|
||||
<span class="directory-path" id="kv_storage"></span>
|
||||
</div>
|
||||
<div class="directory-item">
|
||||
<span class="directory-label">doc_status_storage:</span>
|
||||
<span class="directory-path" id="doc_status_storage"></span>
|
||||
</div>
|
||||
<div class="directory-item">
|
||||
<span class="directory-label">graph_storage:</span>
|
||||
<span class="directory-path" id="graph_storage"></span>
|
||||
</div>
|
||||
<div class="directory-item">
|
||||
<span class="directory-label">vector_storage:</span>
|
||||
<span class="directory-path" id="vector_storage"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
<div id="graph-modal" class="modal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h3 id="graph-title">GRAPH MANAGE</h3>
|
||||
<button class="btn btn-close" onclick="closeGraphModal()">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div id="graph-container">
|
||||
<svg id="graph-svg" width="100%" height="600px">
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-secondary" onclick="closeGraphModal()">SHUT DOWN</button>
|
||||
</div>
|
||||
<div class="resize-handle"></div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
const dropzone = document.getElementById('dropzone');
|
||||
|
||||
dropzone.addEventListener('dragover', (e) => {
|
||||
e.preventDefault();
|
||||
dropzone.classList.add('active');
|
||||
});
|
||||
|
||||
dropzone.addEventListener('dragleave', () => {
|
||||
dropzone.classList.remove('active');
|
||||
});
|
||||
|
||||
dropzone.addEventListener('drop', (e) => {
|
||||
e.preventDefault();
|
||||
dropzone.classList.remove('active');
|
||||
const files = e.dataTransfer.files;
|
||||
handleFiles(files);
|
||||
});
|
||||
|
||||
function handleFiles(files) {
|
||||
console.log('selected file:', files);
|
||||
}
|
||||
|
||||
function showSection(sectionId) {
|
||||
// Hide all content blocks
|
||||
const sections = document.querySelectorAll('.main-content .card');
|
||||
sections.forEach(section => {
|
||||
section.style.display = 'none';
|
||||
});
|
||||
|
||||
// Display target block
|
||||
const targetSection = document.getElementById(sectionId);
|
||||
if (targetSection) {
|
||||
targetSection.style.display = 'block';
|
||||
}
|
||||
|
||||
// Update button activation status (optional)
|
||||
const buttons = document.querySelectorAll('.nav-menu button');
|
||||
buttons.forEach(button => {
|
||||
button.classList.remove('active');
|
||||
});
|
||||
event.target.classList.add('active');
|
||||
}
|
||||
|
||||
// Initialize the display document management module
|
||||
showSection('documents');
|
||||
</script>
|
||||
<script src="js/lightrag.js"></script>
|
||||
<script src="js/graph.js"></script>
|
||||
<script src="https://d3js.org/d3.v7.min.js"></script>
|
||||
</body>
|
||||
</html>
|
@@ -1,500 +0,0 @@
|
||||
// lightrag.js
|
||||
// init
|
||||
function initializeApp() {
|
||||
setupFileUpload();
|
||||
setupQueryHandler();
|
||||
setupSectionObserver();
|
||||
updateFileList();
|
||||
// textarea count
|
||||
const textArea = document.getElementById('textContent');
|
||||
if (textArea) {
|
||||
const charCount = document.createElement('div');
|
||||
charCount.className = 'char-count';
|
||||
textArea.parentNode.appendChild(charCount);
|
||||
|
||||
textArea.addEventListener('input', () => {
|
||||
const count = textArea.value.length;
|
||||
charCount.textContent = `input ${count} character`;
|
||||
charCount.style.color = count > 10000 ? '#ef4444' : 'var (--text-secondary)'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// api request
|
||||
async function apiRequest(endpoint, method = 'GET', body = null) {
|
||||
const options = {
|
||||
method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
|
||||
if (body) {
|
||||
options.body = JSON.stringify(body);
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${endpoint}`, options);
|
||||
if (!response.ok) {
|
||||
throw new Error(`request failed: ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
} catch (error) {
|
||||
console.error('API REQUEST ERROR:', error);
|
||||
showToast(error.message, 'error');
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleTextUpload() {
|
||||
const description = document.getElementById('textDescription').value;
|
||||
const content = document.getElementById('textContent').value.trim();
|
||||
const statusDiv = document.getElementById('textUploadStatus');
|
||||
|
||||
// clear status tip
|
||||
statusDiv.className = 'status-indicator';
|
||||
statusDiv.textContent = '';
|
||||
|
||||
// input valid
|
||||
if (!content) {
|
||||
showStatus('error', 'TEXT CONTENT NOT NULL', statusDiv);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
showStatus('loading', 'UPLOADING...', statusDiv);
|
||||
|
||||
const payload = {
|
||||
text: content,
|
||||
...(description && {description})
|
||||
};
|
||||
|
||||
const response = await fetch(`/documents/text`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.detail || 'UPLOAD FAILED');
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
showStatus('success', `✅ ${result.message} (documents: ${result.document_count})`, statusDiv);
|
||||
|
||||
|
||||
document.getElementById('textContent').value = '';
|
||||
|
||||
// update file list
|
||||
updateFileList();
|
||||
|
||||
} catch (error) {
|
||||
showStatus('error', `❌ ERROR: ${error.message}`, statusDiv);
|
||||
console.error('FILE UPLOAD FAILED:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function showStatus(type, message, container) {
|
||||
container.textContent = message;
|
||||
container.className = `status-indicator ${type}`;
|
||||
|
||||
//auto clear success status
|
||||
if (type === 'success') {
|
||||
setTimeout(() => {
|
||||
container.textContent = '';
|
||||
container.className = 'status-indicator';
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
|
||||
// upload file
|
||||
function setupFileUpload() {
|
||||
const dropzone = document.getElementById('dropzone');
|
||||
const fileInput = document.getElementById('fileInput');
|
||||
|
||||
|
||||
// Drag and drop event handling
|
||||
dropzone.addEventListener('dragover', (e) => {
|
||||
e.preventDefault();
|
||||
dropzone.classList.add('active');
|
||||
});
|
||||
|
||||
dropzone.addEventListener('dragleave', () => {
|
||||
dropzone.classList.remove('active');
|
||||
});
|
||||
|
||||
dropzone.addEventListener('drop', async (e) => {
|
||||
e.preventDefault();
|
||||
dropzone.classList.remove('active');
|
||||
await handleFiles(e.dataTransfer.files);
|
||||
});
|
||||
|
||||
|
||||
fileInput.addEventListener('change', async (e) => {
|
||||
await handleFiles(e.target.files);
|
||||
});
|
||||
}
|
||||
|
||||
async function handleFiles(files) {
|
||||
const formData = new FormData();
|
||||
for (const file of files) {
|
||||
formData.append('file', file);
|
||||
}
|
||||
const statusDiv = document.getElementById('fileUploadStatus');
|
||||
|
||||
|
||||
statusDiv.className = 'status-indicator';
|
||||
statusDiv.textContent = '';
|
||||
try {
|
||||
showStatus('loading', 'UPLOADING...', statusDiv);
|
||||
const response = await fetch(`/documents/upload`, {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
const result = await response.json();
|
||||
showStatus('success', `✅ ${result.message} `, statusDiv);
|
||||
updateFileList();
|
||||
} catch (error) {
|
||||
showToast(error.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function updateFileList() {
|
||||
const fileList = document.querySelector('.file-list');
|
||||
try {
|
||||
const status = await apiRequest('/health');
|
||||
fileList.innerHTML = `
|
||||
<div>INDEXED FILE: ${status.indexed_files_count}</div>
|
||||
`;
|
||||
} catch (error) {
|
||||
fileList.innerHTML = 'UNABLE TO OBTAIN FILE LIST';
|
||||
}
|
||||
}
|
||||
|
||||
// Intelligent retrieval processing
|
||||
function setupQueryHandler() {
|
||||
document.querySelector('#query .btn-primary').addEventListener('click', handleQuery);
|
||||
}
|
||||
|
||||
async function handleQuery() {
|
||||
const queryInput = document.querySelector('#query textarea');
|
||||
const modeSelect = document.querySelector('#query select');
|
||||
const streamCheckbox = document.querySelector('#query input[type="checkbox"]');
|
||||
const resultsDiv = document.querySelector('#query .results');
|
||||
|
||||
const payload = {
|
||||
query: queryInput.value,
|
||||
mode: modeSelect.value,
|
||||
stream: streamCheckbox.checked
|
||||
};
|
||||
|
||||
resultsDiv.innerHTML = '<div class="loading">SEARCHING...</div>';
|
||||
|
||||
try {
|
||||
if (payload.stream) {
|
||||
await handleStreamingQuery(payload, resultsDiv);
|
||||
} else {
|
||||
const result = await apiRequest('/query', 'POST', payload);
|
||||
resultsDiv.innerHTML = `<div class="result">${result.response}</div>`;
|
||||
}
|
||||
} catch (error) {
|
||||
resultsDiv.innerHTML = `<div class="error">SEARCH FAILED: ${error.message}</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
// handle stream api
|
||||
async function handleStreamingQuery(payload, resultsDiv) {
|
||||
try {
|
||||
const response = await fetch(`/query/stream`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
|
||||
|
||||
const contentType = response.headers.get('Content-Type') || '';
|
||||
const validTypes = ['application/x-ndjson', 'application/json'];
|
||||
if (!validTypes.some(t => contentType.includes(t))) {
|
||||
throw new Error(`INVALID CONTENT TYPE: ${contentType}`);
|
||||
}
|
||||
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder('utf-8');
|
||||
let buffer = '';
|
||||
|
||||
resultsDiv.innerHTML = '';
|
||||
|
||||
while (true) {
|
||||
const {done, value} = await reader.read();
|
||||
if (done) break;
|
||||
|
||||
buffer += decoder.decode(value, {stream: true});
|
||||
|
||||
// Split by line break (NDJSON format requirement)
|
||||
let lineEndIndex;
|
||||
while ((lineEndIndex = buffer.indexOf('\n')) >= 0) {
|
||||
const line = buffer.slice(0, lineEndIndex).trim();
|
||||
buffer = buffer.slice(lineEndIndex + 1);
|
||||
|
||||
if (!line) continue;
|
||||
|
||||
try {
|
||||
const data = JSON.parse(line);
|
||||
|
||||
if (data.response) {
|
||||
resultsDiv.innerHTML += data.response;
|
||||
resultsDiv.scrollTop = resultsDiv.scrollHeight;
|
||||
}
|
||||
|
||||
if (data.error) {
|
||||
resultsDiv.innerHTML += `<div class="error">${data.error}</div>`;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('JSON PARSING FAILED:', {
|
||||
error,
|
||||
rawLine: line,
|
||||
bufferRemaining: buffer
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process remaining data
|
||||
if (buffer.trim()) {
|
||||
try {
|
||||
const data = JSON.parse(buffer.trim());
|
||||
if (data.response) {
|
||||
resultsDiv.innerHTML += data.response;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('TAIL DATA PARSING FAILED:', error);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
resultsDiv.innerHTML = `<div class="error">REQUEST FAILED: ${error.message}</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Knowledge Q&A Processing
|
||||
function setupChatHandler() {
|
||||
const sendButton = document.querySelector('#chat button');
|
||||
const chatInput = document.querySelector('#chat input');
|
||||
|
||||
sendButton.addEventListener('click', () => handleChat(chatInput));
|
||||
chatInput.addEventListener('keypress', (e) => {
|
||||
if (e.key === 'Enter') handleChat(chatInput);
|
||||
});
|
||||
}
|
||||
|
||||
async function handleChat(chatInput) {
|
||||
const chatHistory = document.querySelector('#chat .chat-history');
|
||||
|
||||
|
||||
const userMessage = document.createElement('div');
|
||||
userMessage.className = 'message user';
|
||||
userMessage.textContent = chatInput.value;
|
||||
chatHistory.appendChild(userMessage);
|
||||
|
||||
|
||||
const botMessage = document.createElement('div');
|
||||
botMessage.className = 'message bot loading';
|
||||
botMessage.textContent = 'THINKING...';
|
||||
chatHistory.appendChild(botMessage);
|
||||
chatHistory.scrollTop = chatHistory.scrollHeight;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/chat`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({
|
||||
messages: [{role: "user", content: chatInput.value}],
|
||||
stream: true
|
||||
})
|
||||
});
|
||||
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder();
|
||||
botMessage.classList.remove('loading');
|
||||
botMessage.textContent = '';
|
||||
|
||||
while (true) {
|
||||
const {done, value} = await reader.read();
|
||||
if (done) break;
|
||||
|
||||
const chunk = decoder.decode(value);
|
||||
const data = JSON.parse(chunk);
|
||||
botMessage.textContent += data.message?.content || '';
|
||||
chatHistory.scrollTop = chatHistory.scrollHeight;
|
||||
}
|
||||
} catch (error) {
|
||||
botMessage.textContent = `ERROR: ${error.message}`;
|
||||
botMessage.classList.add('error');
|
||||
}
|
||||
|
||||
chatInput.value = '';
|
||||
}
|
||||
|
||||
// system status update
|
||||
async function updateSystemStatus() {
|
||||
const statusElements = {
|
||||
health: document.getElementById('healthStatus'),
|
||||
storageProgress: document.getElementById('storageProgress'),
|
||||
indexedFiles: document.getElementById('indexedFiles'),
|
||||
storageUsage: document.getElementById('storageUsage'),
|
||||
llmModel: document.getElementById('llmModel'),
|
||||
embedModel: document.getElementById('embedModel'),
|
||||
maxTokens: document.getElementById('maxTokens'),
|
||||
workingDir: document.getElementById('workingDir'),
|
||||
inputDir: document.getElementById('inputDir'),
|
||||
kv_storage: document.getElementById("kv_storage"),
|
||||
doc_status_storage: document.getElementById("doc_status_storage"),
|
||||
graph_storage: document.getElementById("graph_storage"),
|
||||
vector_storage: document.getElementById("vector_storage")
|
||||
};
|
||||
|
||||
try {
|
||||
const status = await apiRequest('/health');
|
||||
|
||||
// heath status
|
||||
statusElements.health.className = 'status-badge';
|
||||
statusElements.health.textContent = status.status === 'healthy' ?
|
||||
'✅ Healthy operation in progress' : '⚠️ Service exception';
|
||||
|
||||
// kv status
|
||||
const progressValue = Math.min(Math.round((status.indexed_files_count / 1000) * 100), 100);
|
||||
statusElements.storageProgress.value = progressValue;
|
||||
statusElements.indexedFiles.textContent = `INDEXED FILES:${status.indexed_files_count}`;
|
||||
statusElements.storageUsage.textContent = `USE PERCENT:${progressValue}%`;
|
||||
|
||||
// model state
|
||||
statusElements.llmModel.textContent = `${status.configuration.llm_model} (${status.configuration.llm_binding})`;
|
||||
statusElements.embedModel.textContent = `${status.configuration.embedding_model} (${status.configuration.embedding_binding})`;
|
||||
statusElements.maxTokens.textContent = status.configuration.max_tokens.toLocaleString();
|
||||
|
||||
// dir msg
|
||||
statusElements.workingDir.textContent = status.working_directory;
|
||||
statusElements.inputDir.textContent = status.input_directory;
|
||||
|
||||
// stack msg
|
||||
statusElements.kv_storage.textContent = status.configuration.kv_storage;
|
||||
statusElements.doc_status_storage.textContent = status.configuration.doc_status_storage;
|
||||
statusElements.graph_storage.textContent = status.configuration.graph_storage;
|
||||
statusElements.vector_storage.textContent = status.configuration.vector_storage
|
||||
|
||||
} catch (error) {
|
||||
statusElements.health.className = 'status-badge error';
|
||||
statusElements.health.textContent = '❌GET STATUS FAILED';
|
||||
statusElements.storageProgress.value = 0;
|
||||
statusElements.indexedFiles.textContent = 'INDEXED FILES:GET FAILED';
|
||||
console.error('STATUS UPDATE FAILED:', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Area switching monitoring
|
||||
function setupSectionObserver() {
|
||||
const observer = new MutationObserver(mutations => {
|
||||
mutations.forEach(mutation => {
|
||||
if (mutation.attributeName === 'style') {
|
||||
const isVisible = mutation.target.style.display !== 'none';
|
||||
if (isVisible && mutation.target.id === 'status') {
|
||||
updateSystemStatus();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll('.card').forEach(section => {
|
||||
observer.observe(section, {attributes: true});
|
||||
});
|
||||
}
|
||||
|
||||
// Display prompt information
|
||||
function showToast(message, type = 'info') {
|
||||
const toast = document.createElement('div');
|
||||
toast.className = `toast ${type}`;
|
||||
toast.textContent = message;
|
||||
document.body.appendChild(toast);
|
||||
|
||||
setTimeout(() => {
|
||||
toast.remove();
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
|
||||
// Dynamically load tag list
|
||||
async function loadLabels() {
|
||||
try {
|
||||
const response = await fetch('/graph/label/list');
|
||||
const labels = await response.json();
|
||||
renderLabels(labels);
|
||||
} catch (error) {
|
||||
console.error('DYNAMICALLY LOAD TAG LIST FAILED:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadGraph(label) {
|
||||
try {
|
||||
// render label list
|
||||
openGraphModal(label)
|
||||
} catch (error) {
|
||||
console.error('LOADING LABEL FAILED:', error);
|
||||
|
||||
|
||||
const labelList = document.getElementById("label-list");
|
||||
labelList.innerHTML = `
|
||||
<div class="error-message">
|
||||
LOADING ERROR: ${error.message}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
// render graph label list
|
||||
function renderLabels(labels) {
|
||||
const container = document.getElementById('label-list');
|
||||
container.innerHTML = labels.map(label => `
|
||||
<div class="label-item">
|
||||
<span style="font-weight: 500; color: var(--text-primary);">
|
||||
${label}
|
||||
</span>
|
||||
<div class="label-actions">
|
||||
<button class="btn btn-primary"
|
||||
onclick="handleLabelAction('${label}')">
|
||||
📋 graph
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
|
||||
function handleLabelAction(label) {
|
||||
loadGraph(label)
|
||||
}
|
||||
|
||||
|
||||
function refreshLabels() {
|
||||
showToast('LOADING GRAPH LABELS...', 'info');
|
||||
loadLabels();
|
||||
}
|
||||
|
||||
function showToast(message, type = 'info') {
|
||||
const toast = document.createElement('div');
|
||||
toast.className = `toast toast-${type}`;
|
||||
toast.textContent = message;
|
||||
document.body.appendChild(toast);
|
||||
|
||||
setTimeout(() => {
|
||||
toast.remove();
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', initializeApp);
|
@@ -13,6 +13,7 @@ from typing import (
|
||||
import numpy as np
|
||||
|
||||
from .utils import EmbeddingFunc
|
||||
from .types import KnowledgeGraph
|
||||
|
||||
|
||||
class TextChunkSchema(TypedDict):
|
||||
@@ -175,7 +176,7 @@ class BaseGraphStorage(StorageNameSpace):
|
||||
|
||||
async def get_knowledge_graph(
|
||||
self, node_label: str, max_depth: int = 5
|
||||
) -> dict[str, list[dict]]:
|
||||
) -> KnowledgeGraph:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
|
@@ -18,7 +18,7 @@ config.read("config.ini", "utf-8")
|
||||
|
||||
|
||||
@dataclass
|
||||
class MilvusVectorDBStorge(BaseVectorStorage):
|
||||
class MilvusVectorDBStorage(BaseVectorStorage):
|
||||
cosine_better_than_threshold: float = None
|
||||
|
||||
@staticmethod
|
||||
@@ -65,7 +65,7 @@ class MilvusVectorDBStorge(BaseVectorStorage):
|
||||
),
|
||||
)
|
||||
self._max_batch_size = self.global_config["embedding_batch_num"]
|
||||
MilvusVectorDBStorge.create_collection_if_not_exist(
|
||||
MilvusVectorDBStorage.create_collection_if_not_exist(
|
||||
self._client,
|
||||
self.namespace,
|
||||
dimension=self.embedding_func.embedding_dim,
|
||||
|
@@ -26,6 +26,7 @@ from tenacity import (
|
||||
|
||||
from ..utils import logger
|
||||
from ..base import BaseGraphStorage
|
||||
from ..types import KnowledgeGraph, KnowledgeGraphNode, KnowledgeGraphEdge
|
||||
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
@@ -379,7 +380,7 @@ class Neo4JStorage(BaseGraphStorage):
|
||||
|
||||
async def get_knowledge_graph(
|
||||
self, node_label: str, max_depth: int = 5
|
||||
) -> Dict[str, List[Dict]]:
|
||||
) -> KnowledgeGraph:
|
||||
"""
|
||||
Get complete connected subgraph for specified node (including the starting node itself)
|
||||
|
||||
@@ -390,32 +391,41 @@ class Neo4JStorage(BaseGraphStorage):
|
||||
4. Add depth control
|
||||
"""
|
||||
label = node_label.strip('"')
|
||||
result = {"nodes": [], "edges": []}
|
||||
result = KnowledgeGraph()
|
||||
seen_nodes = set()
|
||||
seen_edges = set()
|
||||
|
||||
async with self._driver.session(database=self._DATABASE) as session:
|
||||
try:
|
||||
# Critical debug step: first verify if starting node exists
|
||||
validate_query = f"MATCH (n:`{label}`) RETURN n LIMIT 1"
|
||||
validate_result = await session.run(validate_query)
|
||||
if not await validate_result.single():
|
||||
logger.warning(f"Starting node {label} does not exist!")
|
||||
return result
|
||||
main_query = ""
|
||||
if label == "*":
|
||||
main_query = """
|
||||
MATCH (n)
|
||||
WITH collect(DISTINCT n) AS nodes
|
||||
MATCH ()-[r]-()
|
||||
RETURN nodes, collect(DISTINCT r) AS relationships;
|
||||
"""
|
||||
else:
|
||||
# Critical debug step: first verify if starting node exists
|
||||
validate_query = f"MATCH (n:`{label}`) RETURN n LIMIT 1"
|
||||
validate_result = await session.run(validate_query)
|
||||
if not await validate_result.single():
|
||||
logger.warning(f"Starting node {label} does not exist!")
|
||||
return result
|
||||
|
||||
# Optimized query (including direction handling and self-loops)
|
||||
main_query = f"""
|
||||
MATCH (start:`{label}`)
|
||||
WITH start
|
||||
CALL apoc.path.subgraphAll(start, {{
|
||||
relationshipFilter: '>',
|
||||
minLevel: 0,
|
||||
maxLevel: {max_depth},
|
||||
bfs: true
|
||||
}})
|
||||
YIELD nodes, relationships
|
||||
RETURN nodes, relationships
|
||||
"""
|
||||
# Optimized query (including direction handling and self-loops)
|
||||
main_query = f"""
|
||||
MATCH (start:`{label}`)
|
||||
WITH start
|
||||
CALL apoc.path.subgraphAll(start, {{
|
||||
relationshipFilter: '>',
|
||||
minLevel: 0,
|
||||
maxLevel: {max_depth},
|
||||
bfs: true
|
||||
}})
|
||||
YIELD nodes, relationships
|
||||
RETURN nodes, relationships
|
||||
"""
|
||||
result_set = await session.run(main_query)
|
||||
record = await result_set.single()
|
||||
|
||||
@@ -423,35 +433,36 @@ class Neo4JStorage(BaseGraphStorage):
|
||||
# Handle nodes (compatible with multi-label cases)
|
||||
for node in record["nodes"]:
|
||||
# Use node ID + label combination as unique identifier
|
||||
node_id = f"{node.id}_{'_'.join(node.labels)}"
|
||||
node_id = node.id
|
||||
if node_id not in seen_nodes:
|
||||
node_data = dict(node)
|
||||
node_data["labels"] = list(node.labels) # Keep all labels
|
||||
result["nodes"].append(node_data)
|
||||
result.nodes.append(
|
||||
KnowledgeGraphNode(
|
||||
id=f"{node_id}",
|
||||
labels=list(node.labels),
|
||||
properties=dict(node),
|
||||
)
|
||||
)
|
||||
seen_nodes.add(node_id)
|
||||
|
||||
# Handle relationships (including direction information)
|
||||
for rel in record["relationships"]:
|
||||
edge_id = f"{rel.id}_{rel.type}"
|
||||
edge_id = rel.id
|
||||
if edge_id not in seen_edges:
|
||||
start = rel.start_node
|
||||
end = rel.end_node
|
||||
edge_data = dict(rel)
|
||||
edge_data.update(
|
||||
{
|
||||
"source": f"{start.id}_{'_'.join(start.labels)}",
|
||||
"target": f"{end.id}_{'_'.join(end.labels)}",
|
||||
"type": rel.type,
|
||||
"direction": rel.element_id.split(
|
||||
"->" if rel.end_node == end else "<-"
|
||||
)[1],
|
||||
}
|
||||
result.edges.append(
|
||||
KnowledgeGraphEdge(
|
||||
id=f"{edge_id}",
|
||||
type=rel.type,
|
||||
source=f"{start.id}",
|
||||
target=f"{end.id}",
|
||||
properties=dict(rel),
|
||||
)
|
||||
)
|
||||
result["edges"].append(edge_data)
|
||||
seen_edges.add(edge_id)
|
||||
|
||||
logger.info(
|
||||
f"Subgraph query successful | Node count: {len(result['nodes'])} | Edge count: {len(result['edges'])}"
|
||||
f"Subgraph query successful | Node count: {len(result.nodes)} | Edge count: {len(result.edges)}"
|
||||
)
|
||||
|
||||
except neo4jExceptions.ClientError as e:
|
||||
|
@@ -35,6 +35,7 @@ from .utils import (
|
||||
logger,
|
||||
set_logger,
|
||||
)
|
||||
from .types import KnowledgeGraph
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read("config.ini", "utf-8")
|
||||
@@ -145,12 +146,12 @@ STORAGES = {
|
||||
"NetworkXStorage": ".kg.networkx_impl",
|
||||
"JsonKVStorage": ".kg.json_kv_impl",
|
||||
"NanoVectorDBStorage": ".kg.nano_vector_db_impl",
|
||||
"JsonDocStatusStorage": ".kg.jsondocstatus_impl",
|
||||
"JsonDocStatusStorage": ".kg.json_doc_status_impl",
|
||||
"Neo4JStorage": ".kg.neo4j_impl",
|
||||
"OracleKVStorage": ".kg.oracle_impl",
|
||||
"OracleGraphStorage": ".kg.oracle_impl",
|
||||
"OracleVectorDBStorage": ".kg.oracle_impl",
|
||||
"MilvusVectorDBStorge": ".kg.milvus_impl",
|
||||
"MilvusVectorDBStorage": ".kg.milvus_impl",
|
||||
"MongoKVStorage": ".kg.mongo_impl",
|
||||
"MongoDocStatusStorage": ".kg.mongo_impl",
|
||||
"MongoGraphStorage": ".kg.mongo_impl",
|
||||
@@ -546,7 +547,9 @@ class LightRAG:
|
||||
text = await self.chunk_entity_relation_graph.get_all_labels()
|
||||
return text
|
||||
|
||||
async def get_graps(self, nodel_label: str, max_depth: int):
|
||||
async def get_knowledge_graph(
|
||||
self, nodel_label: str, max_depth: int
|
||||
) -> KnowledgeGraph:
|
||||
return await self.chunk_entity_relation_graph.get_knowledge_graph(
|
||||
node_label=nodel_label, max_depth=max_depth
|
||||
)
|
||||
|
@@ -1,7 +1,26 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import List
|
||||
from typing import List, Dict, Any
|
||||
|
||||
|
||||
class GPTKeywordExtractionFormat(BaseModel):
|
||||
high_level_keywords: List[str]
|
||||
low_level_keywords: List[str]
|
||||
|
||||
|
||||
class KnowledgeGraphNode(BaseModel):
|
||||
id: str
|
||||
labels: List[str]
|
||||
properties: Dict[str, Any] # anything else goes here
|
||||
|
||||
|
||||
class KnowledgeGraphEdge(BaseModel):
|
||||
id: str
|
||||
type: str
|
||||
source: str # id of source node
|
||||
target: str # id of target node
|
||||
properties: Dict[str, Any] # anything else goes here
|
||||
|
||||
|
||||
class KnowledgeGraph(BaseModel):
|
||||
nodes: List[KnowledgeGraphNode] = []
|
||||
edges: List[KnowledgeGraphEdge] = []
|
||||
|
Reference in New Issue
Block a user