An embedding is a dense vector representation of text mapped into a continuous high-dimensional vector space ($\mathbb{R}^d$). Unlike traditional sparse representations (e.g., one-hot encoding, bag-of-words) where dimensions correspond to discrete vocabulary tokens, embedding dimensions capture latent semantic, syntactic, and conceptual relationships.
Texts conveying similar concepts occupy proximate locations in vector space, measured via angular proximity:
pgvector extension, this operator is denoted by <=>.<#> negative inner product operator. Query: "telecommuting policy"
│
▼ (BGE-m3 Embedder)
[0.042, -0.018, ..., 0.089] ∈ ℝ¹⁰²⁴
│
┌──────────────┴──────────────┐
▼ ▼
Chunk A: "remote work guide" Chunk B: "quarterly revenue"
[0.040, -0.015, ..., 0.085] [-0.091, 0.072, ..., -0.012]
Cosine Similarity: 0.94 Cosine Similarity: 0.12
(HIGH MATCH) (IRRELEVANT)
The platform standardizes on BAAI/bge-m3 as its primary default embedder, with an optional vendor fallback to OpenAI text-embedding-3-large.
| Dimension | BAAI/bge-m3 (Default Local) | OpenAI text-embedding-3-large | Cohere embed-english-v3.0 |
|---|---|---|---|
| Vector Dimension | 1024 | 3072 (configurable) | 1024 |
| Max Sequence Length | 8192 tokens | 8191 tokens | 512 tokens |
| Hosting Model | Self-hosted (local GPU/CPU) | Managed API | Managed API |
| Query Cost | $0.00 (infrastructure only) | $0.00013 / 1k tokens | $0.00010 / 1k tokens |
| Multilingual Support | 100+ languages | High | English specialized |
| Multi-Functionality | Dense + Lexical + Multi-Vector | Dense only | Dense only |
| Privacy / Air-Gapped | Full data isolation | Requires network transit | Requires network transit |
Defined in src/retrieval/embedders.py, the platform uses a vendor-agnostic Python Protocol to decouple the indexing and retrieval pipelines from specific ML runtimes:
class Embedder(Protocol):
dim: int
async def embed(self, texts: list[str]) -> list[list[float]]: ...
Local transformer inference (BGEM3FlagModel) is synchronous and CPU/GPU-bound. Executing it directly within an async route would block the ASGI event loop (preventing concurrent API requests). In src/retrieval/embedders.py, execution is delegated to an executor thread:
loop = asyncio.get_event_loop()
result = await loop.run_in_executor(
None,
lambda: self._model.encode(texts, batch_size=32, max_length=8192)["dense_vecs"],
)
return result.tolist()
In src/retrieval/dense.py, vector distance calculation is executed strictly inside a PostgreSQL WITH authorized AS (...) CTE. Access control policies (rag.access_matches) are evaluated in the WHERE clause before candidate ranking:
WITH authorized AS (
SELECT c.id, c.content, c.metadata, c.page, c.section, c.version,
d.title AS document_title, d.url, d.effective_from, d.effective_to,
d.access_policy, d.id AS document_id,
1 - (c.embedding <=> CAST(:q AS vector)) AS score
FROM document_chunks c
JOIN documents d ON d.id = c.document_id
WHERE d.deleted_at IS NULL
AND rag.access_matches(d.access_policy, :user_role, :user_projects, :user_id)
AND (:department IS NULL OR d.department = :department)
AND (:doc_type IS NULL OR d.doc_type = :doc_type)
ORDER BY c.embedding <=> CAST(:q AS vector)
LIMIT :k
)
SELECT * FROM authorized
WHERE score >= :threshold
ORDER BY score DESC;
To estimate PostgreSQL buffer pool and RAM allocation for vector indexing:
\[\text{Vector Storage per Chunk} = 1024 \times 4\text{ bytes (FP32)} = 4,096\text{ bytes} \approx 4\text{ KB}\]For an organizational corpus of 100,000 document chunks:
Because the index comfortably fits in system cache, sub-15ms p95 vector scan latencies are achieved on standard compute instances.
CAP-402, SOC2-T3) into uninformative regions of semantic space.tsvector) via Reciprocal Rank Fusion (RRF) in src/retrieval/hybrid.py.embedding vector(1024)). Model names and versions are tracked in chunk metadata, and batch re-indexing scripts are provided in scripts/ingest.py.score >= 0.2) to prune irrelevant tail results.BGE-m3) and API-based (OpenAI) backends.