Spaces:
Sleeping
Sleeping
Islam Mamedov commited on
Commit ·
9e3e6cb
1
Parent(s): cb2410e
Fix partial-init bug in retrieval singleton
Browse files- src/retrieval.py +4 -2
src/retrieval.py
CHANGED
|
@@ -47,6 +47,7 @@ Question: {question}"""
|
|
| 47 |
|
| 48 |
# Lazy singletons so models/indexes load once per process, not per query
|
| 49 |
_embedder = None
|
|
|
|
| 50 |
_reranker = None
|
| 51 |
_collection = None
|
| 52 |
_bm25 = None
|
|
@@ -59,8 +60,8 @@ def _tokenize(text: str) -> list[str]:
|
|
| 59 |
|
| 60 |
|
| 61 |
def _load() -> None:
|
| 62 |
-
global _embedder, _collection, _bm25, _chunk_ids, _chunk_by_id
|
| 63 |
-
if
|
| 64 |
return
|
| 65 |
_embedder = SentenceTransformer(EMBED_MODEL)
|
| 66 |
_collection = chromadb.PersistentClient(
|
|
@@ -70,6 +71,7 @@ def _load() -> None:
|
|
| 70 |
_chunk_ids = [c["id"] for c in chunks]
|
| 71 |
_chunk_by_id = {c["id"]: c for c in chunks}
|
| 72 |
_bm25 = BM25Okapi([_tokenize(c["text"]) for c in chunks])
|
|
|
|
| 73 |
|
| 74 |
|
| 75 |
def _get_reranker() -> CrossEncoder:
|
|
|
|
| 47 |
|
| 48 |
# Lazy singletons so models/indexes load once per process, not per query
|
| 49 |
_embedder = None
|
| 50 |
+
_loaded = False
|
| 51 |
_reranker = None
|
| 52 |
_collection = None
|
| 53 |
_bm25 = None
|
|
|
|
| 60 |
|
| 61 |
|
| 62 |
def _load() -> None:
|
| 63 |
+
global _loaded, _embedder, _collection, _bm25, _chunk_ids, _chunk_by_id
|
| 64 |
+
if _loaded:
|
| 65 |
return
|
| 66 |
_embedder = SentenceTransformer(EMBED_MODEL)
|
| 67 |
_collection = chromadb.PersistentClient(
|
|
|
|
| 71 |
_chunk_ids = [c["id"] for c in chunks]
|
| 72 |
_chunk_by_id = {c["id"]: c for c in chunks}
|
| 73 |
_bm25 = BM25Okapi([_tokenize(c["text"]) for c in chunks])
|
| 74 |
+
_loaded = True
|
| 75 |
|
| 76 |
|
| 77 |
def _get_reranker() -> CrossEncoder:
|