Upload folder using huggingface_hub
Browse files- agents/crew.py +1 -0
- app.py +52 -0
- templates/index.html +3 -3
agents/crew.py
CHANGED
|
@@ -258,6 +258,7 @@ def run_query_crew(query: str, top_k: int = None, max_tokens: int = None, use_ve
|
|
| 258 |
unique_chunks = list(all_chunks.values())
|
| 259 |
|
| 260 |
t_retrieval = time.time() - t0
|
|
|
|
| 261 |
print(f"[Retrieval Phase] Done in {t_retrieval:.2f}s — "
|
| 262 |
f"{len(unique_chunks)} unique chunks retrieved from Vector DB, Graph DB, and BM25.")
|
| 263 |
|
|
|
|
| 258 |
unique_chunks = list(all_chunks.values())
|
| 259 |
|
| 260 |
t_retrieval = time.time() - t0
|
| 261 |
+
print(f"[Retrieval] Vector chunks: {len(vec_results)}, Graph chunks: {len(graph_results)}, BM25 chunks: {len(bm25_results)}")
|
| 262 |
print(f"[Retrieval Phase] Done in {t_retrieval:.2f}s — "
|
| 263 |
f"{len(unique_chunks)} unique chunks retrieved from Vector DB, Graph DB, and BM25.")
|
| 264 |
|
app.py
CHANGED
|
@@ -640,6 +640,58 @@ def process_document_pipeline(path: str, orig_name: str, tier: str, token: str,
|
|
| 640 |
except OSError as e:
|
| 641 |
log.warning("Failed to delete %s: %s", path, e)
|
| 642 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 643 |
|
| 644 |
@app.route("/api/ingest", methods=["POST"])
|
| 645 |
def ingest():
|
|
|
|
| 640 |
except OSError as e:
|
| 641 |
log.warning("Failed to delete %s: %s", path, e)
|
| 642 |
|
| 643 |
+
def sync_he_data():
|
| 644 |
+
try:
|
| 645 |
+
import os
|
| 646 |
+
from huggingface_hub import snapshot_download
|
| 647 |
+
import keyring
|
| 648 |
+
|
| 649 |
+
token = os.environ.get("HF_TOKEN")
|
| 650 |
+
if not token:
|
| 651 |
+
try:
|
| 652 |
+
token = keyring.get_password('huggingface', 'my_user') or keyring.get_password('huggingface', 'hf_token')
|
| 653 |
+
except Exception:
|
| 654 |
+
pass
|
| 655 |
+
|
| 656 |
+
kbdocs_dir = Path(__file__).parent / "kbdocs"
|
| 657 |
+
kbdocs_dir.mkdir(exist_ok=True)
|
| 658 |
+
|
| 659 |
+
log.info("Syncing fresh files from Sam-max1/he_data to local kbdocs...")
|
| 660 |
+
snapshot_download(
|
| 661 |
+
repo_id="Sam-max1/he_data",
|
| 662 |
+
repo_type="dataset",
|
| 663 |
+
local_dir=str(kbdocs_dir),
|
| 664 |
+
token=token,
|
| 665 |
+
ignore_patterns=[".git*"]
|
| 666 |
+
)
|
| 667 |
+
log.info("Successfully synced he_data repository.")
|
| 668 |
+
|
| 669 |
+
from pipeline import vector_store
|
| 670 |
+
|
| 671 |
+
existing_docs = vector_store.list_documents("admin")
|
| 672 |
+
existing_names = {d["source"] for d in existing_docs}
|
| 673 |
+
|
| 674 |
+
ingested_count = 0
|
| 675 |
+
for file_path in kbdocs_dir.glob("*.*"):
|
| 676 |
+
if file_path.is_file() and file_path.name not in existing_names:
|
| 677 |
+
log.info(f"Auto-ingesting new file: {file_path.name}")
|
| 678 |
+
process_document_pipeline(str(file_path), file_path.name, "foundation", "admin", delete_after=False)
|
| 679 |
+
ingested_count += 1
|
| 680 |
+
|
| 681 |
+
# show number of chunks and nodes
|
| 682 |
+
log.info("=== Full Data Ingestion Complete ===")
|
| 683 |
+
log.info(f"Vector DB Chunks: {vector_store.count()}")
|
| 684 |
+
|
| 685 |
+
from pipeline import graph_store
|
| 686 |
+
if graph_store.is_available():
|
| 687 |
+
stats = graph_store.get_stats()
|
| 688 |
+
log.info(f"Kuzu DB Nodes: {stats.get('nodes', 0)}, Edges: {stats.get('edges', 0)}")
|
| 689 |
+
|
| 690 |
+
except Exception as e:
|
| 691 |
+
log.error("Failed to sync he_data: %s", e)
|
| 692 |
+
|
| 693 |
+
threading.Thread(target=sync_he_data, daemon=True).start()
|
| 694 |
+
|
| 695 |
|
| 696 |
@app.route("/api/ingest", methods=["POST"])
|
| 697 |
def ingest():
|
templates/index.html
CHANGED
|
@@ -167,7 +167,7 @@
|
|
| 167 |
<header class="banner" role="banner">
|
| 168 |
<div>
|
| 169 |
<h1>Healthcare Policy Expert</h1>
|
| 170 |
-
<div style="font-size: 0.75rem; font-weight: normal; margin-top: 4px; opacity: 0.9;">Agentic AI
|
| 171 |
</div>
|
| 172 |
<div id="status-pill" class="pill not-ready">Not Ready</div>
|
| 173 |
</header>
|
|
@@ -344,8 +344,8 @@
|
|
| 344 |
const payload = {
|
| 345 |
query: q,
|
| 346 |
use_vector: true,
|
| 347 |
-
use_graph:
|
| 348 |
-
use_bm25:
|
| 349 |
top_k: 10,
|
| 350 |
max_tokens: 2048,
|
| 351 |
cpu_threads: 16
|
|
|
|
| 167 |
<header class="banner" role="banner">
|
| 168 |
<div>
|
| 169 |
<h1>Healthcare Policy Expert</h1>
|
| 170 |
+
<div style="font-size: 0.75rem; font-weight: normal; margin-top: 4px; opacity: 0.9;">Agentic AI | RAG System | Edge Compute | Sandboxed</div>
|
| 171 |
</div>
|
| 172 |
<div id="status-pill" class="pill not-ready">Not Ready</div>
|
| 173 |
</header>
|
|
|
|
| 344 |
const payload = {
|
| 345 |
query: q,
|
| 346 |
use_vector: true,
|
| 347 |
+
use_graph: true,
|
| 348 |
+
use_bm25: true,
|
| 349 |
top_k: 10,
|
| 350 |
max_tokens: 2048,
|
| 351 |
cpu_threads: 16
|