The Worst Failure Mode in RAG: HTTP 200 OK With Missing Data
When you migrate a RAG pipeline originally sized for OpenAI text-embedding-3-large (8,191-token context window) over to Google gemini-embedding-001 (2,048-token input window), chunks sized at 2,500 to 4,000 tokens do not fail with an exception. Instead:
- OpenAI
text-embedding-3-large(> 8,191cl100k_basetokens): Rejects the batch with400 Bad Request: This model's maximum context length is 8191 tokens. Loud failure; zero corrupted rows land in Postgres. - Google
gemini-embedding-001(> 2,048SentencePiece tokens): Silently clips tokens2,049..Non defaultembedContentcalls (or when Vertexauto_truncatedefaults totrue) and returnsHTTP 200 OKwith a3072dvector representing only the top of the passage. Indemnification carve-outs, appendix fee tables, and bottom-of-file function definitions vanish from vector recall with zero telemetry warning.
Even worse, cl100k_base token counts do not match SentencePiece counts on JSON, Base64, SQL, or C++/Rust identifiers, where token inflation routinely reaches 1.15x to 1.25x.
gemini-embedding-001 (2,048 Tokens) vs OpenAI (8,191 Tokens) vs Voxell Forge Truncation Matrix
| Embedding Model / Endpoint | Max Input Tokens | Tokenizer Family | Behavior Above Limit | Optimal Semantic Recall Span |
|---|---|---|---|---|
Google gemini-embedding-001 |
2,048 |
Gemini SentencePiece | Silent tail truncation (HTTP 200) unless autoTruncate=false on Vertex |
384 - 1,024 tokens |
Google text-embedding-005 |
2,048 |
Vertex SentencePiece | Silent tail truncation by default (auto_truncate=true) |
384 - 1,024 tokens |
OpenAI text-embedding-3-large |
8,191 |
tiktoken (cl100k_base) |
Hard HTTP 400 error (rejects whole batch) |
512 - 1,536 tokens (dilutes >4k) |
Voxell Forge /v1/embeddings (Turbo / Pro) |
8,192 |
Subword BPE | Deterministic validation + structure-aware SDK splitters | 512 - 2,048 tokens ($0 Turbo / $0.25 Pro) |
Voxell Forge Managed Ingest (/v1/answers) |
Up to 30 MB / doc |
Native AST / PDF / DOCX | Zero silent loss: parent-heading + table-header propagation | 0.8849 nDCG@10 ($199/mo Team) |
Fix 1: Fail-Closed Token Guard + Length-Weighted Window Pooling
Never feed raw strings into embed_content or embeddings.create without pre-tokenizing. When you must produce one document-level vector for a 5,000-token document on a 2,048-token encoder, split into overlapping 1,536-token windows (prepending the document title/breadcrumb to each window), L2-normalize each window vector, weight by token count, and L2-normalize the pooled vector:
import numpy as np
import tiktoken
ENC = tiktoken.get_encoding("cl100k_base")
def split_token_windows(
text: str,
header_prefix: str,
max_tokens: int = 1600, # 22% safety buffer under Gemini's 2,048 SentencePiece cap
overlap_tokens: int = 192,
) -> list[tuple[str, int]]:
prefix_ids = ENC.encode(header_prefix + "\n\n")
body_ids = ENC.encode(text)
budget = max_tokens - len(prefix_ids)
if budget <= overlap_tokens:
raise ValueError("header_prefix exceeds window token budget")
windows: list[tuple[str, int]] = []
step = budget - overlap_tokens
for start in range(0, max(1, len(body_ids)), step):
slice_ids = body_ids[start : start + budget]
chunk_ids = prefix_ids + slice_ids
windows.append((ENC.decode(chunk_ids), len(slice_ids)))
if start + budget >= len(body_ids):
break
return windows
def pool_window_embeddings(vecs: np.ndarray, weights: list[int]) -> np.ndarray:
# 1. Unit-normalize every window first (mandatory for Gemini MRL < 3072d)
vecs = vecs / np.maximum(np.linalg.norm(vecs, axis=1, keepdims=True), 1e-12)
# 2. Token-count weighted mean + final unit L2 projection
w = np.asarray(weights, dtype=np.float32)[:, None]
pooled = (vecs * w).sum(axis=0)
return pooled / max(float(np.linalg.norm(pooled)), 1e-12)
Note the architectural catch with pooled 8,000-token single vectors (including native 8,191-token OpenAI vectors): single-vector dilution. Packing twelve distinct contract clauses into one 1536d or 3072d vector averages their directions together, dropping needle-in-a-haystack clause recall by 14% to 26% compared to keeping child spans indexed separately with parent-section metadata attached.
Fix 2: Eliminate Manual Windowing With Voxell Forge Parent-Span Ingest
Instead of maintaining fragile dual tokenizers (tiktoken + Vertex countTokens RPC round-trips) and header-stitching scripts, Voxell Forge parses whole documents up to 30 MB, preserves heading breadcrumbs and table schemas automatically, runs C_corpus zero-LLM dialect conditioning (99.04% Recall@20), and exposes OpenAI-compatible /v1/embeddings (base_url = "https://api.voxell.ai/v1"). Run a live keyless test on tail-clause preservation right now:
curl -sS -X POST https://api.voxell.ai/api/v1/agent/bakeoff \
-H "Content-Type: application/json" \
-d '{
"documents": [
{"name": "msa-sec-1.md", "text": "Master Services Agreement Section 1: Standard platform uptime commitment is 99.9% measured monthly."},
{"name": "msa-exhibit-c.md", "text": "Master Services Agreement Exhibit C (Tail Carve-Out): Sovereign VPC appliances carry zero external telemetry egress and 15-minute P1 response."}
],
"queries": ["What telemetry egress policy applies under Exhibit C for Sovereign VPC appliances?"]
}'
Size your chunk count and token density tradeoffs in the Vector RAM & TCO Calculator, review PDF Table Extraction Benchmarks, or open the Forge Console (v4.0 Pricing).