Skip to content

Commit 877d139

Browse files
author
Daniele Briggi
committed
feat(cli): download model command
1 parent 1f5d0e2 commit 877d139

File tree

5 files changed

+57
-7
lines changed

5 files changed

+57
-7
lines changed

.github/workflows/pypi-package.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ jobs:
4343
echo "version=$VERSION" >> $GITHUB_OUTPUT
4444
4545
- name: Build
46-
env:
47-
PACKAGE_VERSION: ${{ steps.get_version.outputs.version }}
4846
run: |
4947
# Update version in pyproject.toml
5048
sed -i 's/^version = ".*"/version = "${{ steps.get_version.outputs.version }}"/' pyproject.toml

bandit.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# https://bndit.readthedocs.io/en/latest/config.html
2-
skips: ['B101', 'B608']
2+
skips: ['B101', 'B615']
33
exclude_dirs: ['tests']

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ classifiers = [
1818
dependencies = [
1919
"attrs",
2020
"typer",
21-
"huggingface_hub",
21+
"huggingface_hub[cli]",
2222
"markitdown[all]",
2323
"sqlite-ai",
2424
"sqliteai-vector"
2525
]
2626

2727
[project.optional-dependencies]
2828
dev = [
29+
"toml",
2930
"pytest",
3031
"pytest-cov",
3132
"black",

src/sqlite_rag/cli.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import shlex
44
import sys
5+
from pathlib import Path
56
from typing import Optional
67

78
import typer
@@ -344,6 +345,56 @@ def search(
344345
typer.echo(f"{idx:<3} {snippet:<60} {uri:<40}")
345346

346347

348+
@app.command("download-model")
349+
def download_model(
350+
model_id: str = typer.Argument(
351+
..., help="Hugging Face model ID (e.g., Qwen/Qwen3-Embedding-0.6B-GGUF)"
352+
),
353+
gguf_file: str = typer.Argument(
354+
..., help="GGUF filename to download (e.g., Qwen3-Embedding-0.6B-Q8_0.gguf)"
355+
),
356+
local_dir: str = typer.Option(
357+
"./models", "--local-dir", "-d", help="Local directory to download to"
358+
),
359+
revision: str = typer.Option(
360+
"main", "--revision", "-r", help="Model revision/branch to download from"
361+
),
362+
):
363+
"""Download a GGUF model file from Hugging Face"""
364+
try:
365+
from huggingface_hub import hf_hub_download
366+
except ImportError:
367+
typer.echo(
368+
"Error: huggingface_hub not found. Install with: pip install huggingface_hub"
369+
)
370+
raise typer.Exit(1)
371+
372+
# Create local directory structure
373+
local_path = Path(local_dir) / model_id
374+
local_path.mkdir(parents=True, exist_ok=True)
375+
376+
typer.echo(f"Downloading {gguf_file} from {model_id}...")
377+
378+
try:
379+
# Download the specific GGUF file
380+
downloaded_path = hf_hub_download(
381+
repo_id=model_id,
382+
filename=gguf_file,
383+
local_dir=str(local_path),
384+
revision=revision,
385+
)
386+
387+
final_path = Path(downloaded_path)
388+
typer.echo(f"Downloaded to: {final_path}")
389+
390+
if final_path.exists():
391+
typer.echo(f"File size: {final_path.stat().st_size / (1024*1024):.1f} MB")
392+
393+
except Exception as e:
394+
typer.echo(f"Error downloading model: {e}")
395+
raise typer.Exit(1)
396+
397+
347398
def repl_mode():
348399
"""Interactive REPL mode"""
349400
typer.echo("Entering interactive mode. Type 'help' for commands or 'exit' to quit.")

src/sqlite_rag/settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ class Settings:
1414
model_path_or_name: str = (
1515
"./models/Qwen/Qwen3-Embedding-0.6B-GGUF/Qwen3-Embedding-0.6B-f16.gguf"
1616
)
17-
model_config: str = "n_ctx=12000,pooling_type=last,normalize_embedding=1"
17+
model_config: str = "n_ctx=128,pooling_type=last,normalize_embedding=1"
1818

1919
vector_type: str = "FLOAT16"
2020
embedding_dim: int = 1024
2121
other_vector_config: str = "distance=cosine" # e.g. distance=metric,other=value,...
2222

23-
chunk_size: int = 12000
23+
chunk_size: int = 128
2424
# Token overlap between chunks
25-
chunk_overlap: int = 1200
25+
chunk_overlap: int = 20
2626

2727
#
2828
# Search settings

0 commit comments

Comments
 (0)