Dev.to AI 🤖 Ai 👁 0 📖 7 min read

RAG Silent Failure: When Your Embedding Pipeline Reports Success But Isn't Searchable

The Bug A document gets uploaded. Textract extracts the text, Claude classifies it and writes a summary, the card in the UI flips to "Completed" with a green checkmark. Everything looks fine. Then you ask the chat "wh

The Bug

A document gets uploaded. Textract extracts the text, Claude classifies it and writes a summary, the card in the UI flips to "Completed" with a green checkmark. Everything looks fine.

Then you ask the chat "what's in this document?" and get nothing back. The document is indexed, completed, searchable by every signal the UI shows you — except it isn't actually in the vector index at all.

The key problem: a failure three layers deep was being swallowed at the first layer, so by the time it reached the status the user sees, it had already turned into a success.

I hit this while running a buyer-style test of my own AI Document Processor template — uploading a handful of PDFs back-to-back through a fresh Voyage AI key with no payment method attached. Voyage's free tier caps you at 3 requests/minute and 10K tokens/minute. Upload three documents in a row and the fourth embedding call gets rate-limited.

The Bug

A document gets uploaded. Textract extracts the text, Claude classifies it and writes a summary, the card in the UI flips to "Completed" with a green checkmark. Everything looks fine.

Then you ask the chat "what's in this document?" and get nothing back. The document is indexed, completed, searchable by every signal the UI shows you — except it isn't actually in the vector index at all.

The key problem: a failure three layers deep was being swallowed at the first layer, so by the time it reached the status the user sees, it had already turned into a success.

I hit this while running a buyer-style test of my own AI Document Processor template — uploading a handful of PDFs back-to-back through a fresh Voyage AI key with no payment method attached. Voyage's free tier caps you at 3 requests/minute and 10K tokens/minute. Upload three documents in a row and the fourth embedding call gets rate-limited.

Root Cause

The old embedding function in the Lambda processor looked like this:

# backend/lambdas/processor/handler.py (before)
def _embed_texts(texts: list[str]) -> list[list[float]] | None:
    try:
        import voyageai
        client = voyageai.Client(api_key=os.environ.get("VOYAGE_API_KEY", ""))
        result = client.embed([t[:8000] for t in texts], model="voyage-3", input_type="document")
        return result.embeddings
    except Exception as e:
        logger.warning("embed_failed: %s", str(e))
        return None

Three separate problems stacked on top of each other here:

  1. Any exception — including RateLimitError — was caught, logged at warning level, and swallowed. Nothing upstream ever learned the embeddings didn't exist.
  2. The caller stored chunks with embedding_vec = None when embeddings came back empty, instead of refusing to write incomplete rows.
  3. The document status was set to completed before any of this ran, because chunking/embedding was fire-and-forget, wrapped in its own try/except purely to stop one bad batch from crashing the whole Lambda:
# Step 4: update DB → COMPLETED
_update_document(doc_id, {"status": "completed", ...})

# Step 5: chunk text + generate embeddings + store in pgvector
try:
    _store_chunks(doc_id, result["pages"])
except Exception as e:
    logger.warning("chunk_store_failed: %s", str(e), extra={"doc_id": doc_id})

The document ends up with a summary, a doc type, a "Completed" badge — and zero rows in the vector index. Nothing in the API response, the WebSocket push, or the UI ever surfaces that. The only way to notice is to search for something you know is in the document and get nothing back.

This is the failure mode that worries me most in RAG systems: not a wrong answer, but a correctly shaped success response for a search that silently never happened.

Root Cause

The old embedding function in the Lambda processor looked like this:

# backend/lambdas/processor/handler.py (before)
def _embed_texts(texts: list[str]) -> list[list[float]] | None:
    try:
        import voyageai
        client = voyageai.Client(api_key=os.environ.get("VOYAGE_API_KEY", ""))
        result = client.embed([t[:8000] for t in texts], model="voyage-3", input_type="document")
        return result.embeddings
    except Exception as e:
        logger.warning("embed_failed: %s", str(e))
        return None

Three separate problems stacked on top of each other here:

  1. Any exception — including RateLimitError — was caught, logged at warning level, and swallowed. Nothing upstream ever learned the embeddings didn't exist.
  2. The caller stored chunks with embedding_vec = None when embeddings came back empty, instead of refusing to write incomplete rows.
  3. The document status was set to completed before any of this ran, because chunking/embedding was fire-and-forget, wrapped in its own try/except purely to stop one bad batch from crashing the whole Lambda:
# Step 4: update DB → COMPLETED
_update_document(doc_id, {"status": "completed", ...})

# Step 5: chunk text + generate embeddings + store in pgvector
try:
    _store_chunks(doc_id, result["pages"])
except Exception as e:
    logger.warning("chunk_store_failed: %s", str(e), extra={"doc_id": doc_id})

The document ends up with a summary, a doc type, a "Completed" badge — and zero rows in the vector index. Nothing in the API response, the WebSocket push, or the UI ever surfaces that. The only way to notice is to search for something you know is in the document and get nothing back.

This is the failure mode that worries me most in RAG systems: not a wrong answer, but a correctly shaped success response for a search that silently never happened.

The Fix

Three changes, in order of how much they mattered:

1. Treat embedding failure as a real error, not a warning.

# backend/lambdas/processor/handler.py (after)
class EmbeddingError(Exception):
    """Embeddings could not be generated; the document can't be searched."""

def _embed_texts(texts: list[str], context) -> list[list[float]]:
    client = voyageai.Client(api_key=os.environ.get("VOYAGE_API_KEY", ""))
    embeddings: list[list[float]] = []

    for start in range(0, len(texts), _EMBED_BATCH_SIZE):  # 128 — Voyage's per-request cap
        batch = [t[:8000] for t in texts[start:start + _EMBED_BATCH_SIZE]]
        for attempt in range(_EMBED_MAX_ATTEMPTS):
            try:
                result = client.embed(batch, model="voyage-3", input_type="document")
                embeddings.extend(result.embeddings)
                break
            except RateLimitError as e:
                if attempt == _EMBED_MAX_ATTEMPTS - 1:
                    raise EmbeddingError("Voyage AI rate limit exceeded...") from e
                delay = _EMBED_BACKOFF_SECONDS[attempt] + random.uniform(0, 5)
                if context.get_remaining_time_in_millis() < delay * 1000 + _DEADLINE_MARGIN_MS:
                    raise EmbeddingError("...ran out of time...") from e
                time.sleep(delay)
    return embeddings

No more None return. Either you get back exactly as many embeddings as you sent texts, or you get an exception with a message a user can act on ("add a payment method and re-upload"). The backoff schedule (20s / 40s / 60s + jitter) matches Voyage's free-tier window — just long enough to clear a 3 RPM cap without blowing the Lambda's timeout, which is why the retry loop also checks context.get_remaining_time_in_millis() before sleeping again. A Lambda that times out mid-retry would leave the document stuck on "processing" forever, which is its own silent failure.

2. Embed before you touch existing data, and never store a chunk without its embedding.

The old code deleted a document's existing chunks before generating new ones — so a failed re-index didn't just fail to add new chunks, it deleted the old working ones too. The fix flips the order: generate embeddings first, and only delete + insert once they're confirmed with zip(all_chunks, embeddings, strict=True), which throws if the counts ever mismatch instead of silently zipping short.

3. Make "completed" depend on indexing actually succeeding.

try:
    _store_chunks(doc_id, result["pages"], context)
except EmbeddingError as e:
    _update_document(doc_id, {
        "status": "failed",
        "error_message": f"Search indexing failed: {e}",
        ...
    })
    continue

_update_document(doc_id, {"status": "completed", ...})

error_message is now a real column, exposed through the API schema and rendered on the document card in the frontend, so a failed upload says why it failed instead of a generic "please retry." A failed WebSocket push doesn't carry the message, so the frontend hook refetches the document on a failed event specifically to pick it up.

Lessons Learned

A caught exception that gets logged and ignored is a design decision, not a safety net. except Exception: return None felt defensive when I wrote it — "don't let one broken document crash the whole batch" — but it also meant the one signal that would've told the user something was wrong never left the Lambda.

Status fields need to mean what they say. "Completed" meant "the LLM steps ran" when it should have meant "this document is fully usable." Any state your UI shows the user should be downstream of everything that has to succeed for that state to be true — not set early for convenience and patched around later.

Free tiers change your error distribution, not just your error rate. On a paid Voyage key this bug might never surface — 3 RPM only bites when you're testing with a brand-new, unfunded account, which is exactly the account a first-time buyer of a template product would have. The failure mode that matters most in a product is often the one your own dev environment doesn't hit.

"It looks done" is not the same test as "it works." The card said Completed, the summary was there, Textract and Claude both did their job — every surface signal was green. The only way I caught this was deliberately testing the thing the UI doesn't show: searching for content I knew was in the document.

GitHub

Key code samples (RAG service, Lambda processor, CDK stacks) are available on GitHub:

👉 github.com/sanjaypatoliya/ai-document-processor-sample

About the Author

I'm Sanjay Patoliya — AWS Certified Generative AI Developer Pro, Solutions Architect & DevOps Engineer building production-ready AI systems on AWS. If you're looking to build something similar or need a remote AWS + AI engineer, feel free to reach out.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.