← Back to Pull requests

feat: add offline text ingestion vertical slice #5

Closed
unknown closed this pull request without merging on Oct 01, 2026 14:42 UTC
View on GitHub
unknown unknown commented on Oct 01, 2026 04:47 UTC
Author

Problem

The repository has no validated path from raw source documents to the Qdrant text index consumed by online retrieval.

Phase 1 contract

This PR implements UTF-8 TXT → deterministic character chunks → text embedding interface → configured BGE adapter → Qdrant text points → existing online text reader and authorization filtering.

Storage contract

  • Logical document identity: stable doc_id from source identity.

  • Logical chunk identity: stable chunk_id from source identity, content digest, chunk ordinal, and chunk digest.

  • Physical Qdrant point identity: deterministic UUIDv5 from logical chunk_id plus doc_version_epoch, so identical content can coexist safely across epochs.

  • Payload: doc_id, chunk_id, chunk_index, content, source_path, content_hash, doc_type, embedding_type, role_mask, dept_mask, status, doc_version_epoch, and source metadata.

  • Permissions are required uint32 masks; status is active; epoch is explicit and matched by the online Qdrant filter.

  • Vector dimension and collection come from config.json (rag_text_768, 768 dimensions); cosine distance is validated.

  • Reingestion uses a per-document/epoch POSIX file lock. By default it is in the current user's temporary lock directory; set OFFLINE_INGESTION_LOCK_DIR to a shared private directory when processes have separate temp namespaces. Same-epoch replacement archives old points before upsert and removes stale IDs; different epochs remain intact; empty documents remove prior same-epoch points.

  • Concurrent collection creation tolerates only an explicit already-exists conflict, then reads and validates the existing schema. Other errors propagate.

  • Dense retrieval paginates until it obtains top_k unique document IDs or exhausts the Qdrant results.
  • BGE boundary

    The production adapter lazily uses EmbeddingService, the same configured AutoTokenizer, AutoModel, and attention-mask-aware mean pooling used for online text queries. Ingestion uses the configured bounded embedding batch size (default 32). CI uses a deterministic test embedder; no BGE model is downloaded. A real BGE model smoke test was not run.

    Authorization

    Every stored point includes valid role and department masks. The existing fail-closed ParallelRecallManager authorization path allows matching users and rejects callers lacking either required permission. Qdrant filters active status and the configured epoch before retrieval. QDRANT_HOST, QDRANT_PORT, and QDRANT_GRPC_PORT environment settings are applied by the shared config used by both ingestion and the online reader.

    Bounded input and idempotence

    By default the TXT slice accepts at most 131072 input bytes and 256 chunks per document, configurable through knowledge_base.max_document_bytes and knowledge_base.max_chunks; oversized inputs fail before embedding or collection initialization. Repeating the same source content, chunk settings, and epoch creates the same physical point IDs. The same content in a different epoch has distinct physical IDs and coexists. Changed content is detected by its content hash; stale points are removed only within the replaced document/epoch. RRF scores a source document at most once per retrieval path and carries distinct top-ranked chunk evidence from different paths into the fused content.

    Validation

  • Focused: python3 -m pytest tests/test_offline_text_ingestion.py -q --tb=short — 37 passed.

  • Full: python3 -m pytest tests/ -q --tb=short — 631 passed.

  • Collection: python3 -m pytest --collect-only -q — 631 collected.

  • python3 scripts/check_repo_consistency.py, python3 -m compileall -q ., Ruff check/format, and git diff --check passed.

  • GitHub checks on final HEAD 94d624f604e73e0af9baec1c53248db53843eecf: Python 3.10, Python 3.11, lint, pip-audit, and secret scan all succeeded.

  • Qdrant E2E uses qdrant-client 1.18.0 in local in-memory mode. Real BGE smoke was not run.

  • Codex reviewed final HEAD 94d624f604 and reported no major issues. Unresolved review thread count: 0.

  • Out of scope

    PDF, DOCX, XLSX, OCR, CLIP, Elasticsearch writer, scheduler, rebuild, feedback, RAGAS, fine-tuning, and frontend.

    Part of #2

    Diff: 526 lines (+394 / -132) across 6 files Reviewer: Xander-Xai Review duration: 595m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.48) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 526 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.375
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #5"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.8% (MEDIUM) · Higher = larger blast radius
    47.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.7% · Safe to merge
    20.7%