Backfill Semantic Profiles CLI
Module: aibs_backend.interfaces.cli.backfill_semantic_profiles
Purpose
Build persisted semantic document profiles for already-ingested documents.
Semantic profiles are source-grounded document metadata used by routing, category document-set discovery, catalog planning, and retrieval projections. They are not route-memory records and they are not parser/processing family labels.
Use this CLI for documents ingested before semantic profiles existed, after semantic profile schema/quality changes, or after degraded semantic profiles were persisted during the normal ingestion path.
Command
pdm run python -m aibs_backend.interfaces.cli.backfill_semantic_profiles \
[--workspace <uuid>] [--dry-run] [--force] [--limit N] \
[--page-size 50] [--concurrency 2]
or:
python -m aibs_backend.interfaces.cli.backfill_semantic_profiles \
[--workspace <uuid>] [--dry-run] [--force] [--limit N] \
[--page-size 50] [--concurrency 2]
Options
Option |
Meaning |
|---|---|
|
Process one workspace. Omit to process all workspaces. |
|
Run enrichment and report results without saving document changes. |
|
Rebuild even when a current non-legacy profile already exists. |
|
Maximum number of source documents to inspect in this run. Omit for full coverage. |
|
Repository page size. Default is |
|
Maximum documents enriched concurrently by this CLI process. Default is |
Semantic Profile Contract
The persisted profile schema is SemanticDocumentProfileV1 and includes:
document_rolesdomain_familiesbusiness_typestopicsentitieskey_sectionsdocument_set_keyslegal_referencescompletenessconfidenceevidence_refsbuilt_byschema_version
Values must come from the document’s own source packet: parsed metadata, document context, section headings, and chunk samples. File names and titles may help identify the document, but they must not be treated as enough evidence for semantic category truth unless document content also supports the label.
Processing labels such as narrative_document, research_pdf, or
technical_manual belong to ingestion behavior and must not be copied into
semantic fields.
Model Lane
The default semantic-profile model is qwen3:8b.
Relevant settings:
Setting |
Meaning |
|---|---|
|
Optional provider override. |
|
Optional model endpoint override. |
|
Model used for enrichment. Default: |
|
Per-model request gate. |
|
Request timeout. |
|
Admission wait limit for semantic-profile model work. |
|
JSON output budget. |
|
Context budget for the source packet. |
|
Model keep-alive hint. |
|
Global admission weighting for the semantic-profile role. |
Execution Flow
Validate arguments and optional workspace ID.
Build the application container from
.env.Page documents from the selected workspace or all workspaces.
Skip failed/deleted documents.
Skip documents without parsed and chunked artifacts.
Skip current non-legacy profiles unless
--forceis set.Build a baseline artifact profile from existing metadata, context, headings, chunks, and identifier patterns.
Call the configured semantic-profile enricher with retries.
Persist the enriched
semantic_profileon the document unless--dry-runis set.Print progress and a final report.
Failure Behavior
Live ingestion and this maintenance CLI intentionally differ:
Live ingestion retries semantic enrichment and can persist an unavailable profile so the durable ingestion job completes degraded.
This CLI reports failed documents and does not save an unavailable replacement.
That behavior is deliberate. Backfill is a repair tool, so failures should stay visible to the operator.
Report Fields
Field |
Meaning |
|---|---|
|
Documents inspected. |
|
Documents with a newly saved or dry-run enriched profile. |
|
Existing profile matched the enriched result. |
|
Current profile exists and |
|
Parsed document or chunk set is missing. |
|
Document is failed or deleted. |
|
Enrichment failed after retries. |
Dry runs prefix output with [DRY-RUN] and print No documents were persisted.
Recommended Maintenance Sequence
For a scoped backfill:
pdm run python -m aibs_backend.interfaces.cli.backfill_semantic_profiles \
--workspace <uuid> --dry-run
pdm run python -m aibs_backend.interfaces.cli.backfill_semantic_profiles \
--workspace <uuid>
pdm run python -m aibs_backend.interfaces.cli.rebuild_document_catalog \
--workspace <uuid> --validate-only
pdm run python -m aibs_backend.interfaces.cli.rebuild_document_catalog \
--workspace <uuid>
pdm run python -m aibs_backend.interfaces.cli.rebuild_retrieval_pyramid \
--workspace <uuid> --validate-only
pdm run python -m aibs_backend.interfaces.cli.rebuild_retrieval_pyramid \
--workspace <uuid>
Use --force only when semantic profile quality or schema changed and existing
profiles must be regenerated.
Validation
Use code-owned artifacts and CLI reports for validation:
the CLI report should have
failed=0skipped_missing_artifactsshould be explained by missing parsed/chunked statesampled persisted documents should contain
parsed_document.metadata.semantic_profilecurrent profiles should have
schema_version=1profiles with
completeness=missingorconfidence=lowshould be reviewedprojection validation counts should be clean after catalog and retrieval rebuilds
Do not validate a full selected scope with --limit unless the goal is only a
smoke test.