Return a status dict for display in /status or setup output.
()
| 671 | |
| 672 | |
| 673 | def index_stats() -> dict: |
| 674 | """Return a status dict for display in /status or setup output.""" |
| 675 | chunk_dir = KB_ROOT / "embeddings" |
| 676 | if not chunk_dir.exists(): |
| 677 | return { |
| 678 | "chunk_files": 0, "total_chunks": 0, |
| 679 | "has_semantic": False, "backend": "none", |
| 680 | "kb_root": str(KB_ROOT), |
| 681 | } |
| 682 | |
| 683 | chunk_files = list(chunk_dir.glob("*.chunks.json")) |
| 684 | total = 0 |
| 685 | for cf in chunk_files: |
| 686 | try: |
| 687 | with open(cf) as f: |
| 688 | total += len(json.load(f)) |
| 689 | except Exception: |
| 690 | pass |
| 691 | |
| 692 | has_vec = (chunk_dir / "vectors.npy").exists() |
| 693 | meta = {} |
| 694 | mep = chunk_dir / "vectors.meta.json" |
| 695 | if mep.exists(): |
| 696 | try: |
| 697 | with open(mep) as f: |
| 698 | meta = json.load(f) |
| 699 | except Exception: |
| 700 | pass |
| 701 | |
| 702 | index_backend = meta.get("backend", "unknown") if has_vec else None |
| 703 | dim = meta.get("dim", "?") if has_vec else None |
| 704 | |
| 705 | if has_vec and index_backend == "llama-server": |
| 706 | backend = f"hybrid BM25 + llama-embeddings ({dim}d, RRF)" |
| 707 | elif has_vec and index_backend == "fastembed": |
| 708 | backend = f"hybrid BM25 + fastembed ({dim}d, RRF)" |
| 709 | elif has_vec and index_backend == "sentence-transformers": |
| 710 | backend = f"hybrid BM25 + sentence-transformers ({dim}d, RRF)" |
| 711 | elif HAS_FASTEMBED: |
| 712 | backend = "fastembed available (run build_semantic_index)" |
| 713 | elif HAS_SENTENCE_TRANSFORMERS: |
| 714 | backend = "sentence-transformers available (run build_semantic_index)" |
| 715 | else: |
| 716 | backend = "BM25 keyword (no vector index — run setup_skills.sh with llama-server active)" |
| 717 | |
| 718 | return { |
| 719 | "chunk_files": len(chunk_files), |
| 720 | "total_chunks": total, |
| 721 | "has_semantic": has_vec, |
| 722 | "backend": backend, |
| 723 | "llama_embed_available": check_llama_embeddings(), |
| 724 | "sentence_transformers": HAS_SENTENCE_TRANSFORMERS, |
| 725 | "kb_root": str(KB_ROOT), |
| 726 | } |
no test coverage detected