Mokhtar
feat(production): complete phase 1-4 refactor with hybrid retrieval CAG architecture, E5 dense embeddings, grounding validator, precomputed cold-start index, and 24/24 passing system tests
d54db1a Download cache/warm_cache.py from mokh2x/HNU-Final: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/spaces/mokh2x/HNU-Final/resolve/main/cache/warm_cache.py
- Command line
-
hf download hf://spaces/mokh2x/HNU-Final/cache/warm_cache.py
-
curl -L -o warm_cache.py https://huggingface.co/spaces/mokh2x/HNU-Final/resolve/main/cache/warm_cache.py
1.42 kB
| # cache/warm_cache.py โ Optional Retrieval & Index Warmup Tool (Replaces seed_cache.py) | |
| import time | |
| from pathlib import Path | |
| from knowledge.loader import KnowledgeLoader | |
| from knowledge.chunker import MarkdownChunker | |
| from knowledge.index import HybridIndex | |
| from knowledge.retrieval import HybridRetriever | |
| def warm_up_index(data_dir: Path) -> float: | |
| """Pre-warm knowledge loading, chunking, and hybrid search indexing.""" | |
| start_time = time.time() | |
| print("๐ฅ Pre-warming Retrieval Index...") | |
| loader = KnowledgeLoader(data_dir=str(data_dir)) | |
| documents = loader.load_documents() | |
| chunker = MarkdownChunker() | |
| chunks = chunker.chunk_all(documents) | |
| index = HybridIndex() | |
| index.build_index(chunks) | |
| retriever = HybridRetriever(index=index) | |
| # Run test retrieval queries to warm in-memory data structures | |
| test_queries = [ | |
| "ู ุตุงุฑูู ูููุฉ ุทุจ ุงูุฃุณูุงู", | |
| "ุงูุญุฏ ุงูุฃุฏูู ููููุฉ ุงูููุฏุณุฉ", | |
| "ู ูู ู ุทูุฑูู ุงูู ููุนุ", | |
| "ุจุฑุงู ุฌ ูููุฉ ุงูุนููู " | |
| ] | |
| for q in test_queries: | |
| retriever.retrieve(q) | |
| elapsed = round(time.time() - start_time, 3) | |
| print(f"โ Retrieval Index warmed in {elapsed}s.") | |
| return elapsed | |
| if __name__ == "__main__": | |
| base_dir = Path(__file__).resolve().parent.parent | |
| data_dir = base_dir / "university_data_arabic" | |
| warm_up_index(data_dir) | |