Spaces:
Running
Running
Commit ·
cdcdbbf
1
Parent(s): f50b0fd
fix: optimize local mode Qdrant restore by replacing server snapshots with pre-packaged SQLite databases
Browse files
webapp/tipitaka-api/app/services/rag_service.py
CHANGED
|
@@ -22,26 +22,6 @@ ST_EMBED_MODEL = "jinaai/jina-embeddings-v5-text-small-retrieval"
|
|
| 22 |
logger = logging.getLogger(__name__)
|
| 23 |
|
| 24 |
class RAGService:
|
| 25 |
-
def _extract_snapshot(self, col_name: str, snap_path: Path):
|
| 26 |
-
"""Manually extract a Qdrant snapshot into the storage folder for Local Mode."""
|
| 27 |
-
import tarfile
|
| 28 |
-
import shutil
|
| 29 |
-
|
| 30 |
-
target_dir = Path(self.qdrant_path) / "collections" / col_name
|
| 31 |
-
if target_dir.exists():
|
| 32 |
-
shutil.rmtree(target_dir)
|
| 33 |
-
target_dir.mkdir(parents=True, exist_ok=True)
|
| 34 |
-
|
| 35 |
-
logger.info(f"Extracting snapshot to {target_dir}...")
|
| 36 |
-
try:
|
| 37 |
-
with tarfile.open(snap_path, "r:*") as tar:
|
| 38 |
-
tar.extractall(path=target_dir)
|
| 39 |
-
logger.info(f"Extraction of '{col_name}' complete.")
|
| 40 |
-
return True
|
| 41 |
-
except Exception as e:
|
| 42 |
-
logger.error(f"Error extracting snapshot for {col_name}: {e}")
|
| 43 |
-
return False
|
| 44 |
-
|
| 45 |
def __init__(self):
|
| 46 |
settings = get_settings()
|
| 47 |
self.qdrant_path = settings.QDRANT_PATH
|
|
@@ -92,7 +72,7 @@ class RAGService:
|
|
| 92 |
self.client = None
|
| 93 |
|
| 94 |
def _init_qdrant_local(self):
|
| 95 |
-
"""Initialize Qdrant in Local Mode
|
| 96 |
logger.info(f"Initializing Qdrant in Local Mode at {self.qdrant_path}")
|
| 97 |
storage_path = Path(self.qdrant_path)
|
| 98 |
storage_path.mkdir(parents=True, exist_ok=True)
|
|
@@ -105,15 +85,7 @@ class RAGService:
|
|
| 105 |
except Exception as e:
|
| 106 |
logger.error(f"Failed to remove lock file: {e}")
|
| 107 |
|
| 108 |
-
|
| 109 |
-
col_dir = storage_path / "collections" / col_name
|
| 110 |
-
if not col_dir.exists():
|
| 111 |
-
snap_path = self.snapshot_dir / f"{col_name}.snapshot"
|
| 112 |
-
if snap_path.exists():
|
| 113 |
-
logger.info(f"Restoring '{col_name}' via manual extraction...")
|
| 114 |
-
self._extract_snapshot(col_name, snap_path)
|
| 115 |
-
|
| 116 |
-
self.client = qdrant_client.QdrantClient(path=self.qdrant_path)
|
| 117 |
logger.info("Qdrant Local Client initialized.")
|
| 118 |
|
| 119 |
def _init_qdrant_server(self, qdrant_url: str):
|
|
|
|
| 22 |
logger = logging.getLogger(__name__)
|
| 23 |
|
| 24 |
class RAGService:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
def __init__(self):
|
| 26 |
settings = get_settings()
|
| 27 |
self.qdrant_path = settings.QDRANT_PATH
|
|
|
|
| 72 |
self.client = None
|
| 73 |
|
| 74 |
def _init_qdrant_local(self):
|
| 75 |
+
"""Initialize Qdrant in Local Mode."""
|
| 76 |
logger.info(f"Initializing Qdrant in Local Mode at {self.qdrant_path}")
|
| 77 |
storage_path = Path(self.qdrant_path)
|
| 78 |
storage_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 85 |
except Exception as e:
|
| 86 |
logger.error(f"Failed to remove lock file: {e}")
|
| 87 |
|
| 88 |
+
self.client = qdrant_client.QdrantClient(path=str(self.qdrant_path))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
logger.info("Qdrant Local Client initialized.")
|
| 90 |
|
| 91 |
def _init_qdrant_server(self, qdrant_url: str):
|
webapp/tipitaka-api/download_assets.py
CHANGED
|
@@ -27,8 +27,9 @@ RERANK_REPO_ID = "jinaai/jina-reranker-v2-base-multilingual"
|
|
| 27 |
# Files to check/download
|
| 28 |
BUCKET_FILES = [
|
| 29 |
("tipitaka_mcu.db", str(DB_PATH)),
|
| 30 |
-
("
|
| 31 |
-
("
|
|
|
|
| 32 |
]
|
| 33 |
|
| 34 |
# Essential Reranker files (ONNX)
|
|
@@ -109,8 +110,14 @@ def verify_assets() -> bool:
|
|
| 109 |
if not DB_PATH.exists():
|
| 110 |
missing.append("tipitaka_mcu.db")
|
| 111 |
|
| 112 |
-
if not (
|
| 113 |
-
missing.append("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
rerank_model = MODELS_DIR / "jina-v2-onnx" / "onnx" / "model_int8.onnx"
|
| 116 |
if not rerank_model.exists():
|
|
|
|
| 27 |
# Files to check/download
|
| 28 |
BUCKET_FILES = [
|
| 29 |
("tipitaka_mcu.db", str(DB_PATH)),
|
| 30 |
+
("qdrant_storage/meta.json", str(QDRANT_DIR / "meta.json")),
|
| 31 |
+
("qdrant_storage/collection/tipitaka_chunks/storage.sqlite", str(QDRANT_DIR / "collection" / "tipitaka_chunks" / "storage.sqlite")),
|
| 32 |
+
("qdrant_storage/collection/tipitaka_scripture/storage.sqlite", str(QDRANT_DIR / "collection" / "tipitaka_scripture" / "storage.sqlite")),
|
| 33 |
]
|
| 34 |
|
| 35 |
# Essential Reranker files (ONNX)
|
|
|
|
| 110 |
if not DB_PATH.exists():
|
| 111 |
missing.append("tipitaka_mcu.db")
|
| 112 |
|
| 113 |
+
if not (QDRANT_DIR / "meta.json").exists():
|
| 114 |
+
missing.append("qdrant_storage/meta.json")
|
| 115 |
+
|
| 116 |
+
if not (QDRANT_DIR / "collection" / "tipitaka_chunks" / "storage.sqlite").exists():
|
| 117 |
+
missing.append("qdrant_storage/collection/tipitaka_chunks/storage.sqlite")
|
| 118 |
+
|
| 119 |
+
if not (QDRANT_DIR / "collection" / "tipitaka_scripture" / "storage.sqlite").exists():
|
| 120 |
+
missing.append("qdrant_storage/collection/tipitaka_scripture/storage.sqlite")
|
| 121 |
|
| 122 |
rerank_model = MODELS_DIR / "jina-v2-onnx" / "onnx" / "model_int8.onnx"
|
| 123 |
if not rerank_model.exists():
|