Spaces:
Sleeping
Sleeping
| """ | |
| vector_search.py | |
| Thin wrapper helpers used to orchestrate searches and resets from the app or admin UI. | |
| """ | |
| from typing import List, Dict, Any | |
| from core import vector_store, vector_sync | |
| def semantic_search(query: str, top_k: int = 6) -> List[Dict[str, Any]]: | |
| """ | |
| Safe semantic search that falls back gracefully to empty list. | |
| """ | |
| try: | |
| return vector_store.search_index(query, top_k=top_k) | |
| except Exception as e: | |
| print(f"⚠️ semantic_search error: {e}") | |
| return [] | |
| def reset_faiss_and_rebuild(glossary_builder_fn=None, rebuild_index_fn=None) -> str: | |
| """ | |
| Clear local caches and run rebuilds. The app's reset_faiss_cache() can call this. | |
| - glossary_builder_fn: optional function to run to rebuild glossary (if provided) | |
| - rebuild_index_fn: optional function that triggers full rebuild (if provided) | |
| """ | |
| try: | |
| vector_store.clear_local_faiss() | |
| except Exception as e: | |
| print(f"⚠️ clear_local_faiss failed: {e}") | |
| out = "🧹 Cleared local FAISS files.\n" | |
| # If a glossary builder was provided, run it (safe) | |
| if glossary_builder_fn: | |
| try: | |
| out += glossary_builder_fn() + "\n" | |
| except Exception as e: | |
| out += f"⚠️ Glossary builder failed: {e}\n" | |
| if rebuild_index_fn: | |
| try: | |
| out += rebuild_index_fn() | |
| except Exception as e: | |
| out += f"⚠️ Rebuild index failed: {e}\n" | |
| return out | |