Hypergraph is more powerful. Transform unstructured text into structured knowledge with LLMs. Graphs, hypergraphs, and spatio-temporal extractions — with one command.
feat: scoped search — he search --source/--tag; require ontomem>=0.6.0
yifanfeng97823d451e5802
diff --git a/hyperextract/cli/cli.py b/hyperextract/cli/cli.pyindex 013b7ea..23889b8 100644--- a/hyperextract/cli/cli.py+++ b/hyperextract/cli/cli.py@@ -807,6 +807,12 @@ def search(ka_path: str = typer.Argument(..., help="Knowledge Abstract directory"),query: str = typer.Argument(..., help="Search query"),top_k: int = typer.Option(3, "--top-k", "-n", help="Number of results"),+ source: list[str] | None = typer.Option(+ None, "--source", help="Scope: only knowledge from these source documents"+ ),+ tag: list[str] | None = typer.Option(+ None, "--tag", help="Scope: only knowledge from sources carrying these tags"+ ),):"""Semantic search in Knowledge Abstract."""logger.info("command=search ka_path=%s query=%s top_k=%d", ka_path, query, top_k)@@ -836,7 +842,12 @@ def search(ka.load(path)progress.update(task, description="Searching...")- results = ka.search(query, top_k=top_k)+ scope_kwargs = {}+ if source:+ scope_kwargs["source_ids"] = list(source)+ if tag:+ scope_kwargs["tags"] = list(tag)+ results = ka.search(query, top_k=top_k, **scope_kwargs)logger.info("stage=search_complete results=%d", len(results))except Exception as e:@@ -914,6 +925,61 @@ def chat_loop(ka, ka_path: str, top_k: int = 3):console.print(f"[red]Error:[/red] {e}")[email protected](name="tag")+def tag(+ ka_path: str = typer.Argument(..., help="Knowledge Abstract directory"),+ source: str = typer.Option(..., "--source", help="Source document id to tag"),+ add: list[str] | None = typer.Option(+ None, "--add", help="Tag(s) to add (repeatable)"+ ),+ remove: list[str] | None = typer.Option(+ None, "--remove", help="Tag(s) to remove (repeatable)"+ ),+ list_sources: bool = typer.Option(+ False, "--list", "-l", help="List all sources with their tags"+ ),+):+ """Manage tags on source documents (for scoped search and rollback)."""+ logger.info("command=tag ka_path=%s source=%s", ka_path, source)++ path = validate_ka_with_data(ka_path)+ template, lang = get_template_from_ka(path)+ ka = Template.create(template, lang)+ ka.load(path)++ if list_sources:+ table = Table(title="Source Ledger")+ table.add_column("Source ID", style="cyan")+ table.add_column("Raw Items", justify="right")+ table.add_column("Tags", style="green")+ combined = ka.sources()+ for sid, info_row in sorted(combined.items()):+ tags = ka.source_tags(sid)+ table.add_row(+ sid, str(info_row.get("raw_items", "—")), ", ".join(tags) or "—"+ )+ console.print(table)+ return++ if not add and not remove:+ current = ka.source_tags(source)+ console.print(+ f"[cyan]{source}[/cyan] tags: "+ + (", ".join(current) if current else "[yellow]none[/yellow]")+ )+ console.print("[dim]Use --add/--remove to modify, --list to show all.[/dim]")+ return++ tags = ka.tag_source(source, add=list(add or []), remove=list(remove or []))+ console.print(+ f"[bold green]Tagged![/bold green] {source}: {', '.join(tags) if tags else '(no tags)'}"+ )++ # Persist the ledger change (tags live in the source ledger files).+ ka.dump(path)+ console.print(f"[dim]Saved to {path}[/dim]")++@app.command(name="talk")def talk(ka_path: str = typer.Argument(..., help="Knowledge Abstract directory"),diff --git a/pyproject.toml b/pyproject.tomlindex 7b92e5b..82aec04 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -33,7 +33,7 @@ dependencies = ["langchain-community>=0.4.1","langchain-openai>=1.1.7","structlog>=25.5.0",- "ontomem>=0.5.0",+ "ontomem>=0.6.0","ontosight>=0.1.8","python-dotenv>=1.2.1","semhash>=0.4.1",diff --git a/uv.lock b/uv.lockindex 14ad6e2..8c2db41 100644--- a/uv.lock+++ b/uv.lock@@ -957,7 +957,7 @@ requires-dist = [{ name = "langchain-google-genai", marker = "extra == 'google'", specifier = ">=2.1.0" },{ name = "langchain-openai", specifier = ">=1.1.7" },{ name = "mcp", marker = "extra == 'mcp'", specifier = ">=1.2.0,<3" },- { name = "ontomem", specifier = ">=0.5.0" },+ { name = "ontomem", specifier = ">=0.6.0" },{ name = "ontosight", specifier = ">=0.1.8" },{ name = "python-dotenv", specifier = ">=1.2.1" },{ name = "rich", specifier = ">=13.7.0" },@@ -1879,7 +1879,7 @@ wheels = [[[package]]name = "ontomem"-version = "0.5.0"+version = "0.6.0"source = { registry = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/" }dependencies = [{ name = "faiss-cpu" },@@ -1891,9 +1891,9 @@ dependencies = [{ name = "python-dotenv" },{ name = "structlog" },]-sdist = { url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/fb/1e/5e1e484d8d1ee7caafebf59273a5df87d9bfbc1d5f75ff49a702e8e69372/ontomem-0.5.0.tar.gz", hash = "sha256:25dd2c9676e40e1e11fc519a5b3547c79e263bcb64c17505f0e26560e10f10ee", size = 2549972, upload-time = "2026-09-04T03:55:53.486Z" }+sdist = { url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/b1/f8/b730a2070cad15d1ee0947d5f3e5d1e5d0780903d1668f51b93a88439867/ontomem-0.6.0.tar.gz", hash = "sha256:3c25b0c2ef050f477af5eecc3893a2071399007676ff52a8b909e4da6850b9c2", size = 2550918, upload-time = "2026-09-04T11:35:21.421Z" }wheels = [- { url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/cc/42/adf7dcfc94e9e255fc52a7d38713746ad2fc83f374d157c99d7ca4ecbf82/ontomem-0.5.0-py3-none-any.whl", hash = "sha256:04b2d058cb7b0617d3f3d46fdc469282ed77cee42ccba133041807b775c42b9c", size = 47040, upload-time = "2026-09-04T03:55:52.236Z" },+ { url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/58/47/8c1074a571882b0380bd089f633b0e7d5e4cdeefd402791b9e62afe811ce/ontomem-0.6.0-py3-none-any.whl", hash = "sha256:6733e8780179b59b282bfabe317f63deeaf8853a963cf546c4722db8e4177a25", size = 47563, upload-time = "2026-09-04T11:35:19.508Z" },][[package]]