fix: lighter terminal output box + cache embedding model across papers

This commit is contained in:
Research Assistant 2026-05-13 19:12:52 +08:00
parent 9964d7d03e
commit 3d5a4a4e15
2 changed files with 13 additions and 3 deletions

View file

@ -60,8 +60,13 @@ def get_collection(vault: Path):
)
_cached_model = None
_cached_model_name = None
def get_embedding_model(vault: Path):
"""Load the embedding model based on plugin settings or default."""
"""Load the embedding model based on plugin settings or default. Cached after first load."""
global _cached_model, _cached_model_name
settings = _read_plugin_settings(vault)
mode = settings.get("vector_db_mode", "local")
@ -69,9 +74,14 @@ def get_embedding_model(vault: Path):
return None # API mode — embedding done externally
model_name = settings.get("vector_db_model", "BAAI/bge-small-en-v1.5")
if _cached_model is not None and _cached_model_name == model_name:
return _cached_model
ST = _get_st()
logger.info("Loading embedding model: %s", model_name)
return ST(model_name)
_cached_model = ST(model_name)
_cached_model_name = model_name
return _cached_model
def embed_paper(vault: Path, zotero_key: str, chunks: list[dict]) -> int:

View file

@ -3027,7 +3027,7 @@ class PaperForgeSettingTab extends PluginSettingTab {
// Rebuild button with live terminal output
const terminalEl = containerEl.createEl('pre');
terminalEl.style.cssText = 'display:none; background:#1e1e1e; color:#d4d4d4; padding:10px; border-radius:4px; max-height:300px; overflow-y:auto; font-size:11px; font-family:var(--font-monospace); margin:8px 0; white-space:pre-wrap; word-break:break-all;';
terminalEl.style.cssText = 'display:none; background:var(--background-primary); padding:10px; border-radius:4px; border:1px solid var(--background-modifier-border); max-height:250px; overflow-y:auto; font-size:11px; font-family:var(--font-monospace); margin:8px 0; white-space:pre-wrap; word-break:break-all; opacity:0.8;';
new Setting(containerEl)
.setName('Rebuild Vectors')