Commit 711e611e authored by Kantz's avatar Kantz
Browse files

clear zum einbetten hinzugefügt

parent b3cd9984
......@@ -39,7 +39,7 @@ Ingest markdown docs (expects `markdown/sections`, `markdown/subsections`, `mark
```powershell
cd math-tutor/backend
.\.venv\Scripts\Activate.ps1
python .\scripts\retrieval_cli.py ingest --base markdown
python .\scripts\retrieval_cli.py ingest --base markdown --clear
```
Query via CLI:
......
......@@ -227,6 +227,13 @@ def upsert_docs(pg_url: str, docs: List[DocRecord], embeddings: List[List[float]
return len(rows)
def clear_docs(pg_url: str) -> None:
with psycopg.connect(pg_url) as conn:
with conn.cursor() as cur:
cur.execute("TRUNCATE TABLE docs;")
conn.commit()
@dataclass
class Retrieved:
uid: str
......
......@@ -43,6 +43,8 @@ def cli_ingest(args: argparse.Namespace) -> None:
pg_url = args.pg or os.getenv("POSTGRES_URL")
if not pg_url:
raise ValueError("Missing POSTGRES_URL")
if args.clear:
vector_store.clear_docs(pg_url)
upserted = vector_store.upsert_docs(pg_url, docs, embeddings)
print(f"Ingested/upserted docs: {upserted}")
......@@ -92,6 +94,7 @@ def main() -> int:
ap_ing = sub.add_parser("ingest", help="Embed and upsert markdown docs")
ap_ing.add_argument("--pg", default=None, help="Postgres URL (or set POSTGRES_URL)")
ap_ing.add_argument("--base", default="markdown", help="Base folder with sections/subsections/childs")
ap_ing.add_argument("--clear", action="store_true", help="Clear docs table before ingest")
ap_ing.set_defaults(func=cli_ingest)
ap_q = sub.add_parser("query", help="Run retrieval")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment