feat(qmd): switch to Qwen3 4B embedding and reranker models

Use Qwen3-Embedding-4B and Qwen3-Reranker-4B (both Q4_K_M) for QMD local
search, and make the switch reach existing installations:

- Rewrite the setup-owned models block on every install and update, while
  still recording the user's original block only once.
- When the new embedding size no longer matches stored vectors, the daemon
  clears the old vectors and re-embeds the repository.
- Delete setup-downloaded model files the current models no longer use.
- Skip npm and pnpm lockfiles and minified bundles when indexing
  repositories, which saves embedding work and removes search noise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Julian LechnerandClaude Opus 5.5 committed 2026-11-16 09:51:58 +01:00
1 parent 3fcd7bcbfd
commit ca4cb2a144
8 files changed
+113 -10

No files matched your search

+33 -2
View File
@@ -59,6 +59,14 @@ def node_version_ok(text):
return bool(match) and int(match.group(1)) >= 22
def model_files(text):
"""Cache file names node-llama-cpp gives the hf: model URIs in qmd-lib.mjs: hf_<owner>_<file> plus <file>.etag."""
names = set()
for owner, file in re.findall(r"'hf:([^/']+)/[^/']+/([^/']+\.gguf)'", text):
names |= {f'hf_{owner}_{file}', f'{file}.etag'}
return names
def digest(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
@@ -176,8 +184,9 @@ class Setup:
state['owned_package'] = True
self.install_scripts(state)
atomic_json(self.state_path, state)
# Rewrite the setup-owned block on every run so changed default models reach existing installs.
output = self.node('qmd-config.mjs', 'set-models')
if not state['models_block']:
output = self.node('qmd-config.mjs', 'set-models')
try:
previous = json.loads(output.strip().splitlines()[-1])['previous']
except (IndexError, KeyError, TypeError, json.JSONDecodeError):
@@ -190,6 +199,28 @@ class Setup:
after = {p.name for p in self.models.iterdir()} if self.models.is_dir() else set()
state['owned_models'] = sorted(set(state['owned_models']) | (after - before))
atomic_json(self.state_path, state)
self.prune_models(state)
def prune_models(self, state):
"""Delete setup-downloaded model files the current models no longer use; foreign files stay."""
current = model_files((self.root / 'shared' / 'qmd' / 'qmd-lib.mjs').read_text(encoding='utf-8'))
if not current: # an unparsable model list must never delete every model
return
kept = []
for name in state['owned_models']:
if name in current:
kept.append(name)
continue
path = self.models / name
if name != Path(name).name or not path.is_file() or path.is_symlink():
continue # already gone, or not a plain file the setup can safely delete
try:
path.unlink()
except OSError as error: # a running daemon may still hold it; the next update retries
print(f'QMD local search: could not delete unused model {name}: {error}', file=sys.stderr)
kept.append(name)
state['owned_models'] = sorted(kept)
atomic_json(self.state_path, state)
def detect_gpu(self):
try:
@@ -205,7 +236,7 @@ class Setup:
def enable(self, clients):
state = self.load()
if self.dry_run:
self.say('DRYRUN enable QMD local search: Qwen3-Embedding-0.6B, Qwen3-Reranker-0.6B, QMD query expansion 1.7B')
self.say('DRYRUN enable QMD local search: Qwen3-Embedding-4B, Qwen3-Reranker-4B, QMD query expansion 1.7B')
return
self.install(state)
if state['device'] is None: