Skip to main content

Documents and Maintenance

Documents store metadata for physical files. Maintenance requests track operational issues and interventions.

documents

Purpose

Stores metadata for physical files saved on disk or object storage.

Suggested attributes

FieldDescription
idPrimary identifier.
entity_typeLinked business entity type.
entity_idLinked business entity identifier.
document_typeContract, invoice, bill, identity document, receipt, photo, report, or other document type.
file_pathDisk or object storage path.
file_nameOriginal or display file name.
mime_typeFile MIME type.
uploaded_by_user_idPlatform user who uploaded the file.
created_atCreation timestamp.
notesFree-form notes.

Linked entities

EntityExample use
partyIdentity document, company certificate, tax document.
propertyCadastral document, floor plan, property photo.
property_unitRoom photo, room inventory.
contractContract PDF or registration receipt.
bank_transactionBank receipt or supporting proof.
expected_expenseExpected bill notice.
utility_billUtility bill PDF.
maintenance_requestPhotos, estimates, completion proof.
expenseInvoice or receipt.

Relationships

RelationshipDescription
documents.uploaded_by_user_id to users.idOptional uploader reference.
documents.entity_type and documents.entity_idPolymorphic business link.

Notes and design rationale

Contracts are business entities. The contract PDF is a document linked to a contract. File storage concerns should remain separate from business records.

vector_rebuild_runs

Purpose

Tracks administrator-triggered Vector DB rebuild executions. The table stores the durable state of a rebuild; WebSocket events are only a live delivery mechanism and are not the source of truth.

Suggested attributes

FieldDescription
idPrimary identifier.
statusPENDING, RUNNING, COMPLETED, COMPLETED_WITH_ERRORS, FAILED, or CANCELLED.
started_by_user_idAdmin user who started the rebuild.
cancelled_by_user_idAdmin user who requested cancellation.
started_atRebuild start timestamp.
finished_atRebuild completion/cancellation/failure timestamp.
total_documentsNumber of candidate documents for the run.
processed_documentsNumber of documents processed so far.
failed_documentsNumber of failed documents.
skipped_documentsNumber of skipped documents.
options_jsonRebuild options used for the run.
summary_jsonFinal counters and technical summary.
error_messageRun-level error when the whole run fails.

summary_json.metrics stores the operational summary:

MetricMeaning
totalDurationMsTotal run duration in milliseconds.
documentsPerMinuteProcessed documents per minute.
ocrFailuresFailed items classified as OCR/text-extraction failures.
indexingFailuresFailed items classified as indexing/vector failures.
indexedSuccessfully indexed documents.
failedFailed documents.
skippedSkipped documents.

vector_rebuild_run_items

Purpose

Tracks per-document rebuild state for one Vector DB rebuild run.

Suggested attributes

FieldDescription
idPrimary identifier.
run_idParent rebuild run.
document_idDocument being processed. Nullable to preserve run audit if a document is later deleted.
document_version_idDocument version processed by the run. Nullable to preserve run audit if a version is later deleted.
statusPENDING, PROCESSING, INDEXED, SKIPPED, or FAILED.
ocr_appliedWhether OCR was applied during processing.
chunks_createdNumber of vector chunks created.
error_messageItem-level error.
started_atItem processing start timestamp.
finished_atItem processing end timestamp.

Ownership

document-indexer-service owns rebuild orchestration and Vector DB writes. docs-service owns document download and storage access. datahub owns persistence. redisWsBridge delivers progress events to AdminInterface.

Security and audit

All admin rebuild endpoints are protected server-side through authService /auth/validate; the UI token is validated by the backend before any run or preview is created.

Security constraints:

  • AdminInterface never receives storage tokens, storage object keys, document contents, extracted text, or vector chunk text.
  • Preview returns only technical metadata and counters.
  • Redis events contain only runId, state, counters, documentId, OCR yes/no, chunk count, timestamps, and compact errors.
  • Logs must not include document content, chunk text, storage object keys, or provider tokens.
  • started_by_user_id and cancelled_by_user_id provide auditability for destructive/expensive operations.

Rebuild preview options

The first admin endpoint for this capability is POST /document-indexer-service/admin/vector-rebuild/preview.

Supported options:

OptionValues
modemissing_only, changed_only, full_rebuild
scopeall, entity_type, entity_id, document_id
deleteBeforeReindexBoolean, used by later execution endpoints.
forceOcrBoolean.
maxDocumentsPositive integer with service-side cap.
dryRunAlways treated as true by the preview endpoint.

The preview endpoint is read-only: it reads document metadata and extracted text presence from datahub, but does not download files, run OCR, create embeddings, or write to Qdrant.

Rebuild run APIs

EndpointPurpose
POST /document-indexer-service/admin/vector-rebuild/startCreates a run, creates run items, starts async processing, and returns runId immediately.
GET /document-indexer-service/admin/vector-rebuild/runsLists rebuild runs for history and recovery.
GET /document-indexer-service/admin/vector-rebuild/runs/:idReturns one rebuild run.
GET /document-indexer-service/admin/vector-rebuild/runs/:id/itemsLists per-document items for a rebuild run.
POST /document-indexer-service/admin/vector-rebuild/runs/:id/cancelMarks the run as CANCELLED; the worker stops between documents.
POST /document-indexer-service/admin/vector-rebuild/runs/:id/retry-failedCreates a new run with only failed items from the source run.

Rollout note:

  • First release: schema, dry-run, and AdminInterface preview only.
  • Second release: single-document rebuild is enabled with VECTOR_REBUILD_SINGLE_DOCUMENT_ENABLED=true; start requests must use scope=document_id.
  • Third release: batch rebuild is enabled with VECTOR_REBUILD_EXECUTION_ENABLED=true; all scopes can be executed and maxDocuments controls batch size.
  • Fourth release: retry failed items, cancellation controls, complete paginated history, and operational refinements in AdminInterface.

Execution is idempotent at document level: before rebuilt chunks are inserted, existing Qdrant points for that document_id are deleted. Chunk metadata includes document_id, document_version_id, chunk_index, checksum, entity_type, and entity_id.

OCR remains owned by docs-service. The rebuild worker reuses stored document_texts when available and long enough; otherwise it sends the downloaded file to docs-service /docs/text/extract and indexes the returned extracted/OCR text.

Rebuild live events

document-indexer-service publishes Redis events after persisted run/item state changes. WebSocket delivery through redisWsBridge is best-effort; the persisted run tables remain the source of truth.

EventMeaning
vector_rebuild.startedRun and items were created.
vector_rebuild.progressCounters changed.
vector_rebuild.item_completedOne document was indexed.
vector_rebuild.item_failedOne document failed and the run continued.
vector_rebuild.completedRun reached COMPLETED or COMPLETED_WITH_ERRORS.
vector_rebuild.failedRun-level failure.
vector_rebuild.cancelledRun was cancelled.

Payloads include runId, status, counters, timestamp, and, when applicable, documentId and a short error message.

Operational limits and recovery

The first implementation processes one document at a time. This keeps storage, OCR, embedding generation, and Qdrant load predictable. Cancellation is cooperative: if a document is already being indexed, processing stops before the next item.

If WebSocket delivery is unavailable, AdminInterface must show a warning and use the persisted run APIs as recovery source:

  1. GET /document-indexer-service/admin/vector-rebuild/runs/:id
  2. GET /document-indexer-service/admin/vector-rebuild/runs/:id/items

Recommended recovery procedure:

  1. Inspect the run status and failed items.
  2. Use compact item errors to identify the failing capability: storage download, OCR, embedding, or Vector DB.
  3. Fix the owner service/configuration.
  4. Retry with document_id, entity_id, or missing_only scope before using full_rebuild.

maintenance_requests

Purpose

Tracks maintenance issues and interventions.

Suggested attributes

FieldDescription
idPrimary identifier.
property_idLinked property.
property_unit_idOptional unit attribution.
reported_by_party_idParty that reported the issue.
assigned_to_party_idAssigned provider, manager, or internal party.
categoryMaintenance category.
priorityLOW, MEDIUM, HIGH, or URGENT.
statusOPEN, IN_PROGRESS, WAITING_FOR_SUPPLIER, COMPLETED, or CANCELLED.
descriptionIssue description.
estimated_costEstimated cost.
final_costFinal cost.
document_idOptional primary document.
created_atCreation timestamp.
closed_atClosure timestamp.

Relationships

RelationshipDescription
maintenance_requests.property_id to properties.idEach request belongs to a property.
maintenance_requests.property_unit_id to property_units.idOptional unit-level request.
maintenance_requests.reported_by_party_id to parties.idReporter party.
maintenance_requests.assigned_to_party_id to parties.idAssigned party or provider.
maintenance_requests.document_id to documents.idOptional primary document.
maintenance_requests to expensesA maintenance request may generate one or more expenses.

Notes and design rationale

Maintenance requests connect operational workflows to properties, tenants, providers, expenses, and documents. Future implementations may add a dedicated maintenance-expense join table if one request generates several invoices.

Graphical local diagrams

documents

maintenance_requests