aboutsummaryrefslogtreecommitdiff
path: root/build_index.py
diff options
context:
space:
mode:
authortwells46 <173561638+twells46@users.noreply.github.com>2026-04-01 15:40:57 -0500
committertwells46 <173561638+twells46@users.noreply.github.com>2026-04-01 15:40:57 -0500
commit1e72f44f28b97ef3f28627421bedca379d136a76 (patch)
tree3aa3ebf7ab7ace97744eca4e1784700f68135463 /build_index.py
parent2f37974a4c84f7ffdd07e2c223eba2d8bd981b61 (diff)
Long-running
Diffstat (limited to 'build_index.py')
-rw-r--r--build_index.py37
1 files changed, 26 insertions, 11 deletions
diff --git a/build_index.py b/build_index.py
index 8597c68..d25f446 100644
--- a/build_index.py
+++ b/build_index.py
@@ -2,24 +2,24 @@
from __future__ import annotations
import json
-import sqlite3
+import os
from pathlib import Path
+import sqlite3
+import sys
from typing import Any
+LOCAL_CACHE_DIR = Path("models/hf")
+os.environ.setdefault("HF_HOME", str(LOCAL_CACHE_DIR.resolve()))
+os.environ.setdefault("SENTENCE_TRANSFORMERS_HOME", str(LOCAL_CACHE_DIR.resolve()))
+
import numpy as np
from sentence_transformers import SentenceTransformer
-import os
-from pathlib import Path
+from cheat_runtime import DEFAULT_SOCKET_PATH, send_server_request
DB_PATH = Path("cheat.db")
CARDS_PATH = Path("./cards.jsonl")
MODEL_NAME = "sentence-transformers/all-MiniLM-L6-v2"
-LOCAL_CACHE_DIR = Path("models/hf")
-
-LOCAL_CACHE_DIR = Path("models/hf")
-os.environ.setdefault("HF_HOME", str(LOCAL_CACHE_DIR.resolve()))
-os.environ.setdefault("SENTENCE_TRANSFORMERS_HOME", str(LOCAL_CACHE_DIR.resolve()))
REQUIRED_FIELDS = {
"id",
@@ -154,9 +154,7 @@ def upsert_embedding(
def main() -> None:
if not DB_PATH.exists():
- raise FileNotFoundError(
- f"Database not found at {DB_PATH}. Run scripts/init_db.py first."
- )
+ raise FileNotFoundError(f"Database not found at {DB_PATH}. Run init_db.py first.")
if not CARDS_PATH.exists():
raise FileNotFoundError(f"Cards file not found at {CARDS_PATH}")
@@ -187,6 +185,23 @@ def main() -> None:
finally:
conn.close()
+ try:
+ response = send_server_request(
+ {"action": "reload"},
+ socket_path=DEFAULT_SOCKET_PATH,
+ timeout=1.0,
+ )
+ except OSError:
+ return
+
+ if response.get("ok"):
+ print(f"Reloaded query server at {DEFAULT_SOCKET_PATH}")
+ else:
+ print(
+ f"Warning: query server reload failed: {response.get('error', 'unknown error')}",
+ file=sys.stderr,
+ )
+
if __name__ == "__main__":
main()