Make summarize fast: abstract-based input (~7s/paper vs ~2min)
Feeding 16k chars of body to an 8B model took 126s/paper (42h for the vault). The abstract already carries the gist, so cap the body excerpt to 2.5k chars and num_predict to 500 -> ~7s/paper (~2.3h total), still valid structured JSON. Add --model flag (default gemma4:E4B). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
c1da5ad249
commit
0706d18799
@@ -183,7 +183,7 @@ def cmd_summarize(args: argparse.Namespace) -> int:
|
|||||||
from .summarize import append_insight, has_summary, summarize_one
|
from .summarize import append_insight, has_summary, summarize_one
|
||||||
|
|
||||||
config, _ = _load(args.config, args.topics)
|
config, _ = _load(args.config, args.topics)
|
||||||
oc = OllamaClient()
|
oc = OllamaClient(text_model=args.model)
|
||||||
if not oc.is_up():
|
if not oc.is_up():
|
||||||
console.print("[red]Ollama not reachable.[/red]")
|
console.print("[red]Ollama not reachable.[/red]")
|
||||||
return 2
|
return 2
|
||||||
@@ -313,6 +313,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|||||||
pm = sub.add_parser("summarize", help="LLM structured summaries (gemma4 via Ollama)")
|
pm = sub.add_parser("summarize", help="LLM structured summaries (gemma4 via Ollama)")
|
||||||
pm.add_argument("--limit", type=int, default=None)
|
pm.add_argument("--limit", type=int, default=None)
|
||||||
pm.add_argument("--force", action="store_true", help="re-summarize even if done")
|
pm.add_argument("--force", action="store_true", help="re-summarize even if done")
|
||||||
|
pm.add_argument("--model", default="gemma4:E4B", help="Ollama model for summaries")
|
||||||
pm.set_defaults(func=cmd_summarize)
|
pm.set_defaults(func=cmd_summarize)
|
||||||
|
|
||||||
pb = sub.add_parser("embed", help="embed papers for semantic search (nomic via Ollama)")
|
pb = sub.add_parser("embed", help="embed papers for semantic search (nomic via Ollama)")
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ PROJECT_CONTEXT = (
|
|||||||
"and quantum computing/hardware/networking."
|
"and quantum computing/hardware/networking."
|
||||||
)
|
)
|
||||||
|
|
||||||
MAX_TEXT_CHARS = 16000
|
# The abstract carries the gist; a short body excerpt grounds problem/method.
|
||||||
|
# Keeping the input small is what makes summarization ~7s/paper instead of ~2min.
|
||||||
|
MAX_TEXT_CHARS = 2500
|
||||||
|
|
||||||
_PROMPT = """You are a research assistant building an insight digest.
|
_PROMPT = """You are a research assistant building an insight digest.
|
||||||
|
|
||||||
@@ -51,7 +53,7 @@ def build_prompt(title: str, abstract: str, body: str, context: str = PROJECT_CO
|
|||||||
|
|
||||||
def summarize_paper(client: OllamaClient, *, title: str, abstract: str, body: str) -> dict:
|
def summarize_paper(client: OllamaClient, *, title: str, abstract: str, body: str) -> dict:
|
||||||
"""Return a structured summary dict (best-effort parse of the model JSON)."""
|
"""Return a structured summary dict (best-effort parse of the model JSON)."""
|
||||||
raw = client.generate(build_prompt(title, abstract, body), json_mode=True, num_predict=800)
|
raw = client.generate(build_prompt(title, abstract, body), json_mode=True, num_predict=500)
|
||||||
try:
|
try:
|
||||||
data = json.loads(raw)
|
data = json.loads(raw)
|
||||||
except (json.JSONDecodeError, TypeError):
|
except (json.JSONDecodeError, TypeError):
|
||||||
|
|||||||
Reference in New Issue
Block a user