Spaces:
Sleeping
Sleeping
Commit Β·
ec44444
1
Parent(s): 12f33ae
fix(de-stale): remove deleted get_fast_brain_llm (broke rag.extract import)
Browse filesThe audit framework's Tier-2 surfaced this real defect: get_fast_brain_llm
was deleted in the 2026-05-15 three-chain collapse but still imported/called
by rag/extract.py (raised ImportError on import), tools/reextract_all.py, and
imported-unused by tools/extract_all_corpus.py. Collapsed to the surviving
get_brain_llm() (its NimChainLLM already does internal fallback); fixed the
now-false primary/fallback comments + rag/README. rag.extract now imports
clean. Local only β not pushed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- rag/README.md +1 -1
- rag/extract.py +8 -5
- tools/extract_all_corpus.py +1 -1
- tools/reextract_all.py +3 -3
rag/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Lineage for every artefact below is documented in [`kb/AUDIT_TRAIL.md`](../kb/AU
|
|
| 12 |
| `download_retry.py` | 3. DOWNLOAD | Retries the failures from the previous run. |
|
| 13 |
| `download_regulatory.py` | 3. DOWNLOAD | IRDAI / regulatory PDFs (deferred from v1; see [ADR-017](../70-docs/60-decisions/ADR-017-irdai-corpus-playwright-rescue.md)). |
|
| 14 |
| `ingest.py` | 4. PARSE β 5. CHUNK β 6. EMBED β 7. INDEX | The big one. `read_pdf_pages` (pdfplumber) β `chunk_pages` (800-tok / 120 overlap, sentence-aware) β BGE embed β `chromadb.PersistentClient.add(...)`. Carries the in-process HNSW bloat tripwire ([ADR-029](../70-docs/60-decisions/ADR-029-hnsw-bloat-tripwire.md)). |
|
| 15 |
-
| `extract.py` | 8. STRUCTURED EXTRACTION | LLM extraction over each PDF using `schema.py::HealthPolicy` (62 fields). `get_brain_llm()` (Brain Main: Gemini 2.5 Flash primary per [ADR-040](../70-docs/60-decisions/ADR-040-google-gemini-primary.md))
|
| 16 |
| `build_kb.py` | 9. SCORECARD β KB MIRROR | Runs `backend/scorecard.py` per policy and regenerates the human-readable `kb/policies/<id>.md` tree. |
|
| 17 |
| `source_map.py` | post-build | Builds `source_map.json` β every chunk β (PDF path, page, span) for citation rendering. |
|
| 18 |
|
|
|
|
| 12 |
| `download_retry.py` | 3. DOWNLOAD | Retries the failures from the previous run. |
|
| 13 |
| `download_regulatory.py` | 3. DOWNLOAD | IRDAI / regulatory PDFs (deferred from v1; see [ADR-017](../70-docs/60-decisions/ADR-017-irdai-corpus-playwright-rescue.md)). |
|
| 14 |
| `ingest.py` | 4. PARSE β 5. CHUNK β 6. EMBED β 7. INDEX | The big one. `read_pdf_pages` (pdfplumber) β `chunk_pages` (800-tok / 120 overlap, sentence-aware) β BGE embed β `chromadb.PersistentClient.add(...)`. Carries the in-process HNSW bloat tripwire ([ADR-029](../70-docs/60-decisions/ADR-029-hnsw-bloat-tripwire.md)). |
|
| 15 |
+
| `extract.py` | 8. STRUCTURED EXTRACTION | LLM extraction over each PDF using `schema.py::HealthPolicy` (62 fields). `get_brain_llm()` (Brain Main: Gemini 2.5 Flash primary per [ADR-040](../70-docs/60-decisions/ADR-040-google-gemini-primary.md)) β a `NimChainLLM` fallback chain (the separate `get_fast_brain_llm()` accessor was removed in the 2026-05-15 three-chain collapse) across Google β NIM β OpenRouter. Native JSON mode (`response_mime_type=application/json` on Gemini, `response_format={"type":"json_object"}` on NIM). Writes `rag/extracted/<policy_id>.json` + upserts `policies.duckdb`. |
|
| 16 |
| `build_kb.py` | 9. SCORECARD β KB MIRROR | Runs `backend/scorecard.py` per policy and regenerates the human-readable `kb/policies/<id>.md` tree. |
|
| 17 |
| `source_map.py` | post-build | Builds `source_map.json` β every chunk β (PDF path, page, span) for citation rendering. |
|
| 18 |
|
rag/extract.py
CHANGED
|
@@ -37,7 +37,6 @@ from backend.providers.base import ChatMessage
|
|
| 37 |
from backend.providers.nvidia_nim_llm import (
|
| 38 |
NvidiaNimLLM,
|
| 39 |
get_brain_llm,
|
| 40 |
-
get_fast_brain_llm,
|
| 41 |
)
|
| 42 |
from rag.ingest import policy_id_for
|
| 43 |
from rag.schema import HealthPolicy
|
|
@@ -338,10 +337,14 @@ async def main():
|
|
| 338 |
# different MoE routing path so a Pro timeout doesn't always reproduce
|
| 339 |
# in Flash. Sarvam-M was the old fallback but its <think> tags ate the
|
| 340 |
# 2048 output cap before reaching JSON, causing ~20 truncation failures.
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
t0 = time.time()
|
| 346 |
ok = 0
|
| 347 |
for i, pdf in enumerate(pdfs, 1):
|
|
|
|
| 37 |
from backend.providers.nvidia_nim_llm import (
|
| 38 |
NvidiaNimLLM,
|
| 39 |
get_brain_llm,
|
|
|
|
| 40 |
)
|
| 41 |
from rag.ingest import policy_id_for
|
| 42 |
from rag.schema import HealthPolicy
|
|
|
|
| 337 |
# different MoE routing path so a Pro timeout doesn't always reproduce
|
| 338 |
# in Flash. Sarvam-M was the old fallback but its <think> tags ate the
|
| 339 |
# 2048 output cap before reaching JSON, causing ~20 truncation failures.
|
| 340 |
+
# Three-chain collapse (2026-05-15): the separate FAST_BRAIN_CHAIN /
|
| 341 |
+
# get_fast_brain_llm accessor was removed. One brain chain (get_brain_llm)
|
| 342 |
+
# whose NimChainLLM already does internal multi-candidate fallback;
|
| 343 |
+
# primary/fallback both resolve to it.
|
| 344 |
+
primary = get_brain_llm()
|
| 345 |
+
fallback = get_brain_llm()
|
| 346 |
+
|
| 347 |
+
print(f"Extracting {len(pdfs)} policies. via the brain chain (get_brain_llm, internal fallback).\n")
|
| 348 |
t0 = time.time()
|
| 349 |
ok = 0
|
| 350 |
for i, pdf in enumerate(pdfs, 1):
|
tools/extract_all_corpus.py
CHANGED
|
@@ -13,7 +13,7 @@ from pathlib import Path
|
|
| 13 |
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
| 14 |
from rag.extract import extract_one, find_pdfs, load_manifest, init_db, EXTRACTED_DIR, ROOT
|
| 15 |
from rag.ingest import policy_id_for
|
| 16 |
-
from backend.providers.nvidia_nim_llm import get_brain_llm,
|
| 17 |
|
| 18 |
|
| 19 |
async def run_one(pdf, manifest, primary, fallback, sem, idx, total):
|
|
|
|
| 13 |
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
| 14 |
from rag.extract import extract_one, find_pdfs, load_manifest, init_db, EXTRACTED_DIR, ROOT
|
| 15 |
from rag.ingest import policy_id_for
|
| 16 |
+
from backend.providers.nvidia_nim_llm import get_brain_llm, NvidiaNimLLM
|
| 17 |
|
| 18 |
|
| 19 |
async def run_one(pdf, manifest, primary, fallback, sem, idx, total):
|
tools/reextract_all.py
CHANGED
|
@@ -26,7 +26,7 @@ from rag.extract import (
|
|
| 26 |
EXTRACTED_DIR, ROOT,
|
| 27 |
)
|
| 28 |
from rag.ingest import policy_id_for
|
| 29 |
-
from backend.providers.nvidia_nim_llm import get_brain_llm
|
| 30 |
|
| 31 |
|
| 32 |
async def run_one(pdf: Path, manifest: dict, primary, fallback, sem, idx: int, total: int) -> tuple[str, Path, float]:
|
|
@@ -61,10 +61,10 @@ async def main():
|
|
| 61 |
manifest = load_manifest()
|
| 62 |
|
| 63 |
primary = get_brain_llm()
|
| 64 |
-
fallback =
|
| 65 |
sem = asyncio.Semaphore(3)
|
| 66 |
|
| 67 |
-
print(f"Re-extracting {len(pdfs)} insurer PDFs.
|
| 68 |
t_start = time.time()
|
| 69 |
tasks = [
|
| 70 |
run_one(pdf, manifest, primary, fallback, sem, i + 1, len(pdfs))
|
|
|
|
| 26 |
EXTRACTED_DIR, ROOT,
|
| 27 |
)
|
| 28 |
from rag.ingest import policy_id_for
|
| 29 |
+
from backend.providers.nvidia_nim_llm import get_brain_llm
|
| 30 |
|
| 31 |
|
| 32 |
async def run_one(pdf: Path, manifest: dict, primary, fallback, sem, idx: int, total: int) -> tuple[str, Path, float]:
|
|
|
|
| 61 |
manifest = load_manifest()
|
| 62 |
|
| 63 |
primary = get_brain_llm()
|
| 64 |
+
fallback = get_brain_llm()
|
| 65 |
sem = asyncio.Semaphore(3)
|
| 66 |
|
| 67 |
+
print(f"Re-extracting {len(pdfs)} insurer PDFs. via the brain chain (internal fallback), concurrency=3.\n")
|
| 68 |
t_start = time.time()
|
| 69 |
tasks = [
|
| 70 |
run_one(pdf, manifest, primary, fallback, sem, i + 1, len(pdfs))
|