Glue Plus Bedrock: Offline Doc Enrichment Before Online Code RAG

Glue Plus Bedrock: Offline Doc Enrichment Before Online Code RAG

Interactive code RAG should stay thin: retrieve, cite, answer. Enrichment — summaries, tags, API blurbs — belongs in an offline pipeline. Amazon Glue plus Bedrock batch (or modest on-demand) lets you improve documentation quality every night without taxing IDE latency budgets.

⚡ TL;DR: Extract symbols + raw docs to S3; Glue jobs call Bedrock to emit summaries, tags, and “when to use” notes; write enriched artifacts beside source checksums; online KB indexes enriched blobs only. Idempotent by content hash. Pair with Codebase Embeddings Refresh and Bedrock Batch Inference.

Pipeline shape

git merge → S3 raw/ → Glue enrich (Bedrock) → S3 enriched/ → KB sync → OpenSearch/pgvector
# glue_enrich.py — PySpark / Glue job sketch
import hashlib, json, boto3

bedrock = boto3.client("bedrock-runtime")
MODEL = "anthropic.claude-3-haiku-20240307-v1:0"

PROMPT = """Summarize this code symbol for developer RAG.
Return JSON: {summary, tags[], when_to_use, pitfalls[]}
CODE:
{code}
"""

def enrich_row(path: str, code: str, sha: str) -> dict:
    content_hash = hashlib.sha256(code.encode()).hexdigest()
    # ✅ Skip if enriched already for this hash
    if already_enriched(path, content_hash):
        return load_enriched(path, content_hash)
    body = {
        "anthropic_version": "bedrock-2023-05-31",
        "max_tokens": 512,
        "messages": [{"role": "user", "content": PROMPT.format(code=code[:12000])}],
    }
    resp = bedrock.invoke_model(modelId=MODEL, body=json.dumps(body))
    out = json.loads(resp["body"].read())
    text = out["content"][0]["text"]
    meta = json.loads(extract_json(text))
    meta.update({"path": path, "git_sha": sha, "content_hash": content_hash})
    return meta

Keep online RAG lean

Online index fields: summary, tags, symbol, path, service — not the full Bedrock transcript. Full source remains available via a tool fetch (see Tool-Augmented RAG when published, or fetch by path today).

{
  "path": "src/billing/InvoiceService.ts",
  "symbol": "InvoiceService.create",
  "summary": "Creates a draft invoice and enqueues ledger posting.",
  "tags": ["billing", "ledger", "idempotent"],
  "when_to_use": "New subscription invoice after checkout success",
  "pitfalls": ["Must pass idempotencyKey", "Do not call from sync webhooks"],
  "content_hash": "a1b2..."
}

Cost and quality controls

Control Why
Haiku/Sonnet small for summaries Overnight volume, not IDE chat
Content-hash skip Avoid re-paying for unchanged files
JSON schema validate Reject malformed enrichment
PII scrub pre-Bedrock Same as secret-aware filters
Glue job bookmarks Exactly-once-ish incremental folders

❌ Enriching every minified vendor file. Allowlist src/** and packages/*/src/**.

Wire to Knowledge Base sync

After enriched/ lands, trigger the same webhook/checksum sync you use for source — see sibling topic on KB git webhooks. Online Retrieve should filter on tags and service metadata for precision.

# illustrative Glue trigger after merge batch
aws glue start-job-run --job-name code-doc-enrich \
  --arguments '{"--git_sha":"'"$SHA"'","--prefix":"raw/'"$SHA"'/"}'

Closing checklist

✅ Dos
– ✅ Enrich offline; retrieve online
– ✅ Idempotent by content hash
– ✅ Validate JSON schemas before index
– ✅ Scrub secrets/PII before Bedrock
– ✅ Track token spend per repo per night

❌ Don’ts
– ❌ Don’t call Bedrock enrichment inside the IDE request path
– ❌ Don’t index raw model chatter or chain-of-thought
– ❌ Don’t enrich generated/ or node_modules
– ❌ Don’t skip checksum tombstones on deleted files

Related reading

Last updated on September 11, 2026


Discover more from CheatCoders

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply