Provider-agnostic text vectorization (embeddings) for semantic search + RAG: an Embedder trait, a provenance-preserving chunker, a deterministic dev embedder, and (feature-gated) an in-process ONNX BGE-m3 vectorizer.
| Tier | infrastructure |
| Role | unclassified (baselined) |
| Path | crates/infrastructure/embeddings |
| Edition | 2021 |
| Targets | infrastructure_embeddings |
| Public items | 2 across 0 modules |
| Tests | 11 |
What it is for
infrastructure-embeddings — provider-agnostic text vectorization for semantic search + RAG.
The surface is deliberately small: one Embedder trait, a provenance- preserving chunk_text splitter, and a dependency-free DeterministicEmbedder so the full chunk → embed → store → search pipeline builds and tests with zero native deps. The real in-process ONNX BGE-m3 impl lives behind the ort feature (OrtBgeM3Embedder) and drops in behind the same trait.
Design + rationale: ADR 0016. Consumers own the vector store (pgvector per tenant) and any privilege/isolation policy — this crate never performs external network egress on the default path, so privileged text stays in-process.
use infrastructure_embeddings::{chunk_text, ChunkOptions, DeterministicEmbedder, Embedder};
# async fn demo() -> Result<(), infrastructure_embeddings::EmbeddingError> {
let chunks = chunk_text("some long document text...", &ChunkOptions::default());
let embedder = DeterministicEmbedder::new(1024);
let vectors = embedder.embed_chunks(&chunks).await?;
assert_eq!(vectors.len(), chunks.len());
# Ok(()) }
Capabilities
Embedder
infrastructure-embeddings — provider-agnostic text vectorization for semantic
| Item |
|---|
pub trait Embedder |
NormalizePolicy
infrastructure-embeddings — provider-agnostic text vectorization for semantic
| Item |
|---|
pub enum NormalizePolicy |
How to use it
From this crate's own rustdoc:
use infrastructure_embeddings::{chunk_text, ChunkOptions, DeterministicEmbedder, Embedder};
# async fn demo() -> Result<(), infrastructure_embeddings::EmbeddingError> {
let chunks = chunk_text("some long document text...", &ChunkOptions::default());
let embedder = DeterministicEmbedder::new(1024);
let vectors = embedder.embed_chunks(&chunks).await?;
assert_eq!(vectors.len(), chunks.len());
# Ok(()) }
Module structure
No public modules: the crate root is its whole surface.
Public surface
`crate root`
| Item | What it is |
|---|---|
pub enum NormalizePolicy | How an embedder's output vectors are scaled — the consumer must pair this with the matching pgvector distance operator (UnitL2 ⇒ cosine/inner-product are equivalent; Raw ⇒ pick L2/cosine explicitly). |
pub trait Embedder | A text → vector embedder |
Re-exports. Exported here, defined elsewhere.
| Export | Defined in |
|---|---|
DeterministicEmbedder | dev::DeterministicEmbedder |
EmbeddingError | error::EmbeddingError |
{OrtBgeM3Embedder,OrtOptions} | ort::{OrtBgeM3Embedder,OrtOptions} |
{chunk_text,ChunkOptions,TextChunk} | chunk::{chunk_text,ChunkOptions,TextChunk} |
Boundary
Depends on no other workspace tier.
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) |
| Location | crates/infrastructure/embeddings |
| Vocabulary in force (lexicon) | current |
Dependencies
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
async-trait | ^0.1 | — | no | always |
ndarray | ^0.16 | — | yes | always |
ort | =2.0.0-rc.10 | ndarray, cuda | yes | always |
serde | ^1 | derive, derive | no | always |
thiserror | ^2 | — | no | always |
tokenizers | ^0.20 | onig | yes | always |
Development, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
tokio | ^1 | full, macros, rt-multi-thread | no | always |
Build. None.
Depended on by. 8 workspace crates.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR n_application_legal_knowledge["application-legal-knowledge"] -->|uses| SELF n_application_wiki["application-wiki"] -->|uses| SELF n_domain_prose_shard["domain-prose-shard"] -->|uses| SELF n_foundation_text_clustering["foundation-text-clustering"] -->|uses| SELF n_infrastructure_doc_ingest["infrastructure-doc-ingest"] -->|uses| SELF n_infrastructure_html_text["infrastructure-html-text"] -->|uses| SELF n_infrastructure_web_ingest["infrastructure-web-ingest"] -->|uses| SELF n_tools_corpus["tools-corpus"] -->|uses| SELF SELF["infrastructure-embeddings"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
| Feature | Enables | On by default |
|---|---|---|
default | — | yes |
ort | dep:ort, dep:tokenizers, dep:ndarray | no |
flowchart LR n_default["default"] n_ort["ort"] --> n_dep_ort["dep:ort"] n_ort["ort"] --> n_dep_tokenizers["dep:tokenizers"] n_ort["ort"] --> n_dep_ndarray["dep:ndarray"]
Targets
| Kind | Name | Source |
|---|---|---|
| lib | infrastructure_embeddings | `src/lib.rs` |
Error model
No public error type was detected: no public item declares a type named *Error, and no public signature returns one.
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | none detected |
| async runtime | none detected |
| database access | none detected |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | yes |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
| Variable | Read in |
|---|---|
BGE_M3_MODEL_DIR | src/ort.rs |
CUDA_STRICT_PROBE | src/ort.rs |
Related capabilities
8 workspace crates depend on this one: application-legal-knowledge, application-wiki, domain-prose-shard, foundation-text-clustering, infrastructure-doc-ingest, infrastructure-html-text, infrastructure-web-ingest, tools-corpus.
Verification
| Kind | Count |
|---|---|
| Unit tests | 11 |
| Integration tests | 0 |
| Examples | 0 |
| Doctests | 1 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 2 | 0 | 6 |
What the tests establish, by name:
empty_and_whitespace_yield_no_chunks—src/chunk.rsnever_splits_a_multibyte_codepoint—src/chunk.rsoverlap_ge_max_still_makes_progress—src/chunk.rsshort_input_is_a_single_full_range_chunk—src/chunk.rswindows_overlap_and_cover_everything—src/chunk.rsbatch_preserves_order_and_dim—src/dev.rsdeterministic_and_unit_norm—src/dev.rsdifferent_text_differs—src/dev.rsempty_is_finite_not_nan—src/dev.rsbge_m3_is_unit_dim_and_cross_lingual—src/ort.rscuda_strict_probe—src/ort.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 2 | 2 |
Public modules with a //! block | 0 | 0 |
pie showData
title Public items with rustdoc
"Documented" : 2
"No rustdoc detected" : 0
Metrics
| Metric | Value |
|---|---|
| Rust source files | 5 |
| Source lines | 785 |
| Code lines | 537 |
| Public API items | 2 |
| Public modules | 0 |
| Tests | 11 |
| Examples | 0 |
| Cargo features | 2 |
| Direct runtime dependencies | 6 |
| Workspace reverse dependencies | 8 |
pie showData
title Public API by kind
"enum" : 1
"trait" : 1
pie showData
title Rust source composition
"Code" : 537
"Blank or comment" : 248
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.