Spaces:
Running
Running
Commit ·
0ee86b0
1
Parent(s): 14f16a2
Add database viewer page and enhance navigation
Browse files- Introduced a new `dbviewer.html` page for browsing documents and chunks stored in the ChromaDB database.
- Updated `index.html` to include links for viewing/editing embeddings and database records.
- Modified `manifest.html` and `upload.html` to add a "Back to Home" button for improved navigation.
- Adjusted styles in `manifest.html` for better UI consistency.
- .gitignore +4 -1
- infrastructure/database.py +93 -2
- infrastructure/document_processor.py +5 -7
- routes/api.py +284 -34
- routes/web.py +4 -4
- static/chunks.html +364 -169
- static/dbviewer.html +403 -0
- static/index.html +1 -1
- static/manifest.html +10 -3
- static/upload.html +6 -0
.gitignore
CHANGED
|
@@ -4,4 +4,7 @@ __pycache__
|
|
| 4 |
.DS_Store
|
| 5 |
.env
|
| 6 |
__pycache__/
|
| 7 |
-
tech-trans-rag/
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
.DS_Store
|
| 5 |
.env
|
| 6 |
__pycache__/
|
| 7 |
+
tech-trans-rag/
|
| 8 |
+
chroma_db/
|
| 9 |
+
test_data.py
|
| 10 |
+
data/
|
infrastructure/database.py
CHANGED
|
@@ -581,7 +581,7 @@ def get_document_chunk_counts(doc_ids: list[int]) -> dict[int, int]:
|
|
| 581 |
def get_max_document_id():
|
| 582 |
all_ids = _documents_collection.get(include=[])['ids']
|
| 583 |
if not all_ids:
|
| 584 |
-
return
|
| 585 |
return max([int(i) for i in all_ids])
|
| 586 |
|
| 587 |
def get_all_chunks(limit: int = 200, offset: int = 0):
|
|
@@ -616,6 +616,42 @@ def get_embedding_for_chunk(chunk_id: int):
|
|
| 616 |
|
| 617 |
return Embedding(id=chunk_id, chunk_id=chunk_id, model=model, dim=dim, vector=float_vector)
|
| 618 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 619 |
def delete_document(doc_id: int):
|
| 620 |
chunks_to_delete = _chunks_collection.get(where={"doc_id": doc_id})
|
| 621 |
if chunks_to_delete['ids']:
|
|
@@ -636,6 +672,61 @@ def delete_document(doc_id: int):
|
|
| 636 |
|
| 637 |
_documents_collection.delete(ids=[str(doc_id)])
|
| 638 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 639 |
def update_document(doc_id: int, updates: Dict[str, Any]) -> Optional[Document]:
|
| 640 |
"""Update metadata fields for a document.
|
| 641 |
|
|
@@ -691,7 +782,7 @@ __all__ = [
|
|
| 691 |
"add_document", "add_chunk", "upsert_embedding",
|
| 692 |
"get_document", "get_document_by_sha", "get_chunks_for_doc", "get_chunks_by_ids",
|
| 693 |
"get_documents", "get_document_chunk_counts", "get_all_chunks", "get_max_chunk_id",
|
| 694 |
-
"get_embedding_for_chunk", "delete_document", "clear_database", "update_document",
|
| 695 |
"TOK_VER", "SEG_VER", "ping",
|
| 696 |
"Document", "Chunk", "Embedding",
|
| 697 |
]
|
|
|
|
| 581 |
def get_max_document_id():
|
| 582 |
all_ids = _documents_collection.get(include=[])['ids']
|
| 583 |
if not all_ids:
|
| 584 |
+
return 0
|
| 585 |
return max([int(i) for i in all_ids])
|
| 586 |
|
| 587 |
def get_all_chunks(limit: int = 200, offset: int = 0):
|
|
|
|
| 616 |
|
| 617 |
return Embedding(id=chunk_id, chunk_id=chunk_id, model=model, dim=dim, vector=float_vector)
|
| 618 |
|
| 619 |
+
|
| 620 |
+
def get_embedding_counts_for_chunks(chunk_ids: List[int]) -> dict[int, int]:
|
| 621 |
+
"""Get embedding counts for a list of chunk IDs.
|
| 622 |
+
|
| 623 |
+
Returns a dictionary mapping chunk_id to the number of embeddings (0 or 1)
|
| 624 |
+
since each chunk can have at most one embedding in the current schema.
|
| 625 |
+
|
| 626 |
+
Args:
|
| 627 |
+
chunk_ids: List of chunk IDs to check for embeddings.
|
| 628 |
+
|
| 629 |
+
Returns:
|
| 630 |
+
Dictionary mapping chunk_id to embedding count (0 or 1).
|
| 631 |
+
"""
|
| 632 |
+
if not chunk_ids:
|
| 633 |
+
return {}
|
| 634 |
+
|
| 635 |
+
str_chunk_ids = [str(chunk_id) for chunk_id in chunk_ids]
|
| 636 |
+
chunk_data = _chunks_collection.get(ids=str_chunk_ids, include=["embeddings"])
|
| 637 |
+
|
| 638 |
+
embedding_counts = {}
|
| 639 |
+
|
| 640 |
+
# Initialize all counts to 0
|
| 641 |
+
for chunk_id in chunk_ids:
|
| 642 |
+
embedding_counts[chunk_id] = 0
|
| 643 |
+
|
| 644 |
+
# Check which chunks have embeddings
|
| 645 |
+
if chunk_data['ids'] and chunk_data['embeddings']:
|
| 646 |
+
for i, chunk_id_str in enumerate(chunk_data['ids']):
|
| 647 |
+
chunk_id = int(chunk_id_str)
|
| 648 |
+
embedding = chunk_data['embeddings'][i]
|
| 649 |
+
# Check if embedding exists and is not empty
|
| 650 |
+
if embedding and len(embedding) > 0:
|
| 651 |
+
embedding_counts[chunk_id] = 1
|
| 652 |
+
|
| 653 |
+
return embedding_counts
|
| 654 |
+
|
| 655 |
def delete_document(doc_id: int):
|
| 656 |
chunks_to_delete = _chunks_collection.get(where={"doc_id": doc_id})
|
| 657 |
if chunks_to_delete['ids']:
|
|
|
|
| 672 |
|
| 673 |
_documents_collection.delete(ids=[str(doc_id)])
|
| 674 |
|
| 675 |
+
def update_chunk(chunk_id: int, updates: Dict[str, Any]) -> Optional[Chunk]:
|
| 676 |
+
"""Update metadata fields for a chunk.
|
| 677 |
+
|
| 678 |
+
Only known metadata keys are updated. Returns the updated Chunk or None if not found.
|
| 679 |
+
If the text field is updated, the associated embedding should be regenerated.
|
| 680 |
+
"""
|
| 681 |
+
allowed = {
|
| 682 |
+
"text",
|
| 683 |
+
"section_number",
|
| 684 |
+
"section_title",
|
| 685 |
+
"clause_type",
|
| 686 |
+
"definition_terms",
|
| 687 |
+
"page_start",
|
| 688 |
+
"page_end",
|
| 689 |
+
"path",
|
| 690 |
+
"numbers_present",
|
| 691 |
+
}
|
| 692 |
+
try:
|
| 693 |
+
existing = _chunks_collection.get(ids=[str(chunk_id)])
|
| 694 |
+
if not existing['ids'] or not existing['metadatas']:
|
| 695 |
+
return None
|
| 696 |
+
|
| 697 |
+
meta = dict(existing['metadatas'][0])
|
| 698 |
+
documents_list = existing.get('documents')
|
| 699 |
+
documents = documents_list[0] if documents_list and len(documents_list) > 0 else ''
|
| 700 |
+
|
| 701 |
+
# Update metadata with allowed fields
|
| 702 |
+
for k, v in updates.items():
|
| 703 |
+
if k in allowed:
|
| 704 |
+
if k == "text":
|
| 705 |
+
# Text update should trigger embedding regeneration
|
| 706 |
+
documents = str(v) if v is not None else ''
|
| 707 |
+
elif k in ["page_start", "page_end"]:
|
| 708 |
+
# Ensure integers for page fields
|
| 709 |
+
meta[k] = int(v) if v is not None and str(v).isdigit() else None
|
| 710 |
+
elif k == "numbers_present":
|
| 711 |
+
# Ensure boolean
|
| 712 |
+
meta[k] = bool(v) if v is not None else None
|
| 713 |
+
else:
|
| 714 |
+
meta[k] = str(v) if v is not None else None
|
| 715 |
+
|
| 716 |
+
# Update in ChromaDB
|
| 717 |
+
_chunks_collection.update(
|
| 718 |
+
ids=[str(chunk_id)],
|
| 719 |
+
metadatas=[meta],
|
| 720 |
+
documents=[documents] if documents else None
|
| 721 |
+
)
|
| 722 |
+
|
| 723 |
+
# Return updated chunk
|
| 724 |
+
return Chunk.from_chroma(chunk_id, meta, documents)
|
| 725 |
+
|
| 726 |
+
except Exception as e: # pragma: no cover - defensive
|
| 727 |
+
_logger.error(f"Failed to update chunk {chunk_id}: {e}")
|
| 728 |
+
return None
|
| 729 |
+
|
| 730 |
def update_document(doc_id: int, updates: Dict[str, Any]) -> Optional[Document]:
|
| 731 |
"""Update metadata fields for a document.
|
| 732 |
|
|
|
|
| 782 |
"add_document", "add_chunk", "upsert_embedding",
|
| 783 |
"get_document", "get_document_by_sha", "get_chunks_for_doc", "get_chunks_by_ids",
|
| 784 |
"get_documents", "get_document_chunk_counts", "get_all_chunks", "get_max_chunk_id",
|
| 785 |
+
"get_embedding_for_chunk", "get_embedding_counts_for_chunks", "delete_document", "clear_database", "update_document", "update_chunk",
|
| 786 |
"TOK_VER", "SEG_VER", "ping",
|
| 787 |
"Document", "Chunk", "Embedding",
|
| 788 |
]
|
infrastructure/document_processor.py
CHANGED
|
@@ -233,10 +233,9 @@ def sha256_text(text: str) -> str:
|
|
| 233 |
"""Compute the SHA-256 hash of a text string."""
|
| 234 |
return sha256_bytes(text.encode('utf-8'))
|
| 235 |
|
| 236 |
-
def upsert_manifest_record(text: str, size: str, doc_id: int, sha256: str, source_path: str, clean_path: str, content_type: str | None, title: str | None, jurisdiction: str | None, doc_type: str | None) -> Dict[str, Optional[Any]]:
|
| 237 |
"""Upsert a manifest record in the database."""
|
| 238 |
|
| 239 |
-
manifest = get_manifest_info(text)
|
| 240 |
manifest_record = {
|
| 241 |
"doc_id": str(doc_id),
|
| 242 |
"title": title,
|
|
@@ -245,13 +244,12 @@ def upsert_manifest_record(text: str, size: str, doc_id: int, sha256: str, sourc
|
|
| 245 |
"clean_path": clean_path,
|
| 246 |
"bytes": size,
|
| 247 |
"content_type": content_type,
|
| 248 |
-
"license": manifest.get("license"),
|
| 249 |
"doc_type": doc_type,
|
| 250 |
-
"party_roles":
|
| 251 |
"jurisdiction": jurisdiction,
|
| 252 |
-
"governing_law":
|
| 253 |
-
"industry":
|
| 254 |
-
"effective_date":
|
| 255 |
"created_at": datetime.now(timezone.utc).isoformat(),
|
| 256 |
}
|
| 257 |
|
|
|
|
| 233 |
"""Compute the SHA-256 hash of a text string."""
|
| 234 |
return sha256_bytes(text.encode('utf-8'))
|
| 235 |
|
| 236 |
+
def upsert_manifest_record(text: str, size: str, doc_id: int, sha256: str, source_path: str, clean_path: str, content_type: str | None, title: str | None, jurisdiction: str | None, doc_type: str | None, party_roles: str | None, governing_law: str | None, effective_date: str | None, industry: str | None) -> Dict[str, Optional[Any]]:
|
| 237 |
"""Upsert a manifest record in the database."""
|
| 238 |
|
|
|
|
| 239 |
manifest_record = {
|
| 240 |
"doc_id": str(doc_id),
|
| 241 |
"title": title,
|
|
|
|
| 244 |
"clean_path": clean_path,
|
| 245 |
"bytes": size,
|
| 246 |
"content_type": content_type,
|
|
|
|
| 247 |
"doc_type": doc_type,
|
| 248 |
+
"party_roles": party_roles,
|
| 249 |
"jurisdiction": jurisdiction,
|
| 250 |
+
"governing_law": governing_law,
|
| 251 |
+
"industry": industry,
|
| 252 |
+
"effective_date": effective_date,
|
| 253 |
"created_at": datetime.now(timezone.utc).isoformat(),
|
| 254 |
}
|
| 255 |
|
routes/api.py
CHANGED
|
@@ -3,7 +3,6 @@ import os
|
|
| 3 |
from flask import Blueprint, request, jsonify, send_from_directory
|
| 4 |
from werkzeug.utils import secure_filename
|
| 5 |
from infrastructure.logger import get_logger
|
| 6 |
-
from random import randint
|
| 7 |
|
| 8 |
from infrastructure.database import (
|
| 9 |
init_db,
|
|
@@ -13,17 +12,19 @@ from infrastructure.database import (
|
|
| 13 |
get_documents,
|
| 14 |
get_document_chunk_counts,
|
| 15 |
get_all_chunks,
|
|
|
|
| 16 |
full_reset_chroma,
|
| 17 |
-
get_max_document_id,
|
| 18 |
get_chunks_by_ids,
|
| 19 |
update_document,
|
|
|
|
| 20 |
delete_document,
|
| 21 |
)
|
| 22 |
from infrastructure.document_processor import (
|
| 23 |
extract_text,
|
| 24 |
extract_title_type_jurisdiction,
|
| 25 |
sha256_text,
|
| 26 |
-
upsert_manifest_record
|
|
|
|
| 27 |
)
|
| 28 |
from infrastructure.chunker import chunk_doc
|
| 29 |
from infrastructure.vector_search import find_nearest_neighbors
|
|
@@ -63,6 +64,7 @@ def add_doc():
|
|
| 63 |
title = None
|
| 64 |
doc_id_val = None
|
| 65 |
|
|
|
|
| 66 |
if not doc:
|
| 67 |
filename = secure_filename(file.filename)
|
| 68 |
|
|
@@ -73,18 +75,25 @@ def add_doc():
|
|
| 73 |
doc_type = doc_info.get("doc_type")
|
| 74 |
if "jurisdiction" in doc_info:
|
| 75 |
jurisdiction = doc_info.get("jurisdiction")
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
current_doc_id = max_doc_id + 1 if max_doc_id is not None else 0
|
| 79 |
file_format = file.mimetype
|
| 80 |
file.stream.seek(0, 2)
|
| 81 |
file_size = file.tell()
|
| 82 |
file.stream.seek(0)
|
| 83 |
|
| 84 |
-
raw_filename = f"{str(
|
| 85 |
-
|
| 86 |
raw_path = os.path.join(UPLOAD_FOLDER, raw_filename)
|
| 87 |
-
|
|
|
|
| 88 |
clean_path = os.path.join(CLEAN_FOLDER, txt_filename)
|
| 89 |
|
| 90 |
file.stream.seek(0)
|
|
@@ -95,29 +104,26 @@ def add_doc():
|
|
| 95 |
f.write(clean_text)
|
| 96 |
logger.info("Saved clean text to %s", clean_path)
|
| 97 |
|
| 98 |
-
|
|
|
|
|
|
|
| 99 |
sha256=content_sha,
|
| 100 |
title=title,
|
| 101 |
source_path=raw_path,
|
| 102 |
clean_path=clean_path,
|
| 103 |
doc_type=doc_type or "",
|
| 104 |
jurisdiction=jurisdiction or "",
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
text=clean_text,
|
| 107 |
size=str(file_size),
|
| 108 |
content_type=file_format,
|
| 109 |
)
|
| 110 |
|
| 111 |
-
industry = manifest_record.get("industry") or None
|
| 112 |
-
party_roles = manifest_record.get("party_roles") or None
|
| 113 |
-
governing_law = manifest_record.get("governing_law") or None
|
| 114 |
-
effective_date = manifest_record.get("effective_date") or None
|
| 115 |
-
|
| 116 |
-
doc = add_document(sha256=content_sha, title=title, source_path=raw_path, doc_type=doc_type, jurisdiction=jurisdiction, industry=industry, party_roles=party_roles, governing_law=governing_law, effective_date=effective_date)
|
| 117 |
-
doc_id_val = getattr(doc, "doc_id", 0)
|
| 118 |
-
|
| 119 |
logger.error("INFO: Added document id=%s, sha256=%s, title=%s, doc_type=%s, jurisdiction=%s", doc_id_val, content_sha, title, doc_type, jurisdiction)
|
| 120 |
-
logger.error(f"INFO: DB doc_id: {doc_id_val}; Manifest doc_id: {current_doc_id} ")
|
| 121 |
|
| 122 |
else:
|
| 123 |
doc_id_val = getattr(doc, "doc_id", 0)
|
|
@@ -129,7 +135,7 @@ def add_doc():
|
|
| 129 |
pass
|
| 130 |
|
| 131 |
try:
|
| 132 |
-
chunks = chunk_doc(text=clean_text, doc_id=
|
| 133 |
logger.info("Chunked document into %d chunks", len(chunks))
|
| 134 |
except Exception as e:
|
| 135 |
logger.exception("Chunking failed: %s", e)
|
|
@@ -169,11 +175,14 @@ def get_chunks():
|
|
| 169 |
|
| 170 |
@api_bp.route("/documents", methods=["GET"])
|
| 171 |
def list_documents():
|
| 172 |
-
"""List documents with pagination and
|
| 173 |
|
| 174 |
Query params:
|
| 175 |
-
|
| 176 |
-
|
|
|
|
|
|
|
|
|
|
| 177 |
"""
|
| 178 |
try:
|
| 179 |
limit = int(request.args.get("limit", 100))
|
|
@@ -182,26 +191,49 @@ def list_documents():
|
|
| 182 |
return jsonify({"error": "invalid pagination"}), 400
|
| 183 |
limit = max(1, min(limit, 500))
|
| 184 |
offset = max(0, offset)
|
|
|
|
| 185 |
docs = get_documents(limit=limit, offset=offset)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
ids = [int(getattr(d, 'doc_id')) for d in docs]
|
| 187 |
counts = get_document_chunk_counts(ids)
|
|
|
|
| 188 |
out = []
|
| 189 |
for d in docs:
|
| 190 |
-
|
| 191 |
"doc_id": int(getattr(d, 'doc_id')),
|
| 192 |
-
"title": d.title,
|
| 193 |
"sha256": d.sha256,
|
|
|
|
|
|
|
|
|
|
| 194 |
"doc_type": getattr(d, "doc_type", None),
|
| 195 |
"jurisdiction": getattr(d, "jurisdiction", None),
|
| 196 |
-
"
|
|
|
|
|
|
|
|
|
|
| 197 |
"chunk_count": counts.get(int(getattr(d, 'doc_id')), 0),
|
| 198 |
-
}
|
|
|
|
|
|
|
| 199 |
return jsonify({"documents": out, "count": len(out), "limit": limit, "offset": offset}), 200
|
| 200 |
|
| 201 |
|
| 202 |
@api_bp.route("/chunks/all", methods=["GET"])
|
| 203 |
def list_all_chunks():
|
| 204 |
-
"""List global chunks slice (paginated)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
try:
|
| 206 |
limit = int(request.args.get("limit", 200))
|
| 207 |
offset = int(request.args.get("offset", 0))
|
|
@@ -209,11 +241,19 @@ def list_all_chunks():
|
|
| 209 |
return jsonify({"error": "invalid pagination"}), 400
|
| 210 |
limit = max(1, min(limit, 500))
|
| 211 |
offset = max(0, offset)
|
|
|
|
| 212 |
rows = get_all_chunks(limit=limit, offset=offset)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
out = []
|
| 214 |
for c in rows:
|
| 215 |
-
|
| 216 |
-
out.append({
|
| 217 |
"chunk_id": c.chunk_id,
|
| 218 |
"doc_id": c.doc_id,
|
| 219 |
"chunk_index": c.chunk_index,
|
|
@@ -221,12 +261,73 @@ def list_all_chunks():
|
|
| 221 |
"tok_ver": c.tok_ver,
|
| 222 |
"seg_ver": c.seg_ver,
|
| 223 |
"text": str(getattr(c, 'text', '') or ''),
|
| 224 |
-
"
|
| 225 |
-
"
|
| 226 |
-
"
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
return jsonify({"chunks": out, "count": len(out), "limit": limit, "offset": offset}), 200
|
| 229 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
@api_bp.route("/query", methods=["POST"])
|
| 231 |
def query():
|
| 232 |
"""Vector search against chunk embeddings using ChromaDB."""
|
|
@@ -491,3 +592,152 @@ def serve_raw(subpath: str):
|
|
| 491 |
# To use, ensure source_path links are constructed as /api/raw/<relative to RAW_PREFIX>
|
| 492 |
abs_path = os.path.join(RAW_PREFIX, "")
|
| 493 |
return send_from_directory(abs_path, subpath, as_attachment=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from flask import Blueprint, request, jsonify, send_from_directory
|
| 4 |
from werkzeug.utils import secure_filename
|
| 5 |
from infrastructure.logger import get_logger
|
|
|
|
| 6 |
|
| 7 |
from infrastructure.database import (
|
| 8 |
init_db,
|
|
|
|
| 12 |
get_documents,
|
| 13 |
get_document_chunk_counts,
|
| 14 |
get_all_chunks,
|
| 15 |
+
get_embedding_counts_for_chunks,
|
| 16 |
full_reset_chroma,
|
|
|
|
| 17 |
get_chunks_by_ids,
|
| 18 |
update_document,
|
| 19 |
+
update_chunk,
|
| 20 |
delete_document,
|
| 21 |
)
|
| 22 |
from infrastructure.document_processor import (
|
| 23 |
extract_text,
|
| 24 |
extract_title_type_jurisdiction,
|
| 25 |
sha256_text,
|
| 26 |
+
upsert_manifest_record,
|
| 27 |
+
get_manifest_info
|
| 28 |
)
|
| 29 |
from infrastructure.chunker import chunk_doc
|
| 30 |
from infrastructure.vector_search import find_nearest_neighbors
|
|
|
|
| 64 |
title = None
|
| 65 |
doc_id_val = None
|
| 66 |
|
| 67 |
+
|
| 68 |
if not doc:
|
| 69 |
filename = secure_filename(file.filename)
|
| 70 |
|
|
|
|
| 75 |
doc_type = doc_info.get("doc_type")
|
| 76 |
if "jurisdiction" in doc_info:
|
| 77 |
jurisdiction = doc_info.get("jurisdiction")
|
| 78 |
+
|
| 79 |
+
manifest_record = get_manifest_info(clean_text)
|
| 80 |
+
party_roles = manifest_record.get("party_roles") or None
|
| 81 |
+
governing_law = manifest_record.get("governing_law") or None
|
| 82 |
+
effective_date = manifest_record.get("effective_date") or None
|
| 83 |
+
industry = manifest_record.get("industry") or None
|
| 84 |
+
|
| 85 |
+
doc = add_document(sha256=content_sha, title=title, source_path=None, doc_type=doc_type, jurisdiction=jurisdiction, industry=industry, party_roles=party_roles, governing_law=governing_law, effective_date=effective_date)
|
| 86 |
+
doc_id_val = getattr(doc, "doc_id", 0)
|
| 87 |
|
|
|
|
| 88 |
file_format = file.mimetype
|
| 89 |
file.stream.seek(0, 2)
|
| 90 |
file_size = file.tell()
|
| 91 |
file.stream.seek(0)
|
| 92 |
|
| 93 |
+
raw_filename = f"{str(doc_id_val)}" + "." + filename.rsplit('.', 1)[1].lower()
|
|
|
|
| 94 |
raw_path = os.path.join(UPLOAD_FOLDER, raw_filename)
|
| 95 |
+
|
| 96 |
+
txt_filename = f"{str(doc_id_val)}" + '.txt'
|
| 97 |
clean_path = os.path.join(CLEAN_FOLDER, txt_filename)
|
| 98 |
|
| 99 |
file.stream.seek(0)
|
|
|
|
| 104 |
f.write(clean_text)
|
| 105 |
logger.info("Saved clean text to %s", clean_path)
|
| 106 |
|
| 107 |
+
doc = update_document(doc_id=doc_id_val, updates={"source_path": raw_path})
|
| 108 |
+
|
| 109 |
+
manifest_jsonl_line = upsert_manifest_record(
|
| 110 |
sha256=content_sha,
|
| 111 |
title=title,
|
| 112 |
source_path=raw_path,
|
| 113 |
clean_path=clean_path,
|
| 114 |
doc_type=doc_type or "",
|
| 115 |
jurisdiction=jurisdiction or "",
|
| 116 |
+
party_roles=party_roles or "",
|
| 117 |
+
governing_law=governing_law or "",
|
| 118 |
+
effective_date=effective_date or "",
|
| 119 |
+
industry=industry or "",
|
| 120 |
+
doc_id=doc_id_val,
|
| 121 |
text=clean_text,
|
| 122 |
size=str(file_size),
|
| 123 |
content_type=file_format,
|
| 124 |
)
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
logger.error("INFO: Added document id=%s, sha256=%s, title=%s, doc_type=%s, jurisdiction=%s", doc_id_val, content_sha, title, doc_type, jurisdiction)
|
|
|
|
| 127 |
|
| 128 |
else:
|
| 129 |
doc_id_val = getattr(doc, "doc_id", 0)
|
|
|
|
| 135 |
pass
|
| 136 |
|
| 137 |
try:
|
| 138 |
+
chunks = chunk_doc(text=clean_text, doc_id=doc_id_val)
|
| 139 |
logger.info("Chunked document into %d chunks", len(chunks))
|
| 140 |
except Exception as e:
|
| 141 |
logger.exception("Chunking failed: %s", e)
|
|
|
|
| 175 |
|
| 176 |
@api_bp.route("/documents", methods=["GET"])
|
| 177 |
def list_documents():
|
| 178 |
+
"""List documents with pagination and document metadata.
|
| 179 |
|
| 180 |
Query params:
|
| 181 |
+
limit (default 100, max 500)
|
| 182 |
+
offset (default 0)
|
| 183 |
+
|
| 184 |
+
Returns documents with keys: doc_id, sha_256, title, source_path, created_at,
|
| 185 |
+
docu_type, jurisdiction, governing_law, party_roles, industry, effective_date, chunks.
|
| 186 |
"""
|
| 187 |
try:
|
| 188 |
limit = int(request.args.get("limit", 100))
|
|
|
|
| 191 |
return jsonify({"error": "invalid pagination"}), 400
|
| 192 |
limit = max(1, min(limit, 500))
|
| 193 |
offset = max(0, offset)
|
| 194 |
+
|
| 195 |
docs = get_documents(limit=limit, offset=offset)
|
| 196 |
+
|
| 197 |
+
if not docs:
|
| 198 |
+
return jsonify({"documents": [], "count": 0, "limit": limit, "offset": offset}), 200
|
| 199 |
+
|
| 200 |
+
# Get chunk counts for all documents
|
| 201 |
ids = [int(getattr(d, 'doc_id')) for d in docs]
|
| 202 |
counts = get_document_chunk_counts(ids)
|
| 203 |
+
|
| 204 |
out = []
|
| 205 |
for d in docs:
|
| 206 |
+
doc_data = {
|
| 207 |
"doc_id": int(getattr(d, 'doc_id')),
|
|
|
|
| 208 |
"sha256": d.sha256,
|
| 209 |
+
"title": d.title,
|
| 210 |
+
"source_path": d.source_path,
|
| 211 |
+
"created_at": d.created_at.isoformat() if getattr(d, 'created_at', None) else None,
|
| 212 |
"doc_type": getattr(d, "doc_type", None),
|
| 213 |
"jurisdiction": getattr(d, "jurisdiction", None),
|
| 214 |
+
"governing_law": getattr(d, "governing_law", None),
|
| 215 |
+
"party_roles": getattr(d, "party_roles", None),
|
| 216 |
+
"industry": getattr(d, "industry", None),
|
| 217 |
+
"effective_date": d.effective_date.isoformat() if d.effective_date else None,
|
| 218 |
"chunk_count": counts.get(int(getattr(d, 'doc_id')), 0),
|
| 219 |
+
}
|
| 220 |
+
out.append(doc_data)
|
| 221 |
+
|
| 222 |
return jsonify({"documents": out, "count": len(out), "limit": limit, "offset": offset}), 200
|
| 223 |
|
| 224 |
|
| 225 |
@api_bp.route("/chunks/all", methods=["GET"])
|
| 226 |
def list_all_chunks():
|
| 227 |
+
"""List global chunks slice (paginated) with specified fields and embedding counts.
|
| 228 |
+
|
| 229 |
+
Query params:
|
| 230 |
+
limit (<=500, default 200)
|
| 231 |
+
offset (default 0)
|
| 232 |
+
|
| 233 |
+
Returns chunks with keys: chunk_id, doc_id, chunk_index, token_count, tok_ver,
|
| 234 |
+
seg_ver, text, page_start, page_end, section_number, section_title, clause_type,
|
| 235 |
+
path, numbers_present, definition_terms, embedding_count.
|
| 236 |
+
"""
|
| 237 |
try:
|
| 238 |
limit = int(request.args.get("limit", 200))
|
| 239 |
offset = int(request.args.get("offset", 0))
|
|
|
|
| 241 |
return jsonify({"error": "invalid pagination"}), 400
|
| 242 |
limit = max(1, min(limit, 500))
|
| 243 |
offset = max(0, offset)
|
| 244 |
+
|
| 245 |
rows = get_all_chunks(limit=limit, offset=offset)
|
| 246 |
+
|
| 247 |
+
if not rows:
|
| 248 |
+
return jsonify({"chunks": [], "count": 0, "limit": limit, "offset": offset}), 200
|
| 249 |
+
|
| 250 |
+
# Get embedding counts for all chunks
|
| 251 |
+
chunk_ids = [c.chunk_id for c in rows]
|
| 252 |
+
embedding_counts = get_embedding_counts_for_chunks(chunk_ids)
|
| 253 |
+
|
| 254 |
out = []
|
| 255 |
for c in rows:
|
| 256 |
+
chunk_data = {
|
|
|
|
| 257 |
"chunk_id": c.chunk_id,
|
| 258 |
"doc_id": c.doc_id,
|
| 259 |
"chunk_index": c.chunk_index,
|
|
|
|
| 261 |
"tok_ver": c.tok_ver,
|
| 262 |
"seg_ver": c.seg_ver,
|
| 263 |
"text": str(getattr(c, 'text', '') or ''),
|
| 264 |
+
"page_start": c.page_start,
|
| 265 |
+
"page_end": c.page_end,
|
| 266 |
+
"section_number": c.section_number,
|
| 267 |
+
"section_title": c.section_title,
|
| 268 |
+
"clause_type": c.clause_type,
|
| 269 |
+
"path": c.path,
|
| 270 |
+
"numbers_present": c.numbers_present,
|
| 271 |
+
"definition_terms": c.definition_terms,
|
| 272 |
+
"embedding_count": embedding_counts.get(c.chunk_id, 0),
|
| 273 |
+
}
|
| 274 |
+
out.append(chunk_data)
|
| 275 |
+
|
| 276 |
return jsonify({"chunks": out, "count": len(out), "limit": limit, "offset": offset}), 200
|
| 277 |
|
| 278 |
+
@api_bp.route("/chunks", methods=["PATCH"])
|
| 279 |
+
def update_chunks():
|
| 280 |
+
"""Update a chunk's metadata and optionally regenerate embedding if text changed."""
|
| 281 |
+
payload = request.get_json(force=True) or {}
|
| 282 |
+
chunk_id = payload.get("chunk_id")
|
| 283 |
+
updates = payload.get("updates", {})
|
| 284 |
+
|
| 285 |
+
if not chunk_id:
|
| 286 |
+
return jsonify({"error": "chunk_id required"}), 400
|
| 287 |
+
|
| 288 |
+
try:
|
| 289 |
+
chunk_id = int(chunk_id)
|
| 290 |
+
except (ValueError, TypeError):
|
| 291 |
+
return jsonify({"error": "invalid chunk_id"}), 400
|
| 292 |
+
|
| 293 |
+
if not updates or not isinstance(updates, dict):
|
| 294 |
+
return jsonify({"error": "updates dict required"}), 400
|
| 295 |
+
|
| 296 |
+
logger.info("Updating chunk %d with updates: %s", chunk_id, updates)
|
| 297 |
+
|
| 298 |
+
try:
|
| 299 |
+
updated_chunk = update_chunk(chunk_id, updates)
|
| 300 |
+
if not updated_chunk:
|
| 301 |
+
return jsonify({"error": "chunk not found"}), 404
|
| 302 |
+
|
| 303 |
+
# If text was updated, we should regenerate the embedding using ChromaDB
|
| 304 |
+
if "text" in updates:
|
| 305 |
+
from infrastructure.embeddings import get_chroma_collection
|
| 306 |
+
|
| 307 |
+
try:
|
| 308 |
+
new_text = updates["text"]
|
| 309 |
+
if new_text and new_text.strip():
|
| 310 |
+
# Update text and regenerate embedding via ChromaDB
|
| 311 |
+
collection = get_chroma_collection()
|
| 312 |
+
collection.update(
|
| 313 |
+
ids=[str(chunk_id)],
|
| 314 |
+
documents=[new_text]
|
| 315 |
+
)
|
| 316 |
+
logger.info("Regenerated embedding for chunk %d after text update", chunk_id)
|
| 317 |
+
except Exception as e:
|
| 318 |
+
logger.error("Failed to regenerate embedding for chunk %d: %s", chunk_id, e)
|
| 319 |
+
# Don't fail the request, just log the error
|
| 320 |
+
|
| 321 |
+
return jsonify({
|
| 322 |
+
"message": "chunk updated successfully",
|
| 323 |
+
"chunk_id": chunk_id,
|
| 324 |
+
"updated_fields": list(updates.keys())
|
| 325 |
+
}), 200
|
| 326 |
+
|
| 327 |
+
except Exception as e:
|
| 328 |
+
logger.error("Failed to update chunk %d: %s", chunk_id, e)
|
| 329 |
+
return jsonify({"error": "internal server error"}), 500
|
| 330 |
+
|
| 331 |
@api_bp.route("/query", methods=["POST"])
|
| 332 |
def query():
|
| 333 |
"""Vector search against chunk embeddings using ChromaDB."""
|
|
|
|
| 592 |
# To use, ensure source_path links are constructed as /api/raw/<relative to RAW_PREFIX>
|
| 593 |
abs_path = os.path.join(RAW_PREFIX, "")
|
| 594 |
return send_from_directory(abs_path, subpath, as_attachment=False)
|
| 595 |
+
|
| 596 |
+
|
| 597 |
+
@api_bp.route("/dbviewer/documents", methods=["GET"])
|
| 598 |
+
def dbviewer_documents():
|
| 599 |
+
"""List documents for the database viewer with pagination.
|
| 600 |
+
|
| 601 |
+
Query params:
|
| 602 |
+
page (default 1)
|
| 603 |
+
limit (default 25, max 100)
|
| 604 |
+
|
| 605 |
+
Returns documents with pagination info.
|
| 606 |
+
"""
|
| 607 |
+
try:
|
| 608 |
+
page = int(request.args.get("page", 1))
|
| 609 |
+
limit = int(request.args.get("limit", 25))
|
| 610 |
+
except ValueError:
|
| 611 |
+
return jsonify({"error": "invalid pagination parameters"}), 400
|
| 612 |
+
|
| 613 |
+
page = max(1, page)
|
| 614 |
+
limit = max(1, min(limit, 100))
|
| 615 |
+
offset = (page - 1) * limit
|
| 616 |
+
|
| 617 |
+
docs = get_documents(limit=limit, offset=offset)
|
| 618 |
+
|
| 619 |
+
if not docs:
|
| 620 |
+
return jsonify({
|
| 621 |
+
"documents": [],
|
| 622 |
+
"page": page,
|
| 623 |
+
"limit": limit,
|
| 624 |
+
"total": 0,
|
| 625 |
+
"total_pages": 0
|
| 626 |
+
}), 200
|
| 627 |
+
|
| 628 |
+
# Get chunk counts for all documents
|
| 629 |
+
ids = [int(getattr(d, 'doc_id')) for d in docs]
|
| 630 |
+
counts = get_document_chunk_counts(ids)
|
| 631 |
+
|
| 632 |
+
# Get total count for pagination (this is approximate)
|
| 633 |
+
# We'll fetch one more page to see if there are more documents
|
| 634 |
+
next_docs = get_documents(limit=1, offset=offset + limit)
|
| 635 |
+
has_more = len(next_docs) > 0
|
| 636 |
+
|
| 637 |
+
out = []
|
| 638 |
+
for d in docs:
|
| 639 |
+
doc_data = {
|
| 640 |
+
"doc_id": int(getattr(d, 'doc_id')),
|
| 641 |
+
"sha256": d.sha256,
|
| 642 |
+
"title": d.title,
|
| 643 |
+
"source_path": d.source_path,
|
| 644 |
+
"created_at": d.created_at.isoformat() if getattr(d, 'created_at', None) else None,
|
| 645 |
+
"doc_type": getattr(d, "doc_type", None),
|
| 646 |
+
"jurisdiction": getattr(d, "jurisdiction", None),
|
| 647 |
+
"governing_law": getattr(d, "governing_law", None),
|
| 648 |
+
"party_roles": getattr(d, "party_roles", None),
|
| 649 |
+
"industry": getattr(d, "industry", None),
|
| 650 |
+
"effective_date": d.effective_date.isoformat() if d.effective_date else None,
|
| 651 |
+
"chunk_count": counts.get(int(getattr(d, 'doc_id')), 0),
|
| 652 |
+
}
|
| 653 |
+
out.append(doc_data)
|
| 654 |
+
|
| 655 |
+
# Estimate total for pagination
|
| 656 |
+
estimated_total = offset + len(out) + (100 if has_more else 0)
|
| 657 |
+
estimated_pages = max(1, (estimated_total + limit - 1) // limit)
|
| 658 |
+
|
| 659 |
+
return jsonify({
|
| 660 |
+
"documents": out,
|
| 661 |
+
"page": page,
|
| 662 |
+
"limit": limit,
|
| 663 |
+
"count": len(out),
|
| 664 |
+
"has_more": has_more,
|
| 665 |
+
"estimated_total": estimated_total,
|
| 666 |
+
"estimated_pages": estimated_pages
|
| 667 |
+
}), 200
|
| 668 |
+
|
| 669 |
+
|
| 670 |
+
@api_bp.route("/dbviewer/chunks", methods=["GET"])
|
| 671 |
+
def dbviewer_chunks():
|
| 672 |
+
"""List chunks for the database viewer with pagination.
|
| 673 |
+
|
| 674 |
+
Query params:
|
| 675 |
+
page (default 1)
|
| 676 |
+
limit (default 25, max 100)
|
| 677 |
+
|
| 678 |
+
Returns chunks with pagination info.
|
| 679 |
+
"""
|
| 680 |
+
try:
|
| 681 |
+
page = int(request.args.get("page", 1))
|
| 682 |
+
limit = int(request.args.get("limit", 25))
|
| 683 |
+
except ValueError:
|
| 684 |
+
return jsonify({"error": "invalid pagination parameters"}), 400
|
| 685 |
+
|
| 686 |
+
page = max(1, page)
|
| 687 |
+
limit = max(1, min(limit, 100))
|
| 688 |
+
offset = (page - 1) * limit
|
| 689 |
+
|
| 690 |
+
rows = get_all_chunks(limit=limit, offset=offset)
|
| 691 |
+
|
| 692 |
+
if not rows:
|
| 693 |
+
return jsonify({
|
| 694 |
+
"chunks": [],
|
| 695 |
+
"page": page,
|
| 696 |
+
"limit": limit,
|
| 697 |
+
"total": 0,
|
| 698 |
+
"total_pages": 0
|
| 699 |
+
}), 200
|
| 700 |
+
|
| 701 |
+
# Get embedding counts for all chunks
|
| 702 |
+
chunk_ids = [c.chunk_id for c in rows]
|
| 703 |
+
embedding_counts = get_embedding_counts_for_chunks(chunk_ids)
|
| 704 |
+
|
| 705 |
+
# Check if there are more chunks
|
| 706 |
+
next_chunks = get_all_chunks(limit=1, offset=offset + limit)
|
| 707 |
+
has_more = len(next_chunks) > 0
|
| 708 |
+
|
| 709 |
+
out = []
|
| 710 |
+
for c in rows:
|
| 711 |
+
chunk_data = {
|
| 712 |
+
"chunk_id": c.chunk_id,
|
| 713 |
+
"doc_id": c.doc_id,
|
| 714 |
+
"chunk_index": c.chunk_index,
|
| 715 |
+
"token_count": c.token_count,
|
| 716 |
+
"tok_ver": c.tok_ver,
|
| 717 |
+
"seg_ver": c.seg_ver,
|
| 718 |
+
"text": str(getattr(c, 'text', '') or ''),
|
| 719 |
+
"page_start": c.page_start,
|
| 720 |
+
"page_end": c.page_end,
|
| 721 |
+
"section_number": c.section_number,
|
| 722 |
+
"section_title": c.section_title,
|
| 723 |
+
"clause_type": c.clause_type,
|
| 724 |
+
"path": c.path,
|
| 725 |
+
"numbers_present": c.numbers_present,
|
| 726 |
+
"definition_terms": c.definition_terms,
|
| 727 |
+
"embedding_count": embedding_counts.get(c.chunk_id, 0),
|
| 728 |
+
}
|
| 729 |
+
out.append(chunk_data)
|
| 730 |
+
|
| 731 |
+
# Estimate total for pagination
|
| 732 |
+
estimated_total = offset + len(out) + (100 if has_more else 0)
|
| 733 |
+
estimated_pages = max(1, (estimated_total + limit - 1) // limit)
|
| 734 |
+
|
| 735 |
+
return jsonify({
|
| 736 |
+
"chunks": out,
|
| 737 |
+
"page": page,
|
| 738 |
+
"limit": limit,
|
| 739 |
+
"count": len(out),
|
| 740 |
+
"has_more": has_more,
|
| 741 |
+
"estimated_total": estimated_total,
|
| 742 |
+
"estimated_pages": estimated_pages
|
| 743 |
+
}), 200
|
routes/web.py
CHANGED
|
@@ -14,10 +14,10 @@ def upload():
|
|
| 14 |
def manifest_status():
|
| 15 |
return render_template('manifest.html')
|
| 16 |
|
| 17 |
-
@web_bp.route('/
|
| 18 |
def chunk_status():
|
| 19 |
return render_template('chunks.html')
|
| 20 |
|
| 21 |
-
@web_bp.route('/db-
|
| 22 |
-
def
|
| 23 |
-
return render_template('
|
|
|
|
| 14 |
def manifest_status():
|
| 15 |
return render_template('manifest.html')
|
| 16 |
|
| 17 |
+
@web_bp.route('/chunks')
|
| 18 |
def chunk_status():
|
| 19 |
return render_template('chunks.html')
|
| 20 |
|
| 21 |
+
@web_bp.route('/db-viewer')
|
| 22 |
+
def db_viewer():
|
| 23 |
+
return render_template('dbviewer.html')
|
static/chunks.html
CHANGED
|
@@ -23,29 +23,17 @@
|
|
| 23 |
button.secondary{background:rgba(255,102,102,.45);color:#fff;box-shadow:none}
|
| 24 |
button.secondary:hover{background:rgba(255,102,102,.6)}
|
| 25 |
.status{font-size:.75rem;color:#ccc;min-height:18px}
|
| 26 |
-
|
| 27 |
-
.view-toggles{display:flex;gap:10px;flex-wrap:wrap}
|
| 28 |
-
.view-toggles button{background:#2d3f4d;color:#cfe9ff;box-shadow:none;padding:8px 14px;font-size:.65rem}
|
| 29 |
-
.view-toggles button.active{background:#7ec8ff;color:#001122}
|
| 30 |
.summary{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:14px}
|
| 31 |
.kv{background:#222;border:2px solid #555;border-radius:12px;padding:10px 12px;display:flex;flex-direction:column;gap:4px}
|
| 32 |
.kv span.k{font-size:.6rem;text-transform:uppercase;letter-spacing:1px;color:#999}
|
| 33 |
.kv span.v{font-size:.8rem;word-break:break-word}
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
.truncate{max-width:420px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
| 41 |
-
.chunk{background:#1b2733;border:1px solid #3d4c55;border-radius:14px;padding:16px 18px;display:flex;flex-direction:column;gap:10px;position:relative}
|
| 42 |
-
.chunk h3{margin:0;font-size:.85rem;font-weight:600}
|
| 43 |
-
.meta-row{display:flex;flex-wrap:wrap;gap:6px;font-size:.55rem;letter-spacing:.5px}
|
| 44 |
-
.tag{background:#2d3f4d;color:#cfe9ff;font-size:.55rem;padding:4px 8px;border-radius:100px;text-transform:uppercase}
|
| 45 |
-
.text{font-family:Consolas,Monaco,monospace;font-size:.7rem;line-height:1.35;white-space:pre-wrap;word-break:break-word;max-height:220px;overflow:hidden;position:relative}
|
| 46 |
-
.text.expanded{max-height:none}
|
| 47 |
-
.expand-btn{position:absolute;bottom:0;right:0;background:linear-gradient(90deg,rgba(0,0,0,0),#1b2733 60%);padding:4px 8px;font-size:.55rem;border:none;color:#87CEFA;cursor:pointer}
|
| 48 |
-
.expand-btn:hover{text-decoration:underline}
|
| 49 |
.toolbar{display:flex;flex-wrap:wrap;gap:10px}
|
| 50 |
.toolbar input{background:#222;border:2px solid #555;border-radius:10px;padding:8px 10px;color:#fff;font-size:.75rem;min-width:220px}
|
| 51 |
.toolbar input:focus{outline:none;border-color:#7ec8ff;box-shadow:0 0 0 3px rgba(126,200,255,.15)}
|
|
@@ -55,20 +43,32 @@
|
|
| 55 |
.spinner{width:18px;height:18px;border:3px solid rgba(255,255,255,.2);border-top-color:#7ec8ff;border-radius:50%;animation:spin 1s linear infinite}
|
| 56 |
@keyframes spin{to{transform:rotate(360deg)}}
|
| 57 |
@media (max-width:900px){.panel{padding:22px 20px}h1{font-size:1.7rem}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
</style>
|
| 59 |
</head>
|
| 60 |
<body>
|
| 61 |
<div class="shell">
|
| 62 |
<div class="panel">
|
| 63 |
<h1>Chunks Explorer</h1>
|
| 64 |
-
<p class="sub">
|
| 65 |
<form id="queryForm" class="query" autocomplete="off">
|
| 66 |
<div>
|
| 67 |
<label for="docId">Document ID</label>
|
| 68 |
-
<input type="number" id="docId" min="1" placeholder="e.g., 12"
|
| 69 |
</div>
|
| 70 |
<div>
|
| 71 |
-
<label for="filter">Text Filter
|
| 72 |
<input type="text" id="filter" placeholder="filter text..." />
|
| 73 |
</div>
|
| 74 |
<div>
|
|
@@ -76,28 +76,27 @@
|
|
| 76 |
<input type="number" id="pageSize" min="5" max="200" value="25" />
|
| 77 |
</div>
|
| 78 |
<div style="display:flex;gap:8px;">
|
| 79 |
-
<button type="submit" id="fetchBtn">Fetch</button>
|
| 80 |
-
<button type="button" class="secondary" id="clearBtn">Clear</button>
|
| 81 |
</div>
|
| 82 |
</form>
|
| 83 |
<div class="toolbar">
|
| 84 |
-
<input type="text" id="sectionFilter" placeholder="filter by section
|
| 85 |
-
<input type="text" id="
|
|
|
|
|
|
|
|
|
|
| 86 |
</div>
|
| 87 |
<div class="status" id="status"></div>
|
| 88 |
</div>
|
| 89 |
|
| 90 |
-
<div class="panel results" id="resultsPanel"
|
| 91 |
<div style="display:flex;gap:10px;flex-wrap:wrap;align-items:center;margin-bottom:6px;">
|
| 92 |
-
<
|
| 93 |
-
<button type="button" id="cardsMode" class="active">Cards</button>
|
| 94 |
-
<button type="button" id="tableMode">Table</button>
|
| 95 |
-
</div>
|
| 96 |
<button type="button" id="globalMode" class="secondary" style="margin-left:auto;">Show All Chunks</button>
|
|
|
|
| 97 |
</div>
|
| 98 |
<div class="summary" id="summary"></div>
|
| 99 |
-
<div class="
|
| 100 |
-
<div class="table-wrapper" id="tableWrapper" style="display:none;"></div>
|
| 101 |
<div class="pagination" id="pagination"></div>
|
| 102 |
</div>
|
| 103 |
</div>
|
|
@@ -107,195 +106,391 @@
|
|
| 107 |
const docIdInput = document.getElementById('docId');
|
| 108 |
const filterInput = document.getElementById('filter');
|
| 109 |
const sectionFilter = document.getElementById('sectionFilter');
|
| 110 |
-
const
|
| 111 |
const pageSizeInput = document.getElementById('pageSize');
|
| 112 |
const statusEl = document.getElementById('status');
|
| 113 |
const summaryEl = document.getElementById('summary');
|
| 114 |
-
|
| 115 |
-
const tableWrapper = document.getElementById('tableWrapper');
|
| 116 |
-
const cardsModeBtn = document.getElementById('cardsMode');
|
| 117 |
-
const tableModeBtn = document.getElementById('tableMode');
|
| 118 |
const paginationEl = document.getElementById('pagination');
|
| 119 |
const clearBtn = document.getElementById('clearBtn');
|
| 120 |
-
|
| 121 |
-
|
|
|
|
| 122 |
|
| 123 |
let rawChunks = [];
|
| 124 |
let currentPage = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
-
function
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
-
|
| 131 |
spinner();
|
| 132 |
fetch(`/api/chunks?doc_id=${encodeURIComponent(docId)}`)
|
| 133 |
-
.then(r=>r.json())
|
| 134 |
-
.then(data=>{
|
| 135 |
-
if
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
buildSummary(data);
|
| 139 |
-
currentPage=1;
|
| 140 |
render();
|
| 141 |
-
resultsPanel.style.display='block';
|
| 142 |
})
|
| 143 |
-
.catch(err=>
|
|
|
|
|
|
|
|
|
|
| 144 |
}
|
| 145 |
|
| 146 |
-
function
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
const meta = {
|
| 151 |
-
doc_id: apiData.doc_id,
|
| 152 |
total_chunks: rawChunks.length,
|
| 153 |
first_chunk_id: rawChunks[0]?.chunk_id,
|
| 154 |
last_chunk_id: last?.chunk_id,
|
| 155 |
token_version: last?.tok_ver,
|
| 156 |
segment_version: last?.seg_ver
|
| 157 |
};
|
| 158 |
-
|
| 159 |
-
|
|
|
|
|
|
|
| 160 |
});
|
| 161 |
}
|
| 162 |
|
| 163 |
-
function
|
| 164 |
-
setStatus('');
|
| 165 |
-
summaryEl.innerHTML='';
|
| 166 |
-
spinner();
|
| 167 |
-
const limit = Math.max(50, Math.min(500, parseInt(pageSizeInput.value,10)||200));
|
| 168 |
-
fetch(`/api/chunks/all?limit=${limit}`)
|
| 169 |
-
.then(r=>r.json())
|
| 170 |
-
.then(data => {
|
| 171 |
-
rawChunks = Array.isArray(data.chunks)?data.chunks:[];
|
| 172 |
-
setStatus(rawChunks.length?`Loaded ${rawChunks.length} chunk(s) (global slice).`:'No chunks.');
|
| 173 |
-
currentPage=1; render();
|
| 174 |
-
})
|
| 175 |
-
.catch(err=>{ setStatus('Failed to load global chunks: '+err.message,true); });
|
| 176 |
-
}
|
| 177 |
-
|
| 178 |
-
function applyFilters(list){
|
| 179 |
const t = filterInput.value.trim().toLowerCase();
|
| 180 |
const s = sectionFilter.value.trim().toLowerCase();
|
| 181 |
-
const
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
if(
|
| 185 |
-
if(
|
|
|
|
| 186 |
return true;
|
| 187 |
});
|
| 188 |
}
|
| 189 |
|
| 190 |
-
function
|
| 191 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
}
|
| 193 |
|
| 194 |
-
function
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
|
|
|
| 202 |
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
attachExpandHandlers();
|
| 207 |
} else {
|
| 208 |
-
|
|
|
|
| 209 |
}
|
| 210 |
-
|
|
|
|
| 211 |
}
|
| 212 |
|
| 213 |
-
function
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
}
|
| 233 |
|
| 234 |
-
function
|
| 235 |
-
const
|
| 236 |
-
const
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
if(
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
|
|
|
| 246 |
}
|
| 247 |
|
| 248 |
-
function
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
}
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
} else {
|
| 274 |
-
|
| 275 |
-
cell.dataset.expanded='1';
|
| 276 |
}
|
| 277 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
});
|
| 279 |
-
}
|
|
|
|
|
|
|
| 280 |
}
|
| 281 |
|
| 282 |
-
function
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
}
|
| 290 |
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
|
| 298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
</script>
|
| 300 |
</body>
|
| 301 |
</html>
|
|
|
|
| 23 |
button.secondary{background:rgba(255,102,102,.45);color:#fff;box-shadow:none}
|
| 24 |
button.secondary:hover{background:rgba(255,102,102,.6)}
|
| 25 |
.status{font-size:.75rem;color:#ccc;min-height:18px}
|
| 26 |
+
.results{display:flex;flex-direction:column;gap:22px}
|
|
|
|
|
|
|
|
|
|
| 27 |
.summary{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:14px}
|
| 28 |
.kv{background:#222;border:2px solid #555;border-radius:12px;padding:10px 12px;display:flex;flex-direction:column;gap:4px}
|
| 29 |
.kv span.k{font-size:.6rem;text-transform:uppercase;letter-spacing:1px;color:#999}
|
| 30 |
.kv span.v{font-size:.8rem;word-break:break-word}
|
| 31 |
+
.table-wrapper{background:#222;border:2px solid #555;border-radius:16px;padding:14px 18px;max-height:60vh;overflow:auto}
|
| 32 |
+
table.data-table{width:100%;border-collapse:collapse;font-size:.65rem}
|
| 33 |
+
table.data-table th,table.data-table td{padding:6px 8px;text-align:left;border:1px solid #444;vertical-align:top}
|
| 34 |
+
table.data-table th{position:sticky;top:0;background:#2d3f4d;z-index:2;font-weight:600;letter-spacing:.5px}
|
| 35 |
+
table.data-table tbody tr:nth-child(even){background:#1e2a33}
|
| 36 |
+
.truncate{max-width:350px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
.toolbar{display:flex;flex-wrap:wrap;gap:10px}
|
| 38 |
.toolbar input{background:#222;border:2px solid #555;border-radius:10px;padding:8px 10px;color:#fff;font-size:.75rem;min-width:220px}
|
| 39 |
.toolbar input:focus{outline:none;border-color:#7ec8ff;box-shadow:0 0 0 3px rgba(126,200,255,.15)}
|
|
|
|
| 43 |
.spinner{width:18px;height:18px;border:3px solid rgba(255,255,255,.2);border-top-color:#7ec8ff;border-radius:50%;animation:spin 1s linear infinite}
|
| 44 |
@keyframes spin{to{transform:rotate(360deg)}}
|
| 45 |
@media (max-width:900px){.panel{padding:22px 20px}h1{font-size:1.7rem}}
|
| 46 |
+
|
| 47 |
+
/* Edit mode styles */
|
| 48 |
+
tr.editing { background:#283745 !important; }
|
| 49 |
+
td.editable { cursor:text; }
|
| 50 |
+
td.editable:hover { background:#203240; }
|
| 51 |
+
.row-actions { display:flex; gap:6px; }
|
| 52 |
+
.row-actions button { padding:4px 10px; font-size:.6rem; background:#355064; color:#cfe9ff; }
|
| 53 |
+
.row-actions button.confirm { background:#4caf50; color:#fff; }
|
| 54 |
+
.row-actions button.cancel { background:#d9534f; color:#fff; }
|
| 55 |
+
th.sortable { cursor:pointer; user-select:none; }
|
| 56 |
+
th.sortable:hover { background:#355064; }
|
| 57 |
+
th.sortable .indicator { font-size:.55rem; margin-left:4px; opacity:.8; }
|
| 58 |
</style>
|
| 59 |
</head>
|
| 60 |
<body>
|
| 61 |
<div class="shell">
|
| 62 |
<div class="panel">
|
| 63 |
<h1>Chunks Explorer</h1>
|
| 64 |
+
<p class="sub">Paginated table view of chunks data with inline editing capabilities. Shows key fields from chunks database including metadata.</p>
|
| 65 |
<form id="queryForm" class="query" autocomplete="off">
|
| 66 |
<div>
|
| 67 |
<label for="docId">Document ID</label>
|
| 68 |
+
<input type="number" id="docId" min="1" placeholder="e.g., 12" />
|
| 69 |
</div>
|
| 70 |
<div>
|
| 71 |
+
<label for="filter">Text Filter</label>
|
| 72 |
<input type="text" id="filter" placeholder="filter text..." />
|
| 73 |
</div>
|
| 74 |
<div>
|
|
|
|
| 76 |
<input type="number" id="pageSize" min="5" max="200" value="25" />
|
| 77 |
</div>
|
| 78 |
<div style="display:flex;gap:8px;">
|
| 79 |
+
<button type="submit" id="fetchBtn">Fetch by Doc ID</button>
|
|
|
|
| 80 |
</div>
|
| 81 |
</form>
|
| 82 |
<div class="toolbar">
|
| 83 |
+
<input type="text" id="sectionFilter" placeholder="filter by section title" />
|
| 84 |
+
<input type="text" id="clauseFilter" placeholder="filter by clause type" />
|
| 85 |
+
<div style="display:flex;gap:8px;">
|
| 86 |
+
<button type="button" class="secondary" id="clearBtn">Clear</button>
|
| 87 |
+
</div>
|
| 88 |
</div>
|
| 89 |
<div class="status" id="status"></div>
|
| 90 |
</div>
|
| 91 |
|
| 92 |
+
<div class="panel results" id="resultsPanel">
|
| 93 |
<div style="display:flex;gap:10px;flex-wrap:wrap;align-items:center;margin-bottom:6px;">
|
| 94 |
+
<h2 style="font-size:1.2rem;margin:0;">Chunks Data</h2>
|
|
|
|
|
|
|
|
|
|
| 95 |
<button type="button" id="globalMode" class="secondary" style="margin-left:auto;">Show All Chunks</button>
|
| 96 |
+
<div style="font-size:.65rem;letter-spacing:1px;color:#ccc;">Total: <span id="rowCount">0</span></div>
|
| 97 |
</div>
|
| 98 |
<div class="summary" id="summary"></div>
|
| 99 |
+
<div class="table-wrapper" id="tableWrapper"></div>
|
|
|
|
| 100 |
<div class="pagination" id="pagination"></div>
|
| 101 |
</div>
|
| 102 |
</div>
|
|
|
|
| 106 |
const docIdInput = document.getElementById('docId');
|
| 107 |
const filterInput = document.getElementById('filter');
|
| 108 |
const sectionFilter = document.getElementById('sectionFilter');
|
| 109 |
+
const clauseFilter = document.getElementById('clauseFilter');
|
| 110 |
const pageSizeInput = document.getElementById('pageSize');
|
| 111 |
const statusEl = document.getElementById('status');
|
| 112 |
const summaryEl = document.getElementById('summary');
|
| 113 |
+
const tableWrapper = document.getElementById('tableWrapper');
|
|
|
|
|
|
|
|
|
|
| 114 |
const paginationEl = document.getElementById('pagination');
|
| 115 |
const clearBtn = document.getElementById('clearBtn');
|
| 116 |
+
const resultsPanel = document.getElementById('resultsPanel');
|
| 117 |
+
const globalModeBtn = document.getElementById('globalMode');
|
| 118 |
+
const rowCountEl = document.getElementById('rowCount');
|
| 119 |
|
| 120 |
let rawChunks = [];
|
| 121 |
let currentPage = 1;
|
| 122 |
+
let sortCol = 'chunk_id';
|
| 123 |
+
let sortDir = 'asc';
|
| 124 |
+
let editing = { rowChunkId: null, col: null };
|
| 125 |
+
|
| 126 |
+
const PAGE_SIZE = 25;
|
| 127 |
+
|
| 128 |
+
function esc(v) {
|
| 129 |
+
return String(v ?? '').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
| 130 |
+
}
|
| 131 |
|
| 132 |
+
function setStatus(msg, isErr=false) {
|
| 133 |
+
statusEl.innerHTML = msg ? `<span style="${isErr ? 'color:#ff7b7b;font-weight:600;' : ''}">${esc(msg)}</span>` : '';
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
function spinner() {
|
| 137 |
+
setStatus(`<span style='display:inline-flex;align-items:center;gap:8px;'><span class="spinner"></span> Loading...</span>`);
|
| 138 |
+
}
|
| 139 |
|
| 140 |
+
function fetchChunks(docId) {
|
| 141 |
spinner();
|
| 142 |
fetch(`/api/chunks?doc_id=${encodeURIComponent(docId)}`)
|
| 143 |
+
.then(r => r.json())
|
| 144 |
+
.then(data => {
|
| 145 |
+
if (data.error) {
|
| 146 |
+
setStatus(data.error, true);
|
| 147 |
+
resultsPanel.style.display = 'none';
|
| 148 |
+
return;
|
| 149 |
+
}
|
| 150 |
+
rawChunks = Array.isArray(data.chunks) ? data.chunks : [];
|
| 151 |
+
setStatus(rawChunks.length ? `Loaded ${rawChunks.length} chunk(s).` : 'No chunks.');
|
| 152 |
buildSummary(data);
|
| 153 |
+
currentPage = 1;
|
| 154 |
render();
|
| 155 |
+
resultsPanel.style.display = 'block';
|
| 156 |
})
|
| 157 |
+
.catch(err => {
|
| 158 |
+
setStatus('Failed to load chunks: ' + err.message, true);
|
| 159 |
+
resultsPanel.style.display = 'none';
|
| 160 |
+
});
|
| 161 |
}
|
| 162 |
|
| 163 |
+
function fetchAllChunks() {
|
| 164 |
+
setStatus('');
|
| 165 |
+
summaryEl.innerHTML = '';
|
| 166 |
+
spinner();
|
| 167 |
+
const limit = Math.max(50, Math.min(500, parseInt(pageSizeInput.value, 10) || 200));
|
| 168 |
+
fetch(`/api/chunks/all?limit=${limit}`)
|
| 169 |
+
.then(r => r.json())
|
| 170 |
+
.then(data => {
|
| 171 |
+
rawChunks = Array.isArray(data.chunks) ? data.chunks : [];
|
| 172 |
+
setStatus(rawChunks.length ? `Loaded ${rawChunks.length} chunk(s) (global slice).` : 'No chunks.');
|
| 173 |
+
currentPage = 1;
|
| 174 |
+
render();
|
| 175 |
+
resultsPanel.style.display = 'block';
|
| 176 |
+
})
|
| 177 |
+
.catch(err => {
|
| 178 |
+
setStatus('Failed to load global chunks: ' + err.message, true);
|
| 179 |
+
});
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
function buildSummary(apiData) {
|
| 183 |
+
summaryEl.innerHTML = '';
|
| 184 |
+
if (!rawChunks.length) return;
|
| 185 |
+
|
| 186 |
+
const last = rawChunks[rawChunks.length - 1];
|
| 187 |
const meta = {
|
| 188 |
+
doc_id: apiData.doc_id || 'Global',
|
| 189 |
total_chunks: rawChunks.length,
|
| 190 |
first_chunk_id: rawChunks[0]?.chunk_id,
|
| 191 |
last_chunk_id: last?.chunk_id,
|
| 192 |
token_version: last?.tok_ver,
|
| 193 |
segment_version: last?.seg_ver
|
| 194 |
};
|
| 195 |
+
|
| 196 |
+
Object.entries(meta).forEach(([k, v]) => {
|
| 197 |
+
summaryEl.insertAdjacentHTML('beforeend',
|
| 198 |
+
`<div class="kv"><span class="k">${esc(k)}</span><span class="v">${esc(v)}</span></div>`);
|
| 199 |
});
|
| 200 |
}
|
| 201 |
|
| 202 |
+
function applyFilters(list) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
const t = filterInput.value.trim().toLowerCase();
|
| 204 |
const s = sectionFilter.value.trim().toLowerCase();
|
| 205 |
+
const c = clauseFilter.value.trim().toLowerCase();
|
| 206 |
+
|
| 207 |
+
return list.filter(chunk => {
|
| 208 |
+
if (t && !JSON.stringify(chunk).toLowerCase().includes(t)) return false;
|
| 209 |
+
if (s && !(chunk.section_title || '').toLowerCase().includes(s)) return false;
|
| 210 |
+
if (c && !(chunk.clause_type || '').toLowerCase().includes(c)) return false;
|
| 211 |
return true;
|
| 212 |
});
|
| 213 |
}
|
| 214 |
|
| 215 |
+
function compareValues(a, b) {
|
| 216 |
+
const an = parseFloat(a);
|
| 217 |
+
const bn = parseFloat(b);
|
| 218 |
+
const aNum = !isNaN(an) && String(an) === String(a).trim();
|
| 219 |
+
const bNum = !isNaN(bn) && String(bn) === String(b).trim();
|
| 220 |
+
|
| 221 |
+
if (aNum && bNum) {
|
| 222 |
+
if (an < bn) return -1;
|
| 223 |
+
if (an > bn) return 1;
|
| 224 |
+
return 0;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
const as = String(a).toLowerCase();
|
| 228 |
+
const bs = String(b).toLowerCase();
|
| 229 |
+
if (as < bs) return -1;
|
| 230 |
+
if (as > bs) return 1;
|
| 231 |
+
return 0;
|
| 232 |
}
|
| 233 |
|
| 234 |
+
function sortRows(rows) {
|
| 235 |
+
if (!sortCol) return rows;
|
| 236 |
+
return [...rows].sort((r1, r2) => {
|
| 237 |
+
const v1 = r1[sortCol] ?? '';
|
| 238 |
+
const v2 = r2[sortCol] ?? '';
|
| 239 |
+
const cmp = compareValues(v1, v2);
|
| 240 |
+
return sortDir === 'asc' ? cmp : -cmp;
|
| 241 |
+
});
|
| 242 |
+
}
|
| 243 |
|
| 244 |
+
function setSort(col) {
|
| 245 |
+
if (sortCol === col) {
|
| 246 |
+
sortDir = sortDir === 'asc' ? 'desc' : 'asc';
|
|
|
|
| 247 |
} else {
|
| 248 |
+
sortCol = col;
|
| 249 |
+
sortDir = 'asc';
|
| 250 |
}
|
| 251 |
+
currentPage = 1;
|
| 252 |
+
render();
|
| 253 |
}
|
| 254 |
|
| 255 |
+
function buildHeader(cols) {
|
| 256 |
+
return cols.map(c => {
|
| 257 |
+
const active = c === sortCol;
|
| 258 |
+
const indicator = active ? (sortDir === 'asc' ? '▲' : '▼') : '';
|
| 259 |
+
return `<th class="sortable" data-col="${esc(c)}">${esc(c)}<span class="indicator">${indicator}</span></th>`;
|
| 260 |
+
}).join('');
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
function paginate(rows) {
|
| 264 |
+
const pageSize = parseInt(pageSizeInput.value, 10) || PAGE_SIZE;
|
| 265 |
+
const pageCount = Math.max(1, Math.ceil(rows.length / pageSize));
|
| 266 |
+
if (currentPage > pageCount) currentPage = pageCount;
|
| 267 |
+
|
| 268 |
+
const start = (currentPage - 1) * pageSize;
|
| 269 |
+
const slice = rows.slice(start, start + pageSize);
|
| 270 |
+
|
| 271 |
+
updatePagination(currentPage, pageCount, slice.length, rows.length);
|
| 272 |
+
return slice;
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
function updatePagination(current, total, visible, totalRows) {
|
| 276 |
+
paginationEl.innerHTML = `
|
| 277 |
+
<button id="firstPage" ${current === 1 ? 'disabled' : ''} title="First">⏮</button>
|
| 278 |
+
<button id="prevPage" ${current === 1 ? 'disabled' : ''} title="Previous">◀</button>
|
| 279 |
+
<span>Page ${current} / ${total}</span>
|
| 280 |
+
<button id="nextPage" ${current === total ? 'disabled' : ''} title="Next">▶</button>
|
| 281 |
+
<button id="lastPage" ${current === total ? 'disabled' : ''} title="Last">⏭</button>
|
| 282 |
+
<span>| Rows: ${visible} / ${totalRows}</span>
|
| 283 |
+
`;
|
| 284 |
+
|
| 285 |
+
// Attach pagination event handlers
|
| 286 |
+
const firstBtn = document.getElementById('firstPage');
|
| 287 |
+
const prevBtn = document.getElementById('prevPage');
|
| 288 |
+
const nextBtn = document.getElementById('nextPage');
|
| 289 |
+
const lastBtn = document.getElementById('lastPage');
|
| 290 |
+
|
| 291 |
+
firstBtn?.addEventListener('click', () => { currentPage = 1; render(); });
|
| 292 |
+
prevBtn?.addEventListener('click', () => { if (currentPage > 1) { currentPage--; render(); } });
|
| 293 |
+
nextBtn?.addEventListener('click', () => { currentPage++; render(); });
|
| 294 |
+
lastBtn?.addEventListener('click', () => { currentPage = total; render(); });
|
| 295 |
+
|
| 296 |
+
paginationEl.style.display = totalRows ? 'flex' : 'none';
|
| 297 |
}
|
| 298 |
|
| 299 |
+
function render() {
|
| 300 |
+
const filtered = applyFilters(rawChunks);
|
| 301 |
+
const rows = sortRows(filtered);
|
| 302 |
+
rowCountEl.textContent = rows.length;
|
| 303 |
+
|
| 304 |
+
if (!rows.length) {
|
| 305 |
+
tableWrapper.innerHTML = '<div class="empty">No chunks match filters.</div>';
|
| 306 |
+
paginationEl.style.display = 'none';
|
| 307 |
+
return;
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
const pageRows = paginate(rows);
|
| 311 |
+
renderTable(pageRows);
|
| 312 |
}
|
| 313 |
|
| 314 |
+
function renderTable(pageRows) {
|
| 315 |
+
const cols = ["chunk_id", "doc_id", "text", "section_number", "section_title", "clause_type", "definition_terms", "embedding_count"];
|
| 316 |
+
|
| 317 |
+
let html = '<table class="data-table"><thead><tr>' + buildHeader(cols) + '</tr></thead><tbody>';
|
| 318 |
+
|
| 319 |
+
html += pageRows.map(r => {
|
| 320 |
+
const rid = esc(r.chunk_id);
|
| 321 |
+
let tds = cols.map(c => {
|
| 322 |
+
let val = r[c];
|
| 323 |
+
if (val == null) val = '';
|
| 324 |
+
let full = String(val);
|
| 325 |
+
let display = full;
|
| 326 |
+
|
| 327 |
+
const nonEditable = (c === 'chunk_id' || c === 'doc_id' || c === 'embedding_count');
|
| 328 |
+
|
| 329 |
+
if (c === 'text') {
|
| 330 |
+
// Truncate text to 350 characters unless editing
|
| 331 |
+
if (editing.rowChunkId === String(r.chunk_id) && editing.col === c) {
|
| 332 |
+
display = full; // Show full text when editing
|
| 333 |
+
} else {
|
| 334 |
+
display = full.length > 350 ? full.slice(0, 350) + '…' : full;
|
| 335 |
+
}
|
| 336 |
+
} else if (display.length > 160) {
|
| 337 |
+
display = display.slice(0, 160) + '…';
|
| 338 |
}
|
| 339 |
+
|
| 340 |
+
const cls = [
|
| 341 |
+
display !== full ? 'truncate' : '',
|
| 342 |
+
nonEditable ? '' : 'editable'
|
| 343 |
+
].filter(Boolean).join(' ');
|
| 344 |
+
|
| 345 |
+
let content = esc(display);
|
| 346 |
+
|
| 347 |
+
if (editing.rowChunkId === String(r.chunk_id) && editing.col === c && !nonEditable) {
|
| 348 |
+
if (c === 'text') {
|
| 349 |
+
content = `<textarea style="width:100%;height:80px;background:#16232d;border:1px solid #4a6578;color:#fff;font-size:.65rem;padding:4px 6px;border-radius:4px;resize:vertical;" placeholder="Enter text...">${esc(full)}</textarea>`;
|
| 350 |
} else {
|
| 351 |
+
content = `<input type="text" style="width:100%;background:#16232d;border:1px solid #4a6578;color:#fff;font-size:.65rem;padding:4px 6px;border-radius:4px;" value="${esc(full)}" />`;
|
|
|
|
| 352 |
}
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
return `<td data-col="${esc(c)}" data-chunk="${rid}" class="${cls}" title="${esc(full)}">${content}</td>`;
|
| 356 |
+
}).join('');
|
| 357 |
+
|
| 358 |
+
// Add action buttons if this row is being edited
|
| 359 |
+
const actionTd = editing.rowChunkId === String(r.chunk_id) ?
|
| 360 |
+
`<td class="row-actions"><button class="confirm">Save</button><button class="cancel">Cancel</button></td>` :
|
| 361 |
+
`<td></td>`;
|
| 362 |
+
|
| 363 |
+
const rowClass = editing.rowChunkId === String(r.chunk_id) ? 'editing' : '';
|
| 364 |
+
return `<tr data-chunk="${rid}" class="${rowClass}">${tds}${actionTd}</tr>`;
|
| 365 |
+
}).join('');
|
| 366 |
+
|
| 367 |
+
html += '</tbody></table>';
|
| 368 |
+
tableWrapper.innerHTML = html;
|
| 369 |
+
|
| 370 |
+
// Header sort handlers
|
| 371 |
+
tableWrapper.querySelectorAll('th.sortable').forEach(th => {
|
| 372 |
+
th.addEventListener('click', () => {
|
| 373 |
+
const col = th.getAttribute('data-col');
|
| 374 |
+
if (col) setSort(col);
|
| 375 |
});
|
| 376 |
+
});
|
| 377 |
+
|
| 378 |
+
attachEditHandlers();
|
| 379 |
}
|
| 380 |
|
| 381 |
+
function attachEditHandlers() {
|
| 382 |
+
// Cell editing
|
| 383 |
+
tableWrapper.querySelectorAll('td.editable').forEach(td => {
|
| 384 |
+
td.addEventListener('click', () => beginCellEdit(td));
|
| 385 |
+
});
|
| 386 |
+
|
| 387 |
+
// Save/cancel handlers if visible
|
| 388 |
+
tableWrapper.querySelectorAll('tr').forEach(tr => {
|
| 389 |
+
const chunkId = tr.getAttribute('data-chunk');
|
| 390 |
+
if (!chunkId) return;
|
| 391 |
+
|
| 392 |
+
const confirmBtn = tr.querySelector('button.confirm');
|
| 393 |
+
const cancelBtn = tr.querySelector('button.cancel');
|
| 394 |
+
|
| 395 |
+
if (confirmBtn) confirmBtn.addEventListener('click', () => confirmCellEdit(chunkId));
|
| 396 |
+
if (cancelBtn) cancelBtn.addEventListener('click', cancelCellEdit);
|
| 397 |
+
});
|
| 398 |
}
|
| 399 |
|
| 400 |
+
function beginCellEdit(td) {
|
| 401 |
+
const tr = td.closest('tr');
|
| 402 |
+
const chunkId = tr.getAttribute('data-chunk');
|
| 403 |
+
const col = td.getAttribute('data-col');
|
| 404 |
+
|
| 405 |
+
if (!col || col === 'chunk_id' || col === 'doc_id' || col === 'embedding_count') return;
|
| 406 |
+
|
| 407 |
+
// Only one cell at a time
|
| 408 |
+
editing = { rowChunkId: String(chunkId), col };
|
| 409 |
+
render();
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
function cancelCellEdit() {
|
| 413 |
+
editing = { rowChunkId: null, col: null };
|
| 414 |
+
render();
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
function confirmCellEdit(chunkId) {
|
| 418 |
+
const row = tableWrapper.querySelector(`tr[data-chunk="${CSS.escape(chunkId)}"]`);
|
| 419 |
+
if (!row) return;
|
| 420 |
+
|
| 421 |
+
const cell = row.querySelector(`td[data-col="${CSS.escape(editing.col)}"] input, td[data-col="${CSS.escape(editing.col)}"] textarea`);
|
| 422 |
+
if (!cell) {
|
| 423 |
+
cancelCellEdit();
|
| 424 |
+
return;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
const newVal = cell.value.trim();
|
| 428 |
+
const updates = { [editing.col]: newVal };
|
| 429 |
+
|
| 430 |
+
setStatus('Saving…');
|
| 431 |
+
|
| 432 |
+
fetch('/api/chunks', {
|
| 433 |
+
method: 'PATCH',
|
| 434 |
+
headers: { 'Content-Type': 'application/json' },
|
| 435 |
+
body: JSON.stringify({ chunk_id: parseInt(chunkId), updates })
|
| 436 |
+
})
|
| 437 |
+
.then(r => r.json().then(j => ({ ok: r.ok, data: j })))
|
| 438 |
+
.then(res => {
|
| 439 |
+
if (!res.ok) {
|
| 440 |
+
setStatus(res.data.error || 'Save failed', true);
|
| 441 |
+
return;
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
// Update local data
|
| 445 |
+
const chunk = rawChunks.find(c => String(c.chunk_id) === String(chunkId));
|
| 446 |
+
if (chunk) {
|
| 447 |
+
chunk[editing.col] = newVal;
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
setStatus('Saved.');
|
| 451 |
+
cancelCellEdit();
|
| 452 |
+
})
|
| 453 |
+
.catch(err => setStatus('Save error: ' + err.message, true));
|
| 454 |
+
}
|
| 455 |
|
| 456 |
+
// Event listeners
|
| 457 |
+
form.addEventListener('submit', e => {
|
| 458 |
+
e.preventDefault();
|
| 459 |
+
const id = docIdInput.value.trim();
|
| 460 |
+
if (!id) {
|
| 461 |
+
setStatus('Document ID required', true);
|
| 462 |
+
return;
|
| 463 |
+
}
|
| 464 |
+
fetchChunks(id);
|
| 465 |
+
});
|
| 466 |
+
|
| 467 |
+
clearBtn.addEventListener('click', () => {
|
| 468 |
+
docIdInput.value = '';
|
| 469 |
+
filterInput.value = '';
|
| 470 |
+
sectionFilter.value = '';
|
| 471 |
+
clauseFilter.value = '';
|
| 472 |
+
rawChunks = [];
|
| 473 |
+
resultsPanel.style.display = 'none';
|
| 474 |
+
setStatus('');
|
| 475 |
+
});
|
| 476 |
+
|
| 477 |
+
[filterInput, sectionFilter, clauseFilter, pageSizeInput].forEach(inp =>
|
| 478 |
+
inp.addEventListener('input', () => { currentPage = 1; render(); })
|
| 479 |
+
);
|
| 480 |
+
|
| 481 |
+
globalModeBtn.addEventListener('click', () => {
|
| 482 |
+
fetchAllChunks();
|
| 483 |
+
});
|
| 484 |
+
|
| 485 |
+
// Initial load
|
| 486 |
+
const params = new URLSearchParams(window.location.search);
|
| 487 |
+
const qsId = params.get('doc_id');
|
| 488 |
+
if (qsId) {
|
| 489 |
+
docIdInput.value = qsId;
|
| 490 |
+
fetchChunks(qsId);
|
| 491 |
+
} else {
|
| 492 |
+
fetchAllChunks();
|
| 493 |
+
}
|
| 494 |
</script>
|
| 495 |
</body>
|
| 496 |
</html>
|
static/dbviewer.html
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
| 6 |
+
<title>Database Viewer</title>
|
| 7 |
+
<style>
|
| 8 |
+
* { margin:0; padding:0; box-sizing:border-box; }
|
| 9 |
+
body {
|
| 10 |
+
font-family:-apple-system,BlinkMacSystemFont,'SF Pro Rounded','SF Pro Display',Roboto,Oxygen,Ubuntu,Cantarell,sans-serif;
|
| 11 |
+
background:#001122; color:#fff; min-height:100vh; padding:28px; display:flex; flex-direction:column; gap:28px; align-items:center;
|
| 12 |
+
}
|
| 13 |
+
.shell { width:100%; max-width:1200px; display:flex; flex-direction:column; gap:26px; }
|
| 14 |
+
.panel { background:#333; border-radius:20px; padding:28px 32px; box-shadow:0 18px 50px rgba(0,0,0,.5); }
|
| 15 |
+
h1 { font-size:2.2rem; font-weight:500; text-shadow:0 4px 8px rgba(0,0,0,.5); margin:0 0 8px; }
|
| 16 |
+
p.sub { font-size:.8rem; color:#ccc; font-style:italic; line-height:1.5; }
|
| 17 |
+
a { color:#87CEFA; text-decoration:none; }
|
| 18 |
+
a:hover { text-decoration:underline; }
|
| 19 |
+
.status { font-size:.75rem; color:#ccc; margin-top:6px; min-height:18px; }
|
| 20 |
+
.view-toggles { display:flex; gap:10px; flex-wrap:wrap; margin-bottom:20px; }
|
| 21 |
+
.view-toggles button { background:#2d3f4d; color:#cfe9ff; box-shadow:none; padding:12px 20px; font-size:.8rem; border:none; border-radius:10px; cursor:pointer; transition:.25s; font-weight:600; }
|
| 22 |
+
.view-toggles button.active { background:#7ec8ff; color:#001122; }
|
| 23 |
+
.view-toggles button:hover { background:#355064; }
|
| 24 |
+
.view-toggles button.active:hover { background:#6bb8ff; }
|
| 25 |
+
.table-wrapper { background:#222; border:2px solid #555; border-radius:16px; padding:14px 18px; max-height:60vh; overflow:auto; }
|
| 26 |
+
table.data-table { width:100%; border-collapse:collapse; font-size:.7rem; }
|
| 27 |
+
table.data-table th, table.data-table td { padding:8px 10px; text-align:left; border:1px solid #444; vertical-align:top; }
|
| 28 |
+
table.data-table th { position:sticky; top:0; background:#2d3f4d; z-index:2; font-weight:600; letter-spacing:.5px; }
|
| 29 |
+
table.data-table tbody tr:nth-child(even){ background:#1e2a33; }
|
| 30 |
+
.truncate { max-width:150px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; cursor:pointer; }
|
| 31 |
+
.truncate:hover { background:#203240; }
|
| 32 |
+
.empty { text-align:center; font-style:italic; color:#ccc; padding:40px; }
|
| 33 |
+
.error { color:#ff7b7b; font-weight:600; }
|
| 34 |
+
.spinner { width:18px; height:18px; border:3px solid rgba(255,255,255,.2); border-top-color:#7ec8ff; border-radius:50%; animation:spin 1s linear infinite; }
|
| 35 |
+
.inline { display:inline-flex; align-items:center; gap:10px; }
|
| 36 |
+
@keyframes spin { to { transform:rotate(360deg);} }
|
| 37 |
+
.pagination { display:flex; gap:8px; align-items:center; flex-wrap:wrap; margin-top:16px; font-size:.7rem; }
|
| 38 |
+
.pagination button { padding:8px 12px; font-size:.7rem; background:#2d3f4d; color:#cfe9ff; box-shadow:none; border:none; border-radius:8px; cursor:pointer; transition:.25s; }
|
| 39 |
+
.pagination button:disabled { opacity:.35; cursor:not-allowed; }
|
| 40 |
+
.pagination button:hover:not(:disabled) { background:#355064; }
|
| 41 |
+
.pagination .current { color:#7ec8ff; font-weight:600; }
|
| 42 |
+
@media (max-width:800px){ .panel { padding:22px 20px; } h1 { font-size:1.7rem; } }
|
| 43 |
+
|
| 44 |
+
/* Modal styles for full content view */
|
| 45 |
+
.modal { display:none; position:fixed; z-index:1000; left:0; top:0; width:100%; height:100%; background:rgba(0,0,0,.8); }
|
| 46 |
+
.modal-content { background:#333; margin:5% auto; padding:20px; border-radius:15px; width:90%; max-width:800px; max-height:80vh; overflow:auto; }
|
| 47 |
+
.modal-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:15px; }
|
| 48 |
+
.modal-title { font-size:1.2rem; color:#7ec8ff; }
|
| 49 |
+
.close { color:#ccc; font-size:28px; font-weight:bold; cursor:pointer; }
|
| 50 |
+
.close:hover { color:#fff; }
|
| 51 |
+
.modal-body { background:#222; border:1px solid #555; border-radius:8px; padding:15px; font-family:monospace; font-size:.8rem; white-space:pre-wrap; }
|
| 52 |
+
|
| 53 |
+
.tab-content { display:none; }
|
| 54 |
+
.tab-content.active { display:block; }
|
| 55 |
+
.tab-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:15px; gap:10px; flex-wrap:wrap; }
|
| 56 |
+
.tab-info { font-size:.65rem; letter-spacing:1px; color:#ccc; }
|
| 57 |
+
</style>
|
| 58 |
+
</head>
|
| 59 |
+
<body>
|
| 60 |
+
<div class="shell">
|
| 61 |
+
<div class="panel">
|
| 62 |
+
<h1>Database Viewer</h1>
|
| 63 |
+
<p class="sub">Browse documents and chunks stored in the ChromaDB database. Values longer than 100 characters are truncated - click to view the complete content.</p>
|
| 64 |
+
|
| 65 |
+
<div class="view-toggles">
|
| 66 |
+
<button id="documentsTab" class="active" data-tab="documents">Documents</button>
|
| 67 |
+
<button id="chunksTab" data-tab="chunks">Chunks</button>
|
| 68 |
+
</div>
|
| 69 |
+
|
| 70 |
+
<div class="status" id="status"></div>
|
| 71 |
+
</div>
|
| 72 |
+
|
| 73 |
+
<!-- Documents Tab -->
|
| 74 |
+
<div class="panel tab-content active" id="documentsContent">
|
| 75 |
+
<div class="tab-header">
|
| 76 |
+
<h2 style="font-size:1.2rem;margin:0;">Documents Table</h2>
|
| 77 |
+
<div class="tab-info">
|
| 78 |
+
Page <span id="documentsPage">1</span> |
|
| 79 |
+
<span id="documentsCount">0</span> records
|
| 80 |
+
</div>
|
| 81 |
+
</div>
|
| 82 |
+
<div class="table-wrapper" id="documentsTableWrapper">
|
| 83 |
+
<div class="empty">Loading documents...</div>
|
| 84 |
+
</div>
|
| 85 |
+
<div class="pagination" id="documentsPagination" style="display:none;"></div>
|
| 86 |
+
</div>
|
| 87 |
+
|
| 88 |
+
<!-- Chunks Tab -->
|
| 89 |
+
<div class="panel tab-content" id="chunksContent">
|
| 90 |
+
<div class="tab-header">
|
| 91 |
+
<h2 style="font-size:1.2rem;margin:0;">Chunks Table</h2>
|
| 92 |
+
<div class="tab-info">
|
| 93 |
+
Page <span id="chunksPage">1</span> |
|
| 94 |
+
<span id="chunksCount">0</span> records
|
| 95 |
+
</div>
|
| 96 |
+
</div>
|
| 97 |
+
<div class="table-wrapper" id="chunksTableWrapper">
|
| 98 |
+
<div class="empty">Loading chunks...</div>
|
| 99 |
+
</div>
|
| 100 |
+
<div class="pagination" id="chunksPagination" style="display:none;"></div>
|
| 101 |
+
</div>
|
| 102 |
+
</div>
|
| 103 |
+
|
| 104 |
+
<!-- Modal for full content display -->
|
| 105 |
+
<div id="contentModal" class="modal">
|
| 106 |
+
<div class="modal-content">
|
| 107 |
+
<div class="modal-header">
|
| 108 |
+
<span class="modal-title" id="modalTitle">Content</span>
|
| 109 |
+
<span class="close">×</span>
|
| 110 |
+
</div>
|
| 111 |
+
<div class="modal-body" id="modalBody"></div>
|
| 112 |
+
</div>
|
| 113 |
+
</div>
|
| 114 |
+
|
| 115 |
+
<div style="text-align: center; margin-top: 20px;">
|
| 116 |
+
<a href="/" style="color: #87CEFA; text-decoration: none; font-size: 1rem; padding: 10px 20px; border: 1px solid #87CEFA; border-radius: 10px; transition: all 0.3s ease;" onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration='none'">
|
| 117 |
+
← Back to Home
|
| 118 |
+
</a>
|
| 119 |
+
</div>
|
| 120 |
+
|
| 121 |
+
<script>
|
| 122 |
+
// Global state
|
| 123 |
+
let currentTab = 'documents';
|
| 124 |
+
let documentsPage = 1;
|
| 125 |
+
let chunksPage = 1;
|
| 126 |
+
const PAGE_SIZE = 25;
|
| 127 |
+
|
| 128 |
+
// Elements
|
| 129 |
+
const statusEl = document.getElementById('status');
|
| 130 |
+
const modal = document.getElementById('contentModal');
|
| 131 |
+
const modalTitle = document.getElementById('modalTitle');
|
| 132 |
+
const modalBody = document.getElementById('modalBody');
|
| 133 |
+
const closeModal = document.querySelector('.close');
|
| 134 |
+
|
| 135 |
+
// Tab elements
|
| 136 |
+
const documentsTab = document.getElementById('documentsTab');
|
| 137 |
+
const chunksTab = document.getElementById('chunksTab');
|
| 138 |
+
const documentsContent = document.getElementById('documentsContent');
|
| 139 |
+
const chunksContent = document.getElementById('chunksContent');
|
| 140 |
+
|
| 141 |
+
// Table elements
|
| 142 |
+
const documentsTableWrapper = document.getElementById('documentsTableWrapper');
|
| 143 |
+
const chunksTableWrapper = document.getElementById('chunksTableWrapper');
|
| 144 |
+
const documentsPagination = document.getElementById('documentsPagination');
|
| 145 |
+
const chunksPagination = document.getElementById('chunksPagination');
|
| 146 |
+
|
| 147 |
+
// Status elements
|
| 148 |
+
const documentsPageEl = document.getElementById('documentsPage');
|
| 149 |
+
const documentsCountEl = document.getElementById('documentsCount');
|
| 150 |
+
const chunksPageEl = document.getElementById('chunksPage');
|
| 151 |
+
const chunksCountEl = document.getElementById('chunksCount');
|
| 152 |
+
|
| 153 |
+
function esc(v) {
|
| 154 |
+
return String(v ?? '').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
function setStatus(msg, isError = false) {
|
| 158 |
+
statusEl.innerHTML = msg ? `<span class="${isError ? 'error' : ''}">${esc(msg)}</span>` : '';
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
function spinner() {
|
| 162 |
+
setStatus(`<span class='inline'><span class='spinner'></span> Loading...</span>`);
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
function truncateValue(value, maxLength = 100) {
|
| 166 |
+
const str = String(value ?? '');
|
| 167 |
+
if (str.length <= maxLength) {
|
| 168 |
+
return { display: str, truncated: false, full: str };
|
| 169 |
+
}
|
| 170 |
+
return {
|
| 171 |
+
display: str.slice(0, maxLength) + '…',
|
| 172 |
+
truncated: true,
|
| 173 |
+
full: str
|
| 174 |
+
};
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
function showModal(title, content) {
|
| 178 |
+
modalTitle.textContent = title;
|
| 179 |
+
modalBody.textContent = content;
|
| 180 |
+
modal.style.display = 'block';
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
function hideModal() {
|
| 184 |
+
modal.style.display = 'none';
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
// Modal event listeners
|
| 188 |
+
closeModal.addEventListener('click', hideModal);
|
| 189 |
+
window.addEventListener('click', (e) => {
|
| 190 |
+
if (e.target === modal) {
|
| 191 |
+
hideModal();
|
| 192 |
+
}
|
| 193 |
+
});
|
| 194 |
+
|
| 195 |
+
// Tab switching
|
| 196 |
+
function switchTab(tabName) {
|
| 197 |
+
currentTab = tabName;
|
| 198 |
+
|
| 199 |
+
// Update tab buttons
|
| 200 |
+
document.querySelectorAll('.view-toggles button').forEach(btn => {
|
| 201 |
+
btn.classList.remove('active');
|
| 202 |
+
});
|
| 203 |
+
document.getElementById(tabName + 'Tab').classList.add('active');
|
| 204 |
+
|
| 205 |
+
// Update tab content
|
| 206 |
+
document.querySelectorAll('.tab-content').forEach(content => {
|
| 207 |
+
content.classList.remove('active');
|
| 208 |
+
});
|
| 209 |
+
document.getElementById(tabName + 'Content').classList.add('active');
|
| 210 |
+
|
| 211 |
+
// Load data if needed
|
| 212 |
+
if (tabName === 'documents') {
|
| 213 |
+
loadDocuments();
|
| 214 |
+
} else if (tabName === 'chunks') {
|
| 215 |
+
loadChunks();
|
| 216 |
+
}
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
documentsTab.addEventListener('click', () => switchTab('documents'));
|
| 220 |
+
chunksTab.addEventListener('click', () => switchTab('chunks'));
|
| 221 |
+
|
| 222 |
+
function renderDocumentsTable(data) {
|
| 223 |
+
const { documents, page, count } = data;
|
| 224 |
+
|
| 225 |
+
documentsPageEl.textContent = page;
|
| 226 |
+
documentsCountEl.textContent = count;
|
| 227 |
+
|
| 228 |
+
if (!documents || documents.length === 0) {
|
| 229 |
+
documentsTableWrapper.innerHTML = '<div class="empty">No documents found.</div>';
|
| 230 |
+
documentsPagination.style.display = 'none';
|
| 231 |
+
return;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
const columns = [
|
| 235 |
+
'doc_id', 'title', 'source_path', 'doc_type', 'jurisdiction',
|
| 236 |
+
'governing_law', 'party_roles', 'industry', 'effective_date',
|
| 237 |
+
'created_at', 'chunk_count', 'sha256'
|
| 238 |
+
];
|
| 239 |
+
|
| 240 |
+
let html = '<table class="data-table"><thead><tr>';
|
| 241 |
+
html += columns.map(col => `<th>${esc(col)}</th>`).join('');
|
| 242 |
+
html += '</tr></thead><tbody>';
|
| 243 |
+
|
| 244 |
+
documents.forEach(doc => {
|
| 245 |
+
html += '<tr>';
|
| 246 |
+
columns.forEach(col => {
|
| 247 |
+
const value = doc[col];
|
| 248 |
+
const { display, truncated, full } = truncateValue(value);
|
| 249 |
+
const cls = truncated ? 'truncate' : '';
|
| 250 |
+
const onClick = truncated ? `onclick="showModal('${esc(col)}', ${JSON.stringify(full).replace(/"/g, '"')})"` : '';
|
| 251 |
+
|
| 252 |
+
if (col === 'source_path' && value) {
|
| 253 |
+
// Make source path clickable
|
| 254 |
+
const rawPrefix = '/data/corpus_raw/';
|
| 255 |
+
let rel = '';
|
| 256 |
+
if (value.startsWith(rawPrefix)) {
|
| 257 |
+
rel = value.substring(rawPrefix.length);
|
| 258 |
+
} else {
|
| 259 |
+
try {
|
| 260 |
+
const parts = value.split('/');
|
| 261 |
+
rel = parts.slice(parts.indexOf('corpus_raw') + 1).join('/');
|
| 262 |
+
} catch {
|
| 263 |
+
rel = value.split('/').pop() || '';
|
| 264 |
+
}
|
| 265 |
+
}
|
| 266 |
+
const href = '/api/raw/' + encodeURI(rel);
|
| 267 |
+
html += `<td class="${cls}"><a href="${href}" target="_blank" rel="noopener noreferrer">${esc(display)}</a></td>`;
|
| 268 |
+
} else {
|
| 269 |
+
html += `<td class="${cls}" ${onClick}>${esc(display)}</td>`;
|
| 270 |
+
}
|
| 271 |
+
});
|
| 272 |
+
html += '</tr>';
|
| 273 |
+
});
|
| 274 |
+
|
| 275 |
+
html += '</tbody></table>';
|
| 276 |
+
documentsTableWrapper.innerHTML = html;
|
| 277 |
+
|
| 278 |
+
// Render pagination
|
| 279 |
+
renderPagination('documents', data);
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
function renderChunksTable(data) {
|
| 283 |
+
const { chunks, page, count } = data;
|
| 284 |
+
|
| 285 |
+
chunksPageEl.textContent = page;
|
| 286 |
+
chunksCountEl.textContent = count;
|
| 287 |
+
|
| 288 |
+
if (!chunks || chunks.length === 0) {
|
| 289 |
+
chunksTableWrapper.innerHTML = '<div class="empty">No chunks found.</div>';
|
| 290 |
+
chunksPagination.style.display = 'none';
|
| 291 |
+
return;
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
const columns = [
|
| 295 |
+
'chunk_id', 'doc_id', 'chunk_index', 'text', 'token_count',
|
| 296 |
+
'page_start', 'page_end', 'section_number', 'section_title',
|
| 297 |
+
'clause_type', 'path', 'numbers_present', 'definition_terms',
|
| 298 |
+
'tok_ver', 'seg_ver', 'embedding_count'
|
| 299 |
+
];
|
| 300 |
+
|
| 301 |
+
let html = '<table class="data-table"><thead><tr>';
|
| 302 |
+
html += columns.map(col => `<th>${esc(col)}</th>`).join('');
|
| 303 |
+
html += '</tr></thead><tbody>';
|
| 304 |
+
|
| 305 |
+
chunks.forEach(chunk => {
|
| 306 |
+
html += '<tr>';
|
| 307 |
+
columns.forEach(col => {
|
| 308 |
+
const value = chunk[col];
|
| 309 |
+
const { display, truncated, full } = truncateValue(value);
|
| 310 |
+
const cls = truncated ? 'truncate' : '';
|
| 311 |
+
const onClick = truncated ? `onclick="showModal('${esc(col)}', ${JSON.stringify(full).replace(/"/g, '"')})"` : '';
|
| 312 |
+
html += `<td class="${cls}" ${onClick}>${esc(display)}</td>`;
|
| 313 |
+
});
|
| 314 |
+
html += '</tr>';
|
| 315 |
+
});
|
| 316 |
+
|
| 317 |
+
html += '</tbody></table>';
|
| 318 |
+
chunksTableWrapper.innerHTML = html;
|
| 319 |
+
|
| 320 |
+
// Render pagination
|
| 321 |
+
renderPagination('chunks', data);
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
function renderPagination(type, data) {
|
| 325 |
+
const { page, has_more } = data;
|
| 326 |
+
const paginationEl = type === 'documents' ? documentsPagination : chunksPagination;
|
| 327 |
+
|
| 328 |
+
let html = '';
|
| 329 |
+
|
| 330 |
+
// Previous button
|
| 331 |
+
if (page > 1) {
|
| 332 |
+
html += `<button onclick="changePage('${type}', ${page - 1})">← Previous</button>`;
|
| 333 |
+
} else {
|
| 334 |
+
html += `<button disabled>← Previous</button>`;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
// Current page
|
| 338 |
+
html += `<span class="current">Page ${page}</span>`;
|
| 339 |
+
|
| 340 |
+
// Next button
|
| 341 |
+
if (has_more) {
|
| 342 |
+
html += `<button onclick="changePage('${type}', ${page + 1})">Next →</button>`;
|
| 343 |
+
} else {
|
| 344 |
+
html += `<button disabled>Next →</button>`;
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
paginationEl.innerHTML = html;
|
| 348 |
+
paginationEl.style.display = 'flex';
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
function changePage(type, page) {
|
| 352 |
+
if (type === 'documents') {
|
| 353 |
+
documentsPage = page;
|
| 354 |
+
loadDocuments();
|
| 355 |
+
} else if (type === 'chunks') {
|
| 356 |
+
chunksPage = page;
|
| 357 |
+
loadChunks();
|
| 358 |
+
}
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
function loadDocuments() {
|
| 362 |
+
spinner();
|
| 363 |
+
fetch(`/api/dbviewer/documents?page=${documentsPage}&limit=${PAGE_SIZE}`)
|
| 364 |
+
.then(response => response.json())
|
| 365 |
+
.then(data => {
|
| 366 |
+
if (data.error) {
|
| 367 |
+
setStatus(`Error loading documents: ${data.error}`, true);
|
| 368 |
+
documentsTableWrapper.innerHTML = '<div class="empty">Error loading documents.</div>';
|
| 369 |
+
return;
|
| 370 |
+
}
|
| 371 |
+
renderDocumentsTable(data);
|
| 372 |
+
setStatus(data.count ? `Loaded ${data.count} documents.` : 'No documents found.');
|
| 373 |
+
})
|
| 374 |
+
.catch(error => {
|
| 375 |
+
setStatus(`Failed to load documents: ${error.message}`, true);
|
| 376 |
+
documentsTableWrapper.innerHTML = '<div class="empty">Failed to load documents.</div>';
|
| 377 |
+
});
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
function loadChunks() {
|
| 381 |
+
spinner();
|
| 382 |
+
fetch(`/api/dbviewer/chunks?page=${chunksPage}&limit=${PAGE_SIZE}`)
|
| 383 |
+
.then(response => response.json())
|
| 384 |
+
.then(data => {
|
| 385 |
+
if (data.error) {
|
| 386 |
+
setStatus(`Error loading chunks: ${data.error}`, true);
|
| 387 |
+
chunksTableWrapper.innerHTML = '<div class="empty">Error loading chunks.</div>';
|
| 388 |
+
return;
|
| 389 |
+
}
|
| 390 |
+
renderChunksTable(data);
|
| 391 |
+
setStatus(data.count ? `Loaded ${data.count} chunks.` : 'No chunks found.');
|
| 392 |
+
})
|
| 393 |
+
.catch(error => {
|
| 394 |
+
setStatus(`Failed to load chunks: ${error.message}`, true);
|
| 395 |
+
chunksTableWrapper.innerHTML = '<div class="empty">Failed to load chunks.</div>';
|
| 396 |
+
});
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
// Initialize
|
| 400 |
+
loadDocuments();
|
| 401 |
+
</script>
|
| 402 |
+
</body>
|
| 403 |
+
</html>
|
static/index.html
CHANGED
|
@@ -274,7 +274,7 @@
|
|
| 274 |
<div class="header-section">
|
| 275 |
<h1 class="header-title">Technology Transactions Assistant</h1>
|
| 276 |
<p class="header-subtitle">A RAG model that restricts frontier-level foundation models to technology transactions use cases in the legal domain.</p>
|
| 277 |
-
<p class="header-subtitle">To add to the corpus, visit <a href="/upload" class="upload-link">/upload</a>. To view/edit the corpus, visit <a href="/manifest" class="upload-link">/manifest</a>.</p>
|
| 278 |
</div>
|
| 279 |
|
| 280 |
<div class="main-container">
|
|
|
|
| 274 |
<div class="header-section">
|
| 275 |
<h1 class="header-title">Technology Transactions Assistant</h1>
|
| 276 |
<p class="header-subtitle">A RAG model that restricts frontier-level foundation models to technology transactions use cases in the legal domain.</p>
|
| 277 |
+
<p class="header-subtitle">To add to the corpus, visit <a href="/upload" class="upload-link">/upload</a>. To view/edit the corpus, visit <a href="/manifest" class="upload-link">/manifest</a>. To view/edit embeddedings, visit <a href="/chunks" class="upload-link">/chunks</a>. To view database records directly, visit <a href="/db-viewer" class="upload-link">/db-viewer</a>.</p>
|
| 278 |
</div>
|
| 279 |
|
| 280 |
<div class="main-container">
|
static/manifest.html
CHANGED
|
@@ -33,7 +33,7 @@
|
|
| 33 |
.view-toggles button.active { background:#7ec8ff; color:#001122; }
|
| 34 |
.meta-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(200px,1fr)); gap:14px; }
|
| 35 |
.kv { background:#222; border:2px solid #555; border-radius:12px; padding:12px 14px; display:flex; flex-direction:column; gap:4px; }
|
| 36 |
-
.kv span.k { font-size:.65rem;
|
| 37 |
.kv span.v { font-size:.85rem; word-break:break-word; }
|
| 38 |
.records { background:#222; border:2px solid #555; border-radius:16px; padding:20px; display:flex; flex-direction:column; gap:20px; max-height:50vh; overflow:auto; }
|
| 39 |
.table-wrapper { background:#222; border:2px solid #555; border-radius:16px; padding:14px 18px; max-height:55vh; overflow:auto; }
|
|
@@ -46,7 +46,7 @@
|
|
| 46 |
.record { background:#1b2733; border:1px solid #3d4c55; border-radius:12px; padding:16px 18px; display:flex; flex-direction:column; gap:10px; position:relative; }
|
| 47 |
.record h3 { margin:0; font-size:.95rem; font-weight:600; }
|
| 48 |
.badge-row { display:flex; flex-wrap:wrap; gap:6px; }
|
| 49 |
-
.badge { background:#2d3f4d; color:#cfe9ff; font-size:.6rem; padding:4px 8px; border-radius:100px; letter-spacing:.5px;
|
| 50 |
.json-view { font-family:Consolas,Monaco,monospace; font-size:.7rem; background:#111a22; border:1px solid #2c3a44; border-radius:8px; padding:10px 12px; white-space:pre; overflow:auto; max-height:240px; }
|
| 51 |
.empty { text-align:center; font-style:italic; color:#ccc; }
|
| 52 |
.error { color:#ff7b7b; font-weight:600; }
|
|
@@ -85,8 +85,10 @@
|
|
| 85 |
<label for="filter">Text Filter</label>
|
| 86 |
<input type="text" id="filter" placeholder="Type to filter rows" />
|
| 87 |
</div>
|
| 88 |
-
<div style="display:flex; gap:
|
| 89 |
<button type="button" id="refreshBtn">Refresh</button>
|
|
|
|
|
|
|
| 90 |
<button type="button" class="secondary" id="clearBtn">Clear</button>
|
| 91 |
</div>
|
| 92 |
</form>
|
|
@@ -108,6 +110,11 @@
|
|
| 108 |
</div>
|
| 109 |
</div>
|
| 110 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
<script>
|
| 113 |
const filterForm = document.getElementById('filterForm');
|
|
|
|
| 33 |
.view-toggles button.active { background:#7ec8ff; color:#001122; }
|
| 34 |
.meta-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(200px,1fr)); gap:14px; }
|
| 35 |
.kv { background:#222; border:2px solid #555; border-radius:12px; padding:12px 14px; display:flex; flex-direction:column; gap:4px; }
|
| 36 |
+
.kv span.k { font-size:.65rem; letter-spacing:1px; color:#999; }
|
| 37 |
.kv span.v { font-size:.85rem; word-break:break-word; }
|
| 38 |
.records { background:#222; border:2px solid #555; border-radius:16px; padding:20px; display:flex; flex-direction:column; gap:20px; max-height:50vh; overflow:auto; }
|
| 39 |
.table-wrapper { background:#222; border:2px solid #555; border-radius:16px; padding:14px 18px; max-height:55vh; overflow:auto; }
|
|
|
|
| 46 |
.record { background:#1b2733; border:1px solid #3d4c55; border-radius:12px; padding:16px 18px; display:flex; flex-direction:column; gap:10px; position:relative; }
|
| 47 |
.record h3 { margin:0; font-size:.95rem; font-weight:600; }
|
| 48 |
.badge-row { display:flex; flex-wrap:wrap; gap:6px; }
|
| 49 |
+
.badge { background:#2d3f4d; color:#cfe9ff; font-size:.6rem; padding:4px 8px; border-radius:100px; letter-spacing:.5px;}
|
| 50 |
.json-view { font-family:Consolas,Monaco,monospace; font-size:.7rem; background:#111a22; border:1px solid #2c3a44; border-radius:8px; padding:10px 12px; white-space:pre; overflow:auto; max-height:240px; }
|
| 51 |
.empty { text-align:center; font-style:italic; color:#ccc; }
|
| 52 |
.error { color:#ff7b7b; font-weight:600; }
|
|
|
|
| 85 |
<label for="filter">Text Filter</label>
|
| 86 |
<input type="text" id="filter" placeholder="Type to filter rows" />
|
| 87 |
</div>
|
| 88 |
+
<div style="display:flex; gap:4px;">
|
| 89 |
<button type="button" id="refreshBtn">Refresh</button>
|
| 90 |
+
</div>
|
| 91 |
+
<div style="display:flex; gap:4px;">
|
| 92 |
<button type="button" class="secondary" id="clearBtn">Clear</button>
|
| 93 |
</div>
|
| 94 |
</form>
|
|
|
|
| 110 |
</div>
|
| 111 |
</div>
|
| 112 |
</div>
|
| 113 |
+
<div style="text-align: center; margin-top: 20px;">
|
| 114 |
+
<a href="/" style="color: #87CEFA; text-decoration: none; font-size: 1rem; padding: 10px 20px; border: 1px solid #87CEFA; border-radius: 10px; transition: all 0.3s ease;" onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration='none'">
|
| 115 |
+
← Back to Home
|
| 116 |
+
</a>
|
| 117 |
+
</div>
|
| 118 |
|
| 119 |
<script>
|
| 120 |
const filterForm = document.getElementById('filterForm');
|
static/upload.html
CHANGED
|
@@ -316,6 +316,12 @@
|
|
| 316 |
<div class="upload-result" id="uploadResult"></div>
|
| 317 |
</div>
|
| 318 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
<script>
|
| 320 |
const uploadArea = document.getElementById('uploadArea');
|
| 321 |
const fileInput = document.getElementById('fileInput');
|
|
|
|
| 316 |
<div class="upload-result" id="uploadResult"></div>
|
| 317 |
</div>
|
| 318 |
|
| 319 |
+
<div style="text-align: center; margin-top: 20px;">
|
| 320 |
+
<a href="/" style="color: #87CEFA; text-decoration: none; font-size: 1rem; padding: 10px 20px; border: 1px solid #87CEFA; border-radius: 10px; transition: all 0.3s ease;" onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration='none'">
|
| 321 |
+
← Back to Home
|
| 322 |
+
</a>
|
| 323 |
+
</div>
|
| 324 |
+
|
| 325 |
<script>
|
| 326 |
const uploadArea = document.getElementById('uploadArea');
|
| 327 |
const fileInput = document.getElementById('fileInput');
|