infrastructure tier

infrastructure-doc-ingest

Document ingest shared by the wiki index and the source-code corpus: markdown front-matter/heading parsing and chunking, rename planning from content hashes, source-kind classification, git provenance, and database row counts

Document ingest shared by the wiki index and the source-code corpus: markdown front-matter/heading parsing and chunking, rename planning from content hashes, source-kind classification, git provenance, and database row counts

Tierinfrastructure
Roleunclassified (baselined)
Pathcrates/infrastructure/doc-ingest
Edition2021
Targetsinfrastructure_doc_ingest
Public items33 across 5 modules
Tests42

What it is for

Document-ingest library crates shared by the wiki index and the source-code corpus (sprint 4.21).

These lived in tools-org-knowledge because the wiki was written first. When the source-code corpus moved out to tools-corpus, both consumers needed them — and a shared library crate belongs below both, not inside one.

file-absolute offsets, per-section chunking.

source-kind classification, title derivation, git provenance.

hand (rule 14).

Capabilities

db_stats (other)

Generic per-table row counting, shared across whichever database a

Item
async fn table_row_counts(pool : & PgPool, tables : & & str,) -> Result <Vec <(String, i64)>, sqlx::Error>

embedder (other)

Adapter wiring infrastructure_embeddings::Embedder into

Item
pub const MODEL_DIR_ENV: & str

AnyEmbedder

Adapter wiring infrastructure_embeddings::Embedder into

Item
pub enum AnyEmbedder
AnyEmbedder :: fn model_id(& self) -> & str
AnyEmbedder :: fn dimensions(& self) -> usize
AnyEmbedder :: async fn embed_batch(& self, texts : & String) -> Result <Vec <Vec <f32>>, EmbedError>
fn embedder_from_env() -> Result <AnyEmbedder, String>

KnowledgeEmbedderAdapter

Adapter wiring infrastructure_embeddings::Embedder into

Item
pub struct KnowledgeEmbedderAdapter<E : Embedder>
fn default_embedder() -> KnowledgeEmbedderAdapter <DeterministicEmbedder>

KnowledgeEmbedderAdapter<E>

Adapter wiring infrastructure_embeddings::Embedder into

Item
KnowledgeEmbedderAdapter<E> :: fn new(inner : E) -> Self
KnowledgeEmbedderAdapter<E> :: fn model_id(& self) -> & str
KnowledgeEmbedderAdapter<E> :: fn dimensions(& self) -> usize
KnowledgeEmbedderAdapter<E> :: async fn embed_batch(& self, texts : & String) -> Result <Vec <Vec <f32>>, EmbedError>

markdown (other)

Markdown structure module (Sprint 3.4 T2).

Item
fn parse_document(text : & str) -> Result <ParsedDoc, MarkdownError>
fn chunk_document(text : & str, doc : & ParsedDoc, opts : & ChunkOptions) -> Vec <DocChunk>
fn parse_and_chunk(text : & str, opts : & ChunkOptions,) -> Result <(ParsedDoc, Vec <DocChunk>), MarkdownError>

DocChunk

Markdown structure module (Sprint 3.4 T2).

Item
pub struct DocChunk
DocChunk :: fn to_chunk_input(& self) -> infrastructure_knowledge_index::ChunkInput

MarkdownError

Markdown structure module (Sprint 3.4 T2).

Item
pub enum MarkdownError

ParsedDoc

Markdown structure module (Sprint 3.4 T2).

Item
pub struct ParsedDoc

Section

Markdown structure module (Sprint 3.4 T2).

Item
pub struct Section

session_walk (other)

Screened discovery of agent-session transcripts (sprint 4.21 stage 3).

Item
fn project_is_excluded(project_dir : & str, excludes : & String) -> bool
fn walk_sessions(root : & Path, excludes : & String,) -> Result <Vec <SessionFile>, SessionWalkError>

SessionFile

Screened discovery of agent-session transcripts (sprint 4.21 stage 3).

Item
pub struct SessionFile

SessionWalkError

Screened discovery of agent-session transcripts (sprint 4.21 stage 3).

Item
pub enum SessionWalkError

walk_plan (other)

Shared document-ingest library crates (sprint 4.21).

Item
fn classify_source_kind(rel_ref : & str) -> & 'static str
fn derive_title(front_matter : & serde_json::Value, doc : & markdown::ParsedDoc) -> Option <String>
fn derive_title_or_file_name(front_matter : & serde_json::Value, doc : & markdown::ParsedDoc, rel_path : & str,) -> String
fn file_name_title(rel_path : & str) -> String

GitProvenance

Shared document-ingest library crates (sprint 4.21).

Item
pub struct GitProvenance
fn git_provenance(root : & Path) -> GitProvenance

WalkActions

Shared document-ingest library crates (sprint 4.21).

Item
pub struct WalkActions
fn plan_walk_actions(indexed : & BTreeMap <String, String>, on_disk : & BTreeMap <String, String>,) -> WalkActions

How to use it

No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.

Module structure

infrastructure_doc_ingest

flowchart TD
  n_infrastructure_doc_ingest["infrastructure_doc_ingest"]
  n_infrastructure_doc_ingest --> n_db_stats["db_stats"]
  n_infrastructure_doc_ingest --> n_embedder["embedder"]
  n_infrastructure_doc_ingest --> n_markdown["markdown"]
  n_infrastructure_doc_ingest --> n_session_walk["session_walk"]
  n_infrastructure_doc_ingest --> n_walk_plan["walk_plan"]

Public surface

`db_stats`

ItemWhat it is
async fn table_row_counts(pool : & PgPool, tables : & & str,) -> Result <Vec <(String, i64)>, sqlx::Error>(table, row_count) for every name in tables, in the order given

`embedder`

ItemWhat it is
pub struct KnowledgeEmbedderAdapter<E : Embedder>Wraps any infrastructure_embeddings::Embedder as a KnowledgeEmbedder.
KnowledgeEmbedderAdapter<E> :: fn new(inner : E) -> SelfWrap an embedder implementation.
fn default_embedder() -> KnowledgeEmbedderAdapter <DeterministicEmbedder>The dev/test default: deterministic hashed-feature vectors at the index's declared VECTOR_DIM (1024).
pub const MODEL_DIR_ENV: & strEnv var naming the ONNX BGE-m3 model directory
pub enum AnyEmbedderRuntime embedder selection — one choice for ALL subcommands, so ingest and search always agree on the model (the index refuses mixed-model corpora).
AnyEmbedder :: fn model_id(& self) -> & str
AnyEmbedder :: fn dimensions(& self) -> usize
AnyEmbedder :: async fn embed_batch(& self, texts : & String) -> Result <Vec <Vec <f32>>, EmbedError>
fn embedder_from_env() -> Result <AnyEmbedder, String>Select the embedder from the environment (Gate 1.5 decision 5, sprint 3.15): MODEL_DIR_ENV set and the ort feature built → local ONNX BGE-m3; otherwise deterministic dev vectors with a stderr notice
KnowledgeEmbedderAdapter<E> :: fn model_id(& self) -> & str
KnowledgeEmbedderAdapter<E> :: fn dimensions(& self) -> usize
KnowledgeEmbedderAdapter<E> :: async fn embed_batch(& self, texts : & String) -> Result <Vec <Vec <f32>>, EmbedError>

`markdown`

ItemWhat it is
pub enum MarkdownErrorParse failures worth failing a file over
pub struct SectionA contiguous run of the document under one heading trail
pub struct DocChunkOne embeddable chunk with file-absolute provenance.
DocChunk :: fn to_chunk_input(& self) -> infrastructure_knowledge_index::ChunkInputConvert to the knowledge-index boundary shape (T3 ingest uses this).
pub struct ParsedDocStructural parse result: front matter + heading-split sections.
fn parse_document(text : & str) -> Result <ParsedDoc, MarkdownError>Extract front matter and pre-split the body on ATX headings
fn chunk_document(text : & str, doc : & ParsedDoc, opts : & ChunkOptions) -> Vec <DocChunk>Chunk every section of an already-parsed doc; offsets are file-absolute.
fn parse_and_chunk(text : & str, opts : & ChunkOptions,) -> Result <(ParsedDoc, Vec <DocChunk>), MarkdownError>Convenience: parse + chunk in one call

`session_walk`

ItemWhat it is
pub struct SessionFileOne discovered session file.
pub enum SessionWalkErrorWalk failures
fn project_is_excluded(project_dir : & str, excludes : & String) -> boolTrue when a project directory name matches any exclude pattern (case-insensitive substring — operator decision 2026-08-08: case-file projects stay out of the corpus, including future ones).
fn walk_sessions(root : & Path, excludes : & String,) -> Result <Vec <SessionFile>, SessionWalkError>Discover session files under root, recursively (subagent/workflow transcripts live at <project>/<session-uuid>/subagents/**/*.jsonl)

`walk_plan`

ItemWhat it is
pub struct WalkActionsWhat the walk diff decided (pure; applied by the caller's ingest run).
fn plan_walk_actions(indexed : & BTreeMap <String, String>, on_disk : & BTreeMap <String, String>,) -> WalkActionsPlan rename/removal actions from the indexed state vs the on-disk state
fn classify_source_kind(rel_ref : & str) -> & 'static strClassify a repo-relative markdown path into a source_kind ('adr' \
fn derive_title(front_matter : & serde_json::Value, doc : & markdown::ParsedDoc) -> Option <String>Derive a doc title: front matter title first, else the first ATX heading.
fn derive_title_or_file_name(front_matter : & serde_json::Value, doc : & markdown::ParsedDoc, rel_path : & str,) -> Stringderive_title, then the file name when the document names itself nowhere (B-079: knowledge_doc.title is NOT NULL and non-blank, so a file-backed doc with no front-matter title and no heading is named by its path's last segment -- the same rule as knowledge-index migration 0003's backfill and infrastructure-web-ingest's URL-segment arm).
fn file_name_title(rel_path : & str) -> StringThe last non-empty /-separated segment of rel_path; the whole string when there is none (blank or slash-only)
pub struct GitProvenanceGit provenance stamped on every doc at ingest (memo step 8).
fn git_provenance(root : & Path) -> GitProvenanceRead git provenance for root via strict argument-vector git calls (never a shell)

No pub use re-exports: every item above is declared in this crate.

Boundary

Reaches into foundation.

Shares tier infrastructure with 82 other crates: infrastructure-acquire, infrastructure-adapters-google-calendar, infrastructure-adapters-google-gmail, infrastructure-adapters-google-places, infrastructure-adapters-google-trends, infrastructure-adapters-shodan, infrastructure-adapters-yelp, infrastructure-agent, … (82 total).

_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._

Where it sits

Tier (ontology)infrastructure
Architectural role (taxonomy)unclassified (baselined)
Locationcrates/infrastructure/doc-ingest
Vocabulary in force (lexicon)current

Tier flow. Which tiers this crate's own edges cross.

flowchart LR
  n_infrastructure["infrastructure"] --> n_foundation["foundation"]

Dependencies

Runtime, in this workspace.

CrateTierOptionalOnly on
`foundation-bounded-io`foundationnoalways
`infrastructure-embeddings`infrastructurenoalways
`infrastructure-knowledge-index`infrastructurenoalways

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
async-trait^0.1noalways
serde^1derive, derivenoalways
serde_json^1noalways
serde_yaml^0.9noalways
sqlx^0.8runtime-tokio, postgres, chrono, uuid, jsonnoalways
thiserror^2noalways

Development, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
tokio^1full, macros, rt-multi-threadnoalways
url^2noalways

Build. None.

Depended on by. 3 workspace crates.

Signal flow — what reaches this crate, and what it reaches.

flowchart LR
  n_application_wiki["application-wiki"] -->|uses| SELF
  n_tools_corpus["tools-corpus"] -->|uses| SELF
  n_tools_retrieval_eval["tools-retrieval-eval"] -->|uses| SELF
  SELF["infrastructure-doc-ingest"]
  SELF -->|runtime| n_foundation_bounded_io["foundation-bounded-io"]
  SELF -->|runtime| n_infrastructure_embeddings["infrastructure-embeddings"]
  SELF -->|runtime| n_infrastructure_knowledge_index["infrastructure-knowledge-index"]
  classDef self fill:#1f883d,stroke:#1f883d,color:#fff;
  class SELF self;

Feature flags

FeatureEnablesOn by default
ortinfrastructure-embeddings/ortno
flowchart LR
  n_ort["ort"] --> n_infrastructure_embeddings_ort["infrastructure-embeddings/ort"]

Targets

KindNameSource
libinfrastructure_doc_ingest`src/lib.rs`

Error model

Error typeNamed by
MarkdownErrorparse_and_chunk, parse_document
SessionWalkErrorwalk_sessions

Operational characteristics

PropertyEvidence
async public surfaceyes
async runtimenone detected
database accessyes
network I/Onone detected
unsafe codenone detected
environment variablesyes

No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.

Configuration

VariableRead in
DATABASE_URLsrc/db_stats.rs
ORG_KNOWLEDGE_STRICT_CUDAsrc/embedder.rs
TEST_DATABASE_URLsrc/db_stats.rs

3 workspace crates depend on this one: application-wiki, tools-corpus, tools-retrieval-eval.

Verification

KindCount
Unit tests42
Integration tests0
Examples0
Doctests0

Evidence by module. How often each public module is named by something executable.

ModuleTestsExamplesConsumers
db_stats102
embedder505
markdown7011
session_walk404
walk_plan8014

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc2733
Public modules with a //! block55
pie showData
    title Public items with rustdoc
    "Documented" : 27
    "No rustdoc detected" : 6

Metrics

MetricValue
Rust source files6
Source lines1487
Code lines1111
Public API items33
Public modules5
Tests42
Examples0
Cargo features1
Direct runtime dependencies9
Workspace reverse dependencies3
pie showData
    title Public API by kind
    "constant" : 1
    "enum" : 3
    "function" : 14
    "method" : 8
    "struct" : 7
pie showData
    title Rust source composition
    "Code" : 1111
    "Blank or comment" : 376

Generation

Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.

All infrastructure · Manual