kamp0010 commited on
Commit
e6ff4ad
Β·
verified Β·
1 Parent(s): baaced2

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +22 -2
main.py CHANGED
@@ -95,8 +95,28 @@ from sentence_transformers import SentenceTransformer
95
 
96
 
97
  # ─────────────────────────── Constants ───────────────────────────────────────
98
- DIM = 768 # jina-embeddings-v2-base-code output dimension
99
- STORE_DIR = pathlib.Path("/data/indexes")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
 
101
  LANGUAGE_MAP = {
102
  ".py": "python",
 
95
 
96
 
97
  # ─────────────────────────── Constants ───────────────────────────────────────
98
+ DIM = 768 # jina-embeddings-v2-base-code output dimension
99
+
100
+ def _resolve_store_dir() -> pathlib.Path:
101
+ """
102
+ Try /data/indexes (HF Spaces persistent volume).
103
+ Fall back to ~/.cache/code-search/indexes if /data is not writable
104
+ (local dev, or volume not yet mounted with correct permissions).
105
+ """
106
+ primary = pathlib.Path("/data/indexes")
107
+ try:
108
+ primary.mkdir(parents=True, exist_ok=True)
109
+ probe = primary / ".write_probe"
110
+ probe.touch()
111
+ probe.unlink()
112
+ return primary
113
+ except OSError:
114
+ fallback = pathlib.Path.home() / ".cache" / "code-search" / "indexes"
115
+ fallback.mkdir(parents=True, exist_ok=True)
116
+ print(f"Warning: /data/indexes not writable β€” using fallback: {fallback}")
117
+ return fallback
118
+
119
+ STORE_DIR = _resolve_store_dir()
120
 
121
  LANGUAGE_MAP = {
122
  ".py": "python",